Module: RPCMapper::Scopes::ClassMethods
- Defined in:
- lib/rpc_mapper/scopes.rb
Instance Method Summary collapse
Instance Method Details
#scope(name, scope_options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rpc_mapper/scopes.rb', line 15 def scope(name, ={}) name = name.to_sym # TRP: Define the scope and merge onto the relation scopes[name] = lambda do |*args| = .is_a?(Proc) ? .call(*args) : if .is_a?(Hash) scoped.() else scoped.merge() end end # TRP: Bind the above block to a method for easy access singleton_class.send(:define_method, name, &scopes[name]) end |
#scoped ⇒ Object
11 12 13 |
# File 'lib/rpc_mapper/scopes.rb', line 11 def scoped current_scope ? relation.merge(current_scope) : relation.clone end |
#scopes ⇒ Object
7 8 9 |
# File 'lib/rpc_mapper/scopes.rb', line 7 def scopes read_inheritable_attribute(:scopes) || write_inheritable_attribute(:scopes, {}) end |