Module: Daylight::Refinements::ClassMethods
- Defined in:
- lib/daylight/refinements.rb
Instance Attribute Summary collapse
-
#scope_names ⇒ Object
Returns the value of attribute scope_names.
Instance Method Summary collapse
-
#first(*args) ⇒ Object
Use limits if no argument are supplied.
-
#scopes(*names) ⇒ Object
Define scopes that the class can be refined by.
Instance Attribute Details
#scope_names ⇒ Object
Returns the value of attribute scope_names.
11 12 13 |
# File 'lib/daylight/refinements.rb', line 11 def scope_names @scope_names end |
Instance Method Details
#first(*args) ⇒ Object
Use limits if no argument are supplied. Otherwise, continue to use the ActiveRecord version which retrieves the full result set and calls first.
See: ActiveRecord::Base#first Daylight::ResourceProxy#first
42 43 44 |
# File 'lib/daylight/refinements.rb', line 42 def first *args args.size.zero? ? resource_proxy.first : super end |
#scopes(*names) ⇒ Object
Define scopes that the class can be refined by
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/daylight/refinements.rb', line 14 def scopes *names self.scope_names ||= [] names.each do |scope| self.scope_names << scope # hand chaining duties off to the ResourceProxy instance define_singleton_method scope do resource_proxy.append_scope(scope) end # ResourceProxy instance also needs to respond to scopes resource_proxy_class.send(:define_method, scope) do append_scope(scope) end end # self.scope_names.freeze end |