Module: Resourced::Resource::InstanceMethods
- Defined in:
- lib/resourced.rb
Instance Attribute Summary collapse
-
#chain ⇒ Object
readonly
Returns the value of attribute chain.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#scope ⇒ Object
Returns the value of attribute scope.
Instance Method Summary collapse
-
#context(&block) ⇒ Object
Run external code in context of resource.
- #initialize(params, scope = nil) ⇒ Object
Instance Attribute Details
#chain ⇒ Object (readonly)
Returns the value of attribute chain.
17 18 19 |
# File 'lib/resourced.rb', line 17 def chain @chain end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
17 18 19 |
# File 'lib/resourced.rb', line 17 def key @key end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
17 18 19 |
# File 'lib/resourced.rb', line 17 def model @model end |
#scope ⇒ Object
Returns the value of attribute scope.
16 17 18 |
# File 'lib/resourced.rb', line 16 def scope @scope end |
Instance Method Details
#context(&block) ⇒ Object
Run external code in context of resource
Examples:
resource = UserResource.new(params, scope)
subj = "john"
resource.context do
chain.where(name: subj)
end
30 31 32 33 34 35 36 |
# File 'lib/resourced.rb', line 30 def context(&block) if block_given? @chain = self.instance_eval(&block) end self end |
#initialize(params, scope = nil) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/resourced.rb', line 9 def initialize(params, scope=nil) @scope = scope @model = self.class.instance_variable_get(:@model) @key = self.class.instance_variable_get(:@key) @chain = @model super end |