Module: Inform::Context
- Defined in:
- lib/runtime/context.rb
Overview
Define Context module
Constant Summary collapse
- Registry =
Struct.new(:memo).new(nil)
- AttributeFieldReferenceTemplate =
'@%<attribute>s'.freeze
- AttributeSetterMethodTemplate =
'%<attribute>s='.freeze
Class Method Summary collapse
- .definition ⇒ Object
- .each_attribute(obj) ⇒ Object
- .get ⇒ Object
- .get_value(from, attribute) ⇒ Object
- .set(definition) ⇒ Object
- .setter_method(attribute) ⇒ Object
Class Method Details
.definition ⇒ Object
34 35 36 |
# File 'lib/runtime/context.rb', line 34 def definition Inform::Context::Registry.memo end |
.each_attribute(obj) ⇒ Object
59 60 61 62 63 |
# File 'lib/runtime/context.rb', line 59 def each_attribute(obj) get&.members&.each do |attribute| yield(attribute, get_value(obj, attribute)) end end |
.get ⇒ Object
39 40 41 |
# File 'lib/runtime/context.rb', line 39 def get Inform::Context.definition end |
.get_value(from, attribute) ⇒ Object
46 47 48 49 |
# File 'lib/runtime/context.rb', line 46 def get_value(from, attribute) return from.send(attribute) if from.respond_to?(attribute) from.instance_variable_get(format(AttributeFieldReferenceTemplate, attribute: attribute).to_sym) end |
.set(definition) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/runtime/context.rb', line 66 def set(definition) Inform::Context::Registry.memo = definition get&.members&.each do |attribute| Inform::Command.send(:attr_accessor, attribute) unless Inform::Command.respond_to? attribute Inform::Event.send(:attr_accessor, attribute) unless Inform::Event.respond_to? attribute end definition end |
.setter_method(attribute) ⇒ Object
54 55 56 |
# File 'lib/runtime/context.rb', line 54 def setter_method(attribute) format(AttributeSetterMethodTemplate, attribute: attribute).to_sym end |