Class: ROM::OpenStruct
- Inherits:
-
Object
- Object
- ROM::OpenStruct
- Defined in:
- lib/rom/open_struct.rb
Overview
ROM’s open structs are used for relations with empty schemas. Such relations may exist in cases like using raw SQL strings where schema was not explicitly defined using ‘view` DSL.
Constant Summary collapse
- IVAR =
-> v { :"@#{v}" }
Instance Method Summary collapse
-
#initialize(attributes) ⇒ OpenStruct
constructor
private
A new instance of OpenStruct.
- #respond_to_missing?(meth, include_private = false) ⇒ Boolean private
Constructor Details
#initialize(attributes) ⇒ OpenStruct
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of OpenStruct.
11 12 13 14 15 |
# File 'lib/rom/open_struct.rb', line 11 def initialize(attributes) attributes.each do |key, value| instance_variable_set(IVAR[key], value) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 32 33 |
# File 'lib/rom/open_struct.rb', line 25 def method_missing(meth, *args, &block) ivar = IVAR[meth] if instance_variables.include?(ivar) instance_variable_get(ivar) else super end end |
Instance Method Details
#respond_to_missing?(meth, include_private = false) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 |
# File 'lib/rom/open_struct.rb', line 18 def respond_to_missing?(meth, include_private = false) super || instance_variables.include?(IVAR[meth]) end |