Class: AmsHal::Embed
- Inherits:
-
Object
- Object
- AmsHal::Embed
- Includes:
- ActiveModelSerializers::SerializationContext::UrlHelpers
- Defined in:
- lib/ams_hal/embed.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(serializer, name, options = {}, &block) ⇒ Embed
constructor
A new instance of Embed.
- #resource_for(serializer) ⇒ Object
Constructor Details
#initialize(serializer, name, options = {}, &block) ⇒ Embed
Returns a new instance of Embed.
9 10 11 12 13 |
# File 'lib/ams_hal/embed.rb', line 9 def initialize(serializer, name, = {}, &block) @name = name = @block = block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
31 32 33 34 |
# File 'lib/ams_hal/embed.rb', line 31 def method_missing(method, *args, &block) return super unless @self_before_instance_eval @self_before_instance_eval.send method, *args, &block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/ams_hal/embed.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/ams_hal/embed.rb', line 7 def end |
Instance Method Details
#resource_for(serializer) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ams_hal/embed.rb', line 15 def resource_for(serializer) @object = serializer.object @scope = serializer.scope @self_before_instance_eval = nil # Use the return value of the block unless it is nil. if @block @self_before_instance_eval = eval "self", @block.binding @resource = instance_eval(&@block) else @resource = @object.public_send(name) end end |