Skip to content

Commit

Permalink
Add rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 23, 2015
1 parent 86c1be8 commit 141f7d2
Show file tree
Hide file tree
Showing 250 changed files with 5,004 additions and 5,502 deletions.
243 changes: 243 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
require: rubocop-rspec

AllCops:
RunRailsCops: true
DisplayCopNames: true
Include:
- '**/Rakefile'
Exclude:
- 'script/**/*'

Lint/RescueException:
Exclude:
- 'lib/active_fedora/ldp_cache.rb'

Lint/HandleExceptions:
Exclude:
- 'spec/unit/**/*'
- 'spec/integration/**/*'
- 'lib/active_fedora/cleaner.rb'
- 'lib/active_fedora/associations/builder/contains.rb'

Lint/AssignmentInCondition:
Enabled: false

Metrics/LineLength:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/BlockNesting:
Exclude:
- 'lib/active_fedora/autosave_association.rb'
- 'lib/active_fedora/associations/has_many_association.rb'

Metrics/CyclomaticComplexity:
Exclude:
- 'lib/active_fedora.rb'
- 'lib/active_fedora/reflection.rb'
- 'lib/active_fedora/relation/finder_methods.rb'
- 'lib/active_fedora/query_result_builder.rb'
- 'lib/active_fedora/nested_attributes.rb'
- 'lib/active_fedora/autosave_association.rb'
- 'lib/active_fedora/associations/has_many_association.rb'
- 'lib/active_fedora/associations/has_and_belongs_to_many_association.rb'
- 'lib/active_fedora/associations/builder/indirectly_contains.rb'
- 'lib/active_fedora/associations/builder/directly_contains_one.rb'
- 'lib/active_fedora/file_configurator.rb'
- 'lib/active_fedora/file.rb'
- 'lib/active_fedora/datastreams/nokogiri_datastreams.rb'

Metrics/PerceivedComplexity:
Exclude:
- 'lib/active_fedora.rb'
- 'lib/active_fedora/relation/finder_methods.rb'
- 'lib/active_fedora/nested_attributes.rb'
- 'lib/active_fedora/file_configurator.rb'
- 'lib/active_fedora/datastreams/nokogiri_datastreams.rb'
- 'lib/active_fedora/autosave_association.rb'
- 'lib/active_fedora/associations/has_many_association.rb'
- 'lib/active_fedora/associations/has_and_belongs_to_many_association.rb'
- 'lib/active_fedora/associations/builder/indirectly_contains.rb'
- 'lib/active_fedora/associations/builder/directly_contains_one.rb'

Metrics/ModuleLength:
Exclude:
- 'lib/active_fedora.rb'
- 'lib/active_fedora/relation/finder_methods.rb'
- 'lib/active_fedora/persistence.rb'
- 'lib/active_fedora/attributes.rb'
- 'lib/active_fedora/autosave_association.rb'

Metrics/ClassLength:
Exclude:
- 'spec/samples/hydra-mods_article_datastream.rb'
- 'lib/active_fedora/rdf/rdf_datastream.rb'
- 'lib/active_fedora/rdf/fcrepo.rb'
- 'lib/active_fedora/qualified_dublin_core_datastream.rb'
- 'lib/active_fedora/file_configurator.rb'
- 'lib/active_fedora/file.rb'
- 'lib/active_fedora/associations/collection_proxy.rb'
- 'lib/active_fedora/associations/collection_association.rb'

Metrics/MethodLength:
Enabled: false

Style/MethodName:
Exclude:
- 'lib/active_fedora/with_metadata.rb'

Style/AndOr:
Exclude:
- 'lib/active_fedora/associations/has_many_association.rb'

Style/AccessorMethodName:
Exclude:
- 'lib/active_fedora/with_metadata/metadata_node.rb'
- 'lib/active_fedora/predicates.rb'
- 'lib/active_fedora/fedora_attributes.rb'
- 'lib/active_fedora/attribute_methods/dirty.rb'
- 'lib/active_fedora/associations/has_many_association.rb'
- 'lib/active_fedora/associations/association.rb'

Style/PredicateName:
Exclude:
- 'lib/active_fedora/relation/finder_methods.rb'
- 'lib/active_fedora/versionable.rb'
- 'lib/active_fedora/reflection.rb'
- 'lib/active_fedora/pathing.rb'
- 'lib/active_fedora/om_datastream.rb'
- 'lib/active_fedora/nested_attributes.rb'
- 'lib/active_fedora/clean_connection.rb'
- 'lib/active_fedora/attributes.rb'
- 'lib/active_fedora/file/attributes.rb'
- 'lib/active_fedora/attached_files.rb'
- 'lib/active_fedora/associations.rb'
- 'lib/active_fedora/association_hash.rb'

Style/GuardClause:
Exclude:
- 'lib/active_fedora/autosave_association.rb'

Style/TrivialAccessors:
Exclude:
- 'lib/active_fedora/reflection.rb'
- 'lib/active_fedora/attributes/node_config.rb'
- 'lib/active_fedora/associations/directly_contains_one_association.rb'
- 'lib/active_fedora/associations/belongs_to_association.rb'
- 'lib/active_fedora/associations/association.rb'

Style/EachWithObject:
Exclude:
- 'lib/active_fedora/relation/finder_methods.rb'

Style/CaseEquality:
Exclude:
- 'lib/active_fedora/relation/finder_methods.rb'

Style/BlockDelimiters:
Exclude:
- 'spec/**/*'

Style/BlockEndNewline:
Exclude:
- 'spec/**/*'

Style/MultilineBlockLayout:
Exclude:
- 'spec/**/*'

Style/Semicolon:
Exclude:
- 'spec/**/*'

Style/Lambda:
Exclude:
- 'spec/**/*'

Style/IndentationConsistency:
EnforcedStyle: rails

Style/CollectionMethods:
PreferredMethods:
collect: 'map'
collect!: 'map!'
inject: 'reduce'
detect: 'find'
find_all: 'select'

Style/WordArray:
Enabled: false

Style/RegexpLiteral:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

Style/Documentation:
Enabled: false

Style/HashSyntax:
Exclude:

Style/GlobalVars:
Exclude:
- 'spec/**/*'

Style/SingleLineBlockParams:
Enabled: false

Style/ClassVars:
Exclude:
- 'spec/unit/finder_methods_spec.rb'
- 'spec/unit/base_spec.rb'
- 'spec/integration/indexing_spec.rb'
- 'lib/active_fedora/predicates.rb'
- 'lib/active_fedora/identifiable.rb'

Style/SignalException:
Enabled: false

Style/FileName:
Exclude:
- 'lib/active-fedora.rb'
- 'spec/samples/hydra-mods_article_datastream.rb'

Rails/Output:
Exclude:
- 'lib/generators/**/*'

Rails/Date:
Enabled: false

Rails/TimeZone:
Enabled: false

RSpec/ExampleWording:
CustomTransform:
be: is
have: has
not: does not
NOT: does NOT
IgnoredWords:
- only

RSpec/FilePath:
Enabled: false

RSpec/InstanceVariable:
Enabled: false

RSpec/DescribeClass:
Exclude:
- 'spec/integration/**/*'

RSpec/DescribedClass:
Exclude:
- 'spec/unit/finder_methods_spec.rb'

11 changes: 5 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ Bundler::GemHelper.install_tasks
# load rake tasks defined in lib/tasks that are not loaded in lib/active_fedora.rb
load "lib/tasks/active_fedora_dev.rake"

CLEAN.include %w[**/.DS_Store tmp *.log *.orig *.tmp **/*~]
CLEAN.include %w(**/.DS_Store tmp *.log *.orig *.tmp **/*~)

task :ci => ['jetty:clean', 'active_fedora:ci']
task :spec => ['active_fedora:rspec']
task :rcov => ['active_fedora:rcov']
task ci: ['jetty:clean', 'active_fedora:ci']
task spec: ['active_fedora:rspec']
task rcov: ['active_fedora:rcov']


task :default => [:ci]
task default: [:ci]
2 changes: 2 additions & 0 deletions active-fedora.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec-its"
s.add_development_dependency "equivalent-xml"
s.add_development_dependency "simplecov", '~> 0.7.1'
s.add_development_dependency "rubocop", '~> 0.34'
s.add_development_dependency "rubocop-rspec", '~> 1.3'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {spec}/*`.split("\n")
Expand Down
33 changes: 15 additions & 18 deletions lib/active_fedora.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ module Attributes
end
end


module Scoping
extend ActiveSupport::Autoload

Expand All @@ -169,11 +168,14 @@ class << self
def fedora_config
@fedora_config ||= Config.new(configurator.fedora_config)
end
def solr_config; configurator.solr_config; end
def config_options; configurator.config_options; end
def config_loaded?; configurator.config_loaded?; end

def init( options={} )
delegate :solr_config, to: :configurator

delegate :config_options, to: :configurator

delegate :config_loaded?, to: :configurator

def init(options = {})
# Make config_options into a Hash if nil is passed in as the value
options = {} if options.nil?
# For backwards compatibility, handle cases where config_path (a String) is passed in as the argument rather than a config_options hash
Expand Down Expand Up @@ -202,14 +204,14 @@ def config
# ActiveFedora.init(:environment=>"test")
# ActiveFedora.environment => "test"
def environment
if config_options.fetch(:environment,nil)
if config_options.fetch(:environment, nil)
return config_options[:environment]
elsif defined?(Rails.env) and !Rails.env.nil?
elsif defined?(Rails.env) && !Rails.env.nil?
return Rails.env.to_s
elsif defined?(ENV['environment']) and !(ENV['environment'].nil?)
elsif defined?(ENV['environment']) && !(ENV['environment'].nil?)
return ENV['environment']
elsif defined?(ENV['RAILS_ENV']) and !(ENV['RAILS_ENV'].nil?)
raise RuntimeError, "You're depending on RAILS_ENV for setting your environment. Please use ENV['environment'] for non-rails environment setting: 'rake foo:bar environment=test'"
elsif defined?(ENV['RAILS_ENV']) && !(ENV['RAILS_ENV'].nil?)
raise "You're depending on RAILS_ENV for setting your environment. Please use ENV['environment'] for non-rails environment setting: 'rake foo:bar environment=test'"
else
ENV['environment'] = 'development'
end
Expand All @@ -223,9 +225,7 @@ def fedora
@fedora ||= Fedora.new(fedora_config.credentials)
end

def predicate_config
configurator.predicate_config
end
delegate :predicate_config, to: :configurator

def root
::File.expand_path('../..', __FILE__)
Expand All @@ -244,10 +244,10 @@ def version
# @example Search within ActiveFedora::RdfNode for a class called "TermProxy"
# ActiveFedora.class_from_string("TermProxy", ActiveFedora::RdfNode)
# => ActiveFedora::RdfNode::TermProxy
def class_from_string(class_name, container_class=Kernel)
def class_from_string(full_class_name, container_class = Kernel)
container_class = container_class.name if container_class.is_a? Module
container_parts = container_class.split('::')
(container_parts + class_name.split('::')).flatten.inject(Kernel) do |mod, class_name|
(container_parts + full_class_name.split('::')).flatten.inject(Kernel) do |mod, class_name|
if mod == Kernel
Object.const_get(class_name)
elsif mod.const_defined? class_name.to_sym
Expand All @@ -258,14 +258,11 @@ def class_from_string(class_name, container_class=Kernel)
end
end
end

end

self.configurator ||= ActiveFedora::FileConfigurator.new

end


I18n.load_path << ::File.dirname(__FILE__) + '/active_fedora/locale/en.yml'

require 'active_fedora/railtie' if defined?(Rails)
Loading

0 comments on commit 141f7d2

Please sign in to comment.