Skip to content

Commit

Permalink
Adopt rubocop code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Shaffer committed Jan 30, 2015
1 parent aedc1af commit 4bce679
Show file tree
Hide file tree
Showing 19 changed files with 717 additions and 607 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inherit_from: .rubocop_todo.yml
118 changes: 118 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-01-30 11:07:37 -0800 using RuboCop version 0.28.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Lint/AmbiguousOperator:
Enabled: false

# Offense count: 1
Lint/HandleExceptions:
Enabled: false

# Offense count: 5
Lint/ShadowingOuterLocalVariable:
Enabled: false

# Offense count: 1
Lint/UselessAccessModifier:
Enabled: false

# Offense count: 7
Lint/UselessAssignment:
Enabled: false

# Offense count: 11
Metrics/AbcSize:
Max: 90

# Offense count: 3
Metrics/BlockNesting:
Max: 4

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 277

# Offense count: 6
Metrics/CyclomaticComplexity:
Max: 15

# Offense count: 345
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 274

# Offense count: 10
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 51

# Offense count: 5
Metrics/PerceivedComplexity:
Max: 19

# Offense count: 1
Style/AccessorMethodName:
Enabled: false

# Offense count: 2
# Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep.
Style/CaseIndentation:
Enabled: false

# Offense count: 18
Style/Documentation:
Enabled: false

# Offense count: 1
Style/EachWithObject:
Enabled: false

# Offense count: 1
Style/EvenOdd:
Enabled: false

# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Enabled: false

# Offense count: 1
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
Enabled: false

# Offense count: 2
Style/NestedTernaryOperator:
Enabled: false

# Offense count: 1
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
Style/Next:
Enabled: false

# Offense count: 4
Style/RegexpLiteral:
MaxSlashes: 0

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon:
Enabled: false

# Offense count: 1
# Configuration parameters: Methods.
Style/SingleLineBlockParams:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist.
Style/TrivialAccessors:
Enabled: false
2 changes: 1 addition & 1 deletion Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch('spec/spec_helper.rb') { 'spec' }
end
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
require 'bundler/gem_tasks'

require "rspec/core/rake_task"
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
task default: :spec
37 changes: 19 additions & 18 deletions brainstem.gemspec
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
# -*- encoding: utf-8 -*-
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
require "brainstem/version"
require 'brainstem/version'

Gem::Specification.new do |gem|
gem.name = "brainstem"
gem.authors = ["Mavenlink"]
gem.email = ["[email protected]"]
gem.description = %q{Brainstem allows you to create rich API presenters that know how to filter, sort, and include associations.}
gem.summary = %q{ActiveRecord presenters with a rich request API}
gem.homepage = "http://github.com/mavenlink/brainstem"
gem.license = "MIT"
gem.name = 'brainstem'
gem.authors = ['Mavenlink']
gem.email = ['[email protected]']
gem.description = 'Brainstem allows you to create rich API presenters that know how to filter, sort, and include associations.'
gem.summary = 'ActiveRecord presenters with a rich request API'
gem.homepage = 'http://github.com/mavenlink/brainstem'
gem.license = 'MIT'

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

gem.add_dependency "activerecord", ">= 3.2"
gem.add_dependency 'activerecord', '>= 3.2'

gem.add_development_dependency "rake"
gem.add_development_dependency "redcarpet" # for markdown in yard
gem.add_development_dependency "rr"
gem.add_development_dependency "rspec"
gem.add_development_dependency "sqlite3"
gem.add_development_dependency "yard"
gem.add_development_dependency 'rake'
gem.add_development_dependency 'redcarpet' # for markdown in yard
gem.add_development_dependency 'rr'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'rubocop'
gem.add_development_dependency 'sqlite3'
gem.add_development_dependency 'yard'
end
22 changes: 11 additions & 11 deletions lib/brainstem.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
require "brainstem/version"
require "brainstem/presenter"
require "brainstem/presenter_collection"
require "brainstem/controller_methods"
require 'brainstem/version'
require 'brainstem/presenter'
require 'brainstem/presenter_collection'
require 'brainstem/controller_methods'

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

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

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

Expand All @@ -46,7 +46,7 @@ def self.logger
if defined?(Rails)
Rails.logger
else
require "logger"
require 'logger'
Logger.new(STDOUT)
end
end
Expand All @@ -55,7 +55,7 @@ def self.logger
# Sets a new Brainstem logger.
# @param [Logger] logger A new Brainstem logger.
# @return [Logger] The new Brainstem logger.
def self.logger=(logger)
@logger = logger
class << self
attr_writer :logger
end
end
6 changes: 3 additions & 3 deletions lib/brainstem/association_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def initialize(*args, &block)
@ignore_type = options[:ignore_type] || false
@restrict_to_only = options[:restrict_to_only] || false
if block_given?
raise ArgumentError, "options[:json_name] is required when using a block" unless options[:json_name]
raise ArgumentError, "Method name is invalid with a block" if method_name
fail ArgumentError, 'options[:json_name] is required when using a block' unless options[:json_name]
fail ArgumentError, 'Method name is invalid with a block' if method_name
@block = block
elsif method_name
@method_name = method_name
else
raise ArgumentError, "Method name or block is required"
fail ArgumentError, 'Method name or block is required'
end
end

Expand Down
10 changes: 4 additions & 6 deletions lib/brainstem/controller_methods.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
module Brainstem

# ControllerMethods are intended to be included into controllers that will be handling requests for presented objects.
# The present method will pass through +params+, so that any allowed and requested includes, filters, sort orders
# will be applied to the presented data.
module ControllerMethods

# Return a Ruby hash that contains models requested by the user's params and allowed
# by the +name+ presenter's configuration.
#
Expand All @@ -16,7 +14,7 @@ module ControllerMethods
# @yield (see PresenterCollection#presenting)
# @return (see PresenterCollection#presenting)
def present(name, options = {}, &block)
Brainstem.presenter_collection(options[:namespace]).presenting(name, options.reverse_merge(:params => params), &block)
Brainstem.presenter_collection(options[:namespace]).presenting(name, options.reverse_merge(params: params), &block)
end

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

if objects.is_a?(ActiveRecord::Relation) || objects.is_a?(Array)
raise ActiveRecord::RecordNotFound if objects.empty?
fail ActiveRecord::RecordNotFound if objects.empty?
klass = objects.first.class
ids = objects.map(&:id)
else
Expand All @@ -40,7 +38,7 @@ def present_object(objects, options = {})
end

options[:as] = (options[:key_map] || {})[klass.to_s] || klass.table_name
present(klass, options) { klass.where(:id => ids) }
present(klass, options) { klass.where(id: ids) }
end
alias_method :present_objects, :present_object
end
Expand Down
Loading

0 comments on commit 4bce679

Please sign in to comment.