Class: HALPresenter::Collection::Properties
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#attribute(*args, **kwargs, &block) ⇒ Object
-
#change_context(context) ⇒ Object
-
#curie(rel, value = nil, **kwargs, &block) ⇒ Object
-
#embed(*args, **kwargs, &block) ⇒ Object
-
#initialize(name, scope, &block) ⇒ Properties
constructor
A new instance of Properties.
-
#link(rel, value = nil, **kwargs, &block) ⇒ Object
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
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
#name ⇒ Object
Returns the value of attribute name.
14
15
16
|
# File 'lib/hal_presenter/collection.rb', line 14
def name
@name
end
|
#scope ⇒ Object
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
|
#link(rel, value = nil, **kwargs, &block) ⇒ Object
28
29
30
31
|
# File 'lib/hal_presenter/collection.rb', line 28
def link(rel, value = nil, **kwargs, &block)
kwargs[:context] = scope
super
end
|