Skip to content

Commit 4bce679

Browse files
author
Chad Shaffer
committed
Adopt rubocop code style
1 parent aedc1af commit 4bce679

19 files changed

Lines changed: 717 additions & 607 deletions

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
inherit_from: .rubocop_todo.yml

.rubocop_todo.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# This configuration was generated by `rubocop --auto-gen-config`
2+
# on 2015-01-30 11:07:37 -0800 using RuboCop version 0.28.0.
3+
# The point is for the user to remove these configuration records
4+
# one by one as the offenses are removed from the code base.
5+
# Note that changes in the inspected code, or installation of new
6+
# versions of RuboCop, may require this file to be generated again.
7+
8+
# Offense count: 1
9+
Lint/AmbiguousOperator:
10+
Enabled: false
11+
12+
# Offense count: 1
13+
Lint/HandleExceptions:
14+
Enabled: false
15+
16+
# Offense count: 5
17+
Lint/ShadowingOuterLocalVariable:
18+
Enabled: false
19+
20+
# Offense count: 1
21+
Lint/UselessAccessModifier:
22+
Enabled: false
23+
24+
# Offense count: 7
25+
Lint/UselessAssignment:
26+
Enabled: false
27+
28+
# Offense count: 11
29+
Metrics/AbcSize:
30+
Max: 90
31+
32+
# Offense count: 3
33+
Metrics/BlockNesting:
34+
Max: 4
35+
36+
# Offense count: 2
37+
# Configuration parameters: CountComments.
38+
Metrics/ClassLength:
39+
Max: 277
40+
41+
# Offense count: 6
42+
Metrics/CyclomaticComplexity:
43+
Max: 15
44+
45+
# Offense count: 345
46+
# Configuration parameters: AllowURI, URISchemes.
47+
Metrics/LineLength:
48+
Max: 274
49+
50+
# Offense count: 10
51+
# Configuration parameters: CountComments.
52+
Metrics/MethodLength:
53+
Max: 51
54+
55+
# Offense count: 5
56+
Metrics/PerceivedComplexity:
57+
Max: 19
58+
59+
# Offense count: 1
60+
Style/AccessorMethodName:
61+
Enabled: false
62+
63+
# Offense count: 2
64+
# Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep.
65+
Style/CaseIndentation:
66+
Enabled: false
67+
68+
# Offense count: 18
69+
Style/Documentation:
70+
Enabled: false
71+
72+
# Offense count: 1
73+
Style/EachWithObject:
74+
Enabled: false
75+
76+
# Offense count: 1
77+
Style/EvenOdd:
78+
Enabled: false
79+
80+
# Offense count: 1
81+
# Configuration parameters: MinBodyLength.
82+
Style/GuardClause:
83+
Enabled: false
84+
85+
# Offense count: 1
86+
# Configuration parameters: MaxLineLength.
87+
Style/IfUnlessModifier:
88+
Enabled: false
89+
90+
# Offense count: 2
91+
Style/NestedTernaryOperator:
92+
Enabled: false
93+
94+
# Offense count: 1
95+
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
96+
Style/Next:
97+
Enabled: false
98+
99+
# Offense count: 4
100+
Style/RegexpLiteral:
101+
MaxSlashes: 0
102+
103+
# Offense count: 1
104+
# Cop supports --auto-correct.
105+
# Configuration parameters: AllowAsExpressionSeparator.
106+
Style/Semicolon:
107+
Enabled: false
108+
109+
# Offense count: 1
110+
# Configuration parameters: Methods.
111+
Style/SingleLineBlockParams:
112+
Enabled: false
113+
114+
# Offense count: 1
115+
# Cop supports --auto-correct.
116+
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist.
117+
Style/TrivialAccessors:
118+
Enabled: false

Guardfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
guard 'rspec' do
55
watch(%r{^spec/.+_spec\.rb$})
66
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7-
watch('spec/spec_helper.rb') { "spec" }
7+
watch('spec/spec_helper.rb') { 'spec' }
88
end

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env rake
2-
require "bundler/gem_tasks"
2+
require 'bundler/gem_tasks'
33

4-
require "rspec/core/rake_task"
4+
require 'rspec/core/rake_task'
55
RSpec::Core::RakeTask.new(:spec)
6-
task :default => :spec
6+
task default: :spec

brainstem.gemspec

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
# -*- encoding: utf-8 -*-
22
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3-
require "brainstem/version"
3+
require 'brainstem/version'
44

55
Gem::Specification.new do |gem|
6-
gem.name = "brainstem"
7-
gem.authors = ["Mavenlink"]
8-
gem.email = ["opensource@mavenlink.com"]
9-
gem.description = %q{Brainstem allows you to create rich API presenters that know how to filter, sort, and include associations.}
10-
gem.summary = %q{ActiveRecord presenters with a rich request API}
11-
gem.homepage = "http://github.com/mavenlink/brainstem"
12-
gem.license = "MIT"
6+
gem.name = 'brainstem'
7+
gem.authors = ['Mavenlink']
8+
gem.email = ['opensource@mavenlink.com']
9+
gem.description = 'Brainstem allows you to create rich API presenters that know how to filter, sort, and include associations.'
10+
gem.summary = 'ActiveRecord presenters with a rich request API'
11+
gem.homepage = 'http://github.com/mavenlink/brainstem'
12+
gem.license = 'MIT'
1313

14-
gem.files = Dir["**/*"]
15-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14+
gem.files = Dir['**/*']
15+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
1616
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17-
gem.require_paths = ["lib"]
17+
gem.require_paths = ['lib']
1818
gem.version = Brainstem::VERSION
1919

20-
gem.add_dependency "activerecord", ">= 3.2"
20+
gem.add_dependency 'activerecord', '>= 3.2'
2121

22-
gem.add_development_dependency "rake"
23-
gem.add_development_dependency "redcarpet" # for markdown in yard
24-
gem.add_development_dependency "rr"
25-
gem.add_development_dependency "rspec"
26-
gem.add_development_dependency "sqlite3"
27-
gem.add_development_dependency "yard"
22+
gem.add_development_dependency 'rake'
23+
gem.add_development_dependency 'redcarpet' # for markdown in yard
24+
gem.add_development_dependency 'rr'
25+
gem.add_development_dependency 'rspec'
26+
gem.add_development_dependency 'rubocop'
27+
gem.add_development_dependency 'sqlite3'
28+
gem.add_development_dependency 'yard'
2829
end

lib/brainstem.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
require "brainstem/version"
2-
require "brainstem/presenter"
3-
require "brainstem/presenter_collection"
4-
require "brainstem/controller_methods"
1+
require 'brainstem/version'
2+
require 'brainstem/presenter'
3+
require 'brainstem/presenter_collection'
4+
require 'brainstem/controller_methods'
55

66
# The Brainstem module itself contains a +default_namespace+ class attribute and a few helpers that make managing +PresenterCollections+ and their corresponding namespaces easier.
77
module Brainstem
88
# Sets {default_namespace} to a new value.
99
# @param [String] namespace
1010
# @return [String] the new default namespace
11-
def self.default_namespace=(namespace)
12-
@default_namespace = namespace
11+
class << self
12+
attr_writer :default_namespace
1313
end
1414

1515
# The namespace that will be used by {presenter_collection} and {add_presenter_class} if none is given or implied.
1616
# @return [String] the default namespace
1717
def self.default_namespace
18-
@default_namespace || "none"
18+
@default_namespace || 'none'
1919
end
2020

2121
# @param [String] namespace
@@ -36,7 +36,7 @@ def self.add_presenter_class(presenter_class, *klasses)
3636
# @param [Class] klass The Ruby class whose namespace we would like to know.
3737
# @return [String] The name of the module containing the passed-in class.
3838
def self.namespace_of(klass)
39-
names = klass.to_s.split("::")
39+
names = klass.to_s.split('::')
4040
names[-2] ? names[-2] : default_namespace
4141
end
4242

@@ -46,7 +46,7 @@ def self.logger
4646
if defined?(Rails)
4747
Rails.logger
4848
else
49-
require "logger"
49+
require 'logger'
5050
Logger.new(STDOUT)
5151
end
5252
end
@@ -55,7 +55,7 @@ def self.logger
5555
# Sets a new Brainstem logger.
5656
# @param [Logger] logger A new Brainstem logger.
5757
# @return [Logger] The new Brainstem logger.
58-
def self.logger=(logger)
59-
@logger = logger
58+
class << self
59+
attr_writer :logger
6060
end
6161
end

lib/brainstem/association_field.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def initialize(*args, &block)
3333
@ignore_type = options[:ignore_type] || false
3434
@restrict_to_only = options[:restrict_to_only] || false
3535
if block_given?
36-
raise ArgumentError, "options[:json_name] is required when using a block" unless options[:json_name]
37-
raise ArgumentError, "Method name is invalid with a block" if method_name
36+
fail ArgumentError, 'options[:json_name] is required when using a block' unless options[:json_name]
37+
fail ArgumentError, 'Method name is invalid with a block' if method_name
3838
@block = block
3939
elsif method_name
4040
@method_name = method_name
4141
else
42-
raise ArgumentError, "Method name or block is required"
42+
fail ArgumentError, 'Method name or block is required'
4343
end
4444
end
4545

lib/brainstem/controller_methods.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
module Brainstem
2-
32
# ControllerMethods are intended to be included into controllers that will be handling requests for presented objects.
43
# The present method will pass through +params+, so that any allowed and requested includes, filters, sort orders
54
# will be applied to the presented data.
65
module ControllerMethods
7-
86
# Return a Ruby hash that contains models requested by the user's params and allowed
97
# by the +name+ presenter's configuration.
108
#
@@ -16,7 +14,7 @@ module ControllerMethods
1614
# @yield (see PresenterCollection#presenting)
1715
# @return (see PresenterCollection#presenting)
1816
def present(name, options = {}, &block)
19-
Brainstem.presenter_collection(options[:namespace]).presenting(name, options.reverse_merge(:params => params), &block)
17+
Brainstem.presenter_collection(options[:namespace]).presenting(name, options.reverse_merge(params: params), &block)
2018
end
2119

2220
# Similar to ControllerMethods#present, but always returns all of the given objects, not just those that match any provided
@@ -27,10 +25,10 @@ def present(name, options = {}, &block)
2725
# only required if the name cannot be inferred.
2826
# @return (see PresenterCollection#presenting)
2927
def present_object(objects, options = {})
30-
options.merge!(:params => params, :apply_default_filters => false)
28+
options.merge!(params: params, apply_default_filters: false)
3129

3230
if objects.is_a?(ActiveRecord::Relation) || objects.is_a?(Array)
33-
raise ActiveRecord::RecordNotFound if objects.empty?
31+
fail ActiveRecord::RecordNotFound if objects.empty?
3432
klass = objects.first.class
3533
ids = objects.map(&:id)
3634
else
@@ -40,7 +38,7 @@ def present_object(objects, options = {})
4038
end
4139

4240
options[:as] = (options[:key_map] || {})[klass.to_s] || klass.table_name
43-
present(klass, options) { klass.where(:id => ids) }
41+
present(klass, options) { klass.where(id: ids) }
4442
end
4543
alias_method :present_objects, :present_object
4644
end

0 commit comments

Comments
 (0)