Class: HALDecorator::SerializeHooks::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/hal_decorator/serialize_hooks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Hook

Returns a new instance of Hook.



9
10
11
# File 'lib/hal_decorator/serialize_hooks.rb', line 9

def initialize(&block)
  @block = block
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/hal_decorator/serialize_hooks.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/hal_decorator/serialize_hooks.rb', line 7

def options
  @options
end

#resourceObject (readonly)

Returns the value of attribute resource.



7
8
9
# File 'lib/hal_decorator/serialize_hooks.rb', line 7

def resource
  @resource
end

Instance Method Details

#run(resource, options, arg) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/hal_decorator/serialize_hooks.rb', line 13

def run(resource, options, arg)
  @resource = resource
  @options = options
  instance_exec(arg, &@block) if @block
ensure
  @resource = nil
  @options = nil
end