Class: HALPresenter::Collection::Properties

Inherits:
Object
  • Object
show all
Includes:
Attributes, HALPresenter::Curies, Embedded, Links
Defined in:
lib/hal_presenter/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, scope, &block) ⇒ Properties

Returns a new instance of Properties.



16
17
18
19
20
21
# File 'lib/hal_presenter/collection.rb', line 16

def initialize(name, scope, &block)
  @name = name
  return unless block_given?
  @scope = scope
  instance_exec(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



50
51
52
53
54
# File 'lib/hal_presenter/collection.rb', line 50

def method_missing(method, *args, &block)
  return super unless scope&.respond_to? method
  define_singleton_method(method) { |*a, &b| scope.public_send method, *a, &b }
  public_send(method, *args, &block)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/hal_presenter/collection.rb', line 14

def name
  @name
end

#scopeObject (readonly)

Returns the value of attribute scope.



14
15
16
# File 'lib/hal_presenter/collection.rb', line 14

def scope
  @scope
end

Instance Method Details

#attribute(*args, **kwargs, &block) ⇒ Object



23
24
25
26
# File 'lib/hal_presenter/collection.rb', line 23

def attribute(*args, **kwargs, &block)
  kwargs[:context] = scope
  super
end

#change_context(context) ⇒ Object



43
44
45
46
# File 'lib/hal_presenter/collection.rb', line 43

def change_context(context)
  @scope = context
  self
end

#curie(rel, value = nil, **kwargs, &block) ⇒ Object



33
34
35
36
# File 'lib/hal_presenter/collection.rb', line 33

def curie(rel, value = nil, **kwargs, &block)
  kwargs[:context] = scope
  super
end

#embed(*args, **kwargs, &block) ⇒ Object



38
39
40
41
# File 'lib/hal_presenter/collection.rb', line 38

def embed(*args, **kwargs, &block)
  kwargs[:context] = scope
  super
end


28
29
30
31
# File 'lib/hal_presenter/collection.rb', line 28

def link(rel, value = nil, **kwargs, &block)
  kwargs[:context] = scope
  super
end