Permalink
Browse files

add rubocop and fix single quotes interpolation

  • Loading branch information...
1 parent f8348ce commit 6d46d2aa2ebd05c9ed4bbed4ecae2643e11461b7 @coorasse coorasse committed Dec 11, 2016
View
@@ -0,0 +1,14 @@
+Metrics/LineLength:
+ Max: 120
+
+Style/Documentation:
+ Enabled: false
+
+Style/NonNilCheck:
+ IncludeSemanticChanges: true
+
+Style/FrozenStringLiteralComment:
+ Enabled: false
+
+AllCops:
+ TargetRubyVersion: 2.0
View
@@ -1,3 +1,3 @@
-source "https://rubygems.org"
+source 'https://rubygems.org'
gemspec
View
@@ -1,7 +1,7 @@
-require "bundler/gem_tasks"
+require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
-desc "Run RSpec"
+desc 'Run RSpec'
RSpec::Core::RakeTask.new do |t|
t.verbose = false
end
View
@@ -4,22 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cancan/version'
Gem::Specification.new do |s|
- s.name = "cancancan"
+ s.name = 'cancancan'
s.version = CanCan::VERSION
- s.authors = ["Bryan Rite", "Ryan Bates", "Richard Wilson"]
- s.email = "r.crawfordwilson@gmail.com"
- s.homepage = "https://github.com/CanCanCommunity/cancancan"
- s.summary = "Simple authorization solution for Rails."
- s.description = "Continuation of the simple authorization solution for Rails which is decoupled from user roles. All permissions are stored in a single location."
+ s.authors = ['Bryan Rite', 'Ryan Bates', 'Richard Wilson']
+ s.email = 'r.crawfordwilson@gmail.com'
+ s.homepage = 'https://github.com/CanCanCommunity/cancancan'
+ s.summary = 'Simple authorization solution for Rails.'
+ s.description = 'Continuation of the simple authorization solution for Rails which is decoupled from user roles. All permissions are stored in a single location.'
s.platform = Gem::Platform::RUBY
- s.license = "MIT"
+ s.license = 'MIT'
s.files = `git ls-files`.split($/)
s.test_files = `git ls-files -- Appraisals {spec,features,gemfiles}/*`.split($/)
s.executables = `git ls-files -- bin/*`.split($/).map{ |f| File.basename(f) }
- s.require_paths = ["lib"]
+ s.require_paths = ['lib']
- s.required_ruby_version = ">= 2.0.0"
+ s.required_ruby_version = '>= 2.0.0'
s.add_development_dependency 'bundler', '~> 1.3'
s.add_development_dependency 'rake', '~> 10.1.1'
View
@@ -1,4 +1,4 @@
-require "cancan/version"
+require 'cancan/version'
require 'cancan/ability'
require 'cancan/rule'
require 'cancan/controller_resource'
@@ -13,7 +13,7 @@
if defined? ActiveRecord
require 'cancan/model_adapters/active_record_adapter'
if ActiveRecord.respond_to?(:version) &&
- ActiveRecord.version >= Gem::Version.new("4")
+ ActiveRecord.version >= Gem::Version.new('4')
require 'cancan/model_adapters/active_record_4_adapter'
else
require 'cancan/model_adapters/active_record_3_adapter'
@@ -222,7 +222,7 @@ def unauthorized_message(action, subject)
keys = unauthorized_message_keys(action, subject)
variables = {:action => action.to_s}
variables[:subject] = (subject.class == Class ? subject : subject.class).to_s.underscore.humanize.downcase
- message = I18n.translate(nil, variables.merge(:scope => :unauthorized, :default => keys + [""]))
+ message = I18n.translate(nil, variables.merge(:scope => :unauthorized, :default => keys + ['']))
message.blank? ? nil : message
end
@@ -254,13 +254,13 @@ def skip_authorize_resource(*args)
# check_authorization :unless => :devise_controller?
#
def check_authorization(options = {})
- method_name = ActiveSupport.respond_to?(:version) && ActiveSupport.version >= Gem::Version.new("4") ? :after_action : :after_filter
+ method_name = ActiveSupport.respond_to?(:version) && ActiveSupport.version >= Gem::Version.new('4') ? :after_action : :after_filter
block = Proc.new do |controller|
next if controller.instance_variable_defined?(:@_authorized)
next if options[:if] && !controller.send(options[:if])
next if options[:unless] && controller.send(options[:unless])
- raise AuthorizationNotPerformed, "This action failed the check_authorization because it does not authorize_resource. Add skip_authorization_check to bypass this check."
+ raise AuthorizationNotPerformed, 'This action failed the check_authorization because it does not authorize_resource. Add skip_authorization_check to bypass this check.'
end
self.send(method_name, options.slice(:only, :except), &block)
@@ -274,17 +274,17 @@ def check_authorization(options = {})
#
# Any arguments are passed to the +before_action+ it triggers.
def skip_authorization_check(*args)
- method_name = ActiveSupport.respond_to?(:version) && ActiveSupport.version >= Gem::Version.new("4") ? :before_action : :before_filter
+ method_name = ActiveSupport.respond_to?(:version) && ActiveSupport.version >= Gem::Version.new('4') ? :before_action : :before_filter
block = Proc.new{ |controller| controller.instance_variable_set(:@_authorized, true) }
self.send(method_name, *args, &block)
end
def skip_authorization(*args)
- raise ImplementationRemoved, "The CanCan skip_authorization method has been renamed to skip_authorization_check. Please update your code."
+ raise ImplementationRemoved, 'The CanCan skip_authorization method has been renamed to skip_authorization_check. Please update your code.'
end
def cancan_resource_class
- if ancestors.map(&:to_s).include? "InheritedResources::Actions"
+ if ancestors.map(&:to_s).include? 'InheritedResources::Actions'
InheritedResource
else
ControllerResource
@@ -343,7 +343,7 @@ def authorize!(*args)
end
def unauthorized!(message = nil)
- raise ImplementationRemoved, "The unauthorized! method has been removed from CanCan, use authorize! instead."
+ raise ImplementationRemoved, 'The unauthorized! method has been removed from CanCan, use authorize! instead.'
end
# Creates and returns the current user's ability and caches it. If you
@@ -12,7 +12,7 @@ def self.add_before_action(controller_class, method, *args)
end
def self.before_callback_name(options)
- if ActiveSupport.respond_to?(:version) && ActiveSupport.version >= Gem::Version.new("4")
+ if ActiveSupport.respond_to?(:version) && ActiveSupport.version >= Gem::Version.new('4')
options.delete(:prepend) ? :prepend_before_action : :before_action
else
options.delete(:prepend) ? :prepend_before_filter : :before_filter
@@ -24,9 +24,9 @@ def initialize(controller, *args)
@params = controller.params
@options = args.extract_options!
@name = args.first
- raise CanCan::ImplementationRemoved, "The :nested option is no longer supported, instead use :through with separate load/authorize call." if @options[:nested]
- raise CanCan::ImplementationRemoved, "The :name option is no longer supported, instead pass the name as the first argument." if @options[:name]
- raise CanCan::ImplementationRemoved, "The :resource option has been renamed back to :class, use false if no class." if @options[:resource]
+ raise CanCan::ImplementationRemoved, 'The :nested option is no longer supported, instead use :through with separate load/authorize call.' if @options[:nested]
+ raise CanCan::ImplementationRemoved, 'The :name option is no longer supported, instead pass the name as the first argument.' if @options[:name]
+ raise CanCan::ImplementationRemoved, 'The :resource option has been renamed back to :class, use false if no class.' if @options[:resource]
end
def load_and_authorize_resource
@@ -110,8 +110,8 @@ def find_resource
if @options[:find_by]
if resource_base.respond_to? "find_by_#{@options[:find_by]}!"
resource_base.send("find_by_#{@options[:find_by]}!", id_param)
- elsif resource_base.respond_to? "find_by"
- resource_base.send("find_by", { @options[:find_by].to_sym => id_param })
+ elsif resource_base.respond_to? 'find_by'
+ resource_base.send('find_by', { @options[:find_by].to_sym => id_param })
else
resource_base.send(@options[:find_by], id_param)
end
@@ -40,7 +40,7 @@ def initialize(message = nil, action = nil, subject = nil)
@message = message
@action = action
@subject = subject
- @default_message = I18n.t(:"unauthorized.default", :default => "You are not authorized to access this page.")
+ @default_message = I18n.t(:"unauthorized.default", :default => 'You are not authorized to access this page.')
end
def to_s
@@ -28,7 +28,7 @@ def self.override_conditions_hash_matching?(subject, conditions)
# Override if override_conditions_hash_matching? returns true
def self.matches_conditions_hash?(subject, conditions)
- raise NotImplemented, "This model adapter does not support matching on a conditions hash."
+ raise NotImplemented, 'This model adapter does not support matching on a conditions hash.'
end
# Used to determine if this model adapter will override the matching behavior for a specific condition.
@@ -39,7 +39,7 @@ def self.override_condition_matching?(subject, name, value)
# Override if override_condition_matching? returns true
def self.matches_condition?(subject, name, value)
- raise NotImplemented, "This model adapter does not support matching on a specific condition."
+ raise NotImplemented, 'This model adapter does not support matching on a specific condition.'
end
def initialize(model_class, rules)
@@ -49,7 +49,7 @@ def initialize(model_class, rules)
def database_records
# This should be overridden in a subclass to return records which match @rules
- raise NotImplemented, "This model adapter does not support fetching records from the database."
+ raise NotImplemented, 'This model adapter does not support fetching records from the database.'
end
end
end
@@ -59,7 +59,7 @@ def simplify_relations model_class, conditions
v = simplify_relations(relation_class_name.constantize, v)
relation_ids = relation_class_name.constantize.where(v).only(:id).map(&:id)
k = "#{k}_id"
- v = { "$in" => relation_ids }
+ v = { '$in' => relation_ids }
end
[k,v]
}
@@ -1,3 +1,3 @@
module CanCan
- VERSION = "1.15.0"
+ VERSION = '1.15.0'
end
@@ -4,7 +4,7 @@ class AbilityGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
def generate_ability
- copy_file "ability.rb", "app/models/ability.rb"
+ copy_file 'ability.rb', 'app/models/ability.rb'
end
end
end
Oops, something went wrong.

0 comments on commit 6d46d2a

Please sign in to comment.