Module: Resourced::Resource::InstanceMethods

Defined in:
lib/resourced.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chainObject (readonly)

Returns the value of attribute chain.



17
18
19
# File 'lib/resourced.rb', line 17

def chain
  @chain
end

#keyObject (readonly)

Returns the value of attribute key.



17
18
19
# File 'lib/resourced.rb', line 17

def key
  @key
end

#modelObject (readonly)

Returns the value of attribute model.



17
18
19
# File 'lib/resourced.rb', line 17

def model
  @model
end

#scopeObject

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