Module: Consul::Util
Instance Method Summary collapse
- #adjective_and_argument(*args) ⇒ Object
- #around_action(controller_class, *args, &block) ⇒ Object
- #before_action(controller_class, *args, &block) ⇒ Object
- #collection?(value) ⇒ Boolean
-
#define_default_scope(klass, conditions) ⇒ Object
This method does not support dynamic default scopes via lambdas (as does #define_scope), because it is currently not required.
- #define_scope(klass, name, lambda) ⇒ Object
- #scope?(value) ⇒ Boolean
- #scope_selects_all_records?(scope) ⇒ Boolean
- #skip_before_action(controller_class, name, options) ⇒ Object
Instance Method Details
#adjective_and_argument(*args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/consul/util.rb', line 36 def adjective_and_argument(*args) if args.size > 1 adjective = args[0] record = args[1] else adjective = nil record = args[0] end [adjective, record] end |
#around_action(controller_class, *args, &block) ⇒ Object
59 60 61 |
# File 'lib/consul/util.rb', line 59 def around_action(controller_class, *args, &block) controller_class.around_action *args, &block end |
#before_action(controller_class, *args, &block) ⇒ Object
55 56 57 |
# File 'lib/consul/util.rb', line 55 def before_action(controller_class, *args, &block) controller_class.before_action *args, &block end |
#collection?(value) ⇒ Boolean
17 18 19 |
# File 'lib/consul/util.rb', line 17 def collection?(value) value.is_a?(Array) || value.is_a?(Set) end |
#define_default_scope(klass, conditions) ⇒ Object
This method does not support dynamic default scopes via lambdas (as does #define_scope), because it is currently not required.
30 31 32 33 34 |
# File 'lib/consul/util.rb', line 30 def define_default_scope(klass, conditions) klass.send :default_scope do klass.scoped(conditions) end end |
#define_scope(klass, name, lambda) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/consul/util.rb', line 21 def define_scope(klass, name, lambda) klass.send :scope, name, lambda { |*args| = lambda.call(*args) klass.scoped(.slice *EdgeRider::Scoped::VALID_FIND_OPTIONS) } end |
#scope?(value) ⇒ Boolean
13 14 15 |
# File 'lib/consul/util.rb', line 13 def scope?(value) value.respond_to?(:scoped) end |
#scope_selects_all_records?(scope) ⇒ Boolean
5 6 7 8 9 10 11 |
# File 'lib/consul/util.rb', line 5 def scope_selects_all_records?(scope) scope = scope.scoped scope_sql = scope.to_sql quoted_table_name = Regexp.quote(scope.connection.quote_table_name(scope.table_name)) all_sql_pattern = /\ASELECT (#{quoted_table_name}\.)?\* FROM #{quoted_table_name}\z/ scope_sql.squish =~ all_sql_pattern end |
#skip_before_action(controller_class, name, options) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/consul/util.rb', line 47 def skip_before_action(controller_class, name, ) # Every `power` in a controller will skip the power check filter. After the 1st time, Rails will raise # an error because there is no `unchecked_power` action to skip any more. # To avoid this, we add the following extra option. # See http://api.rubyonrails.org/classes/ActiveSupport/Callbacks/ClassMethods.html#method-i-skip_callback controller_class.skip_before_action name, { :raise => false }.merge!() end |