Module: AWS::Record::Scopes
- Included in:
- Base
- Defined in:
- lib/aws/record/scopes.rb
Instance Method Summary collapse
-
#scope(name, scope = nil, &block) ⇒ Object
Adds a scoped finder method to this class.
Instance Method Details
#scope(name, scope = nil, &block) ⇒ Object
Adds a scoped finder method to this class. Given a call to scope like:
scope :top_10, order(:popularity, :desc).limit(10)
Then you can call the method top_10
on the class and it will return an enumerable scope object with the given find conditions.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aws/record/scopes.rb', line 33 def scope name, scope = nil, &block raise ArgumentError, "only a scope or block may be passed, not both" if scope and block_given? method_definition = scope ? lambda{ scope } : block extend(Module.new { define_method(name, &method_definition) }) end |