Module: Inform::Context
- Included in:
- Object
- Defined in:
- lib/story_teller/context.rb
Overview
Define Context module
Constant Summary collapse
- AttributeFieldReferenceTemplate =
'@%<attribute>s'.freeze
- AttributeSetterMethodTemplate =
'%<attribute>s='.freeze
Class Method Summary collapse
- .definition ⇒ Object (also: get)
- .each_attribute(obj) ⇒ Object
- .get_value(from, attribute) ⇒ Object
- .set(definition) ⇒ Object
- .setter_method(attribute) ⇒ Object
Class Method Details
.definition ⇒ Object Also known as: get
41 42 43 |
# File 'lib/story_teller/context.rb', line 41 def definition @definition end |
.each_attribute(obj) ⇒ Object
60 61 62 63 64 |
# File 'lib/story_teller/context.rb', line 60 def each_attribute(obj) @definition&.members&.each do |attribute| yield(attribute, get_value(obj, attribute)) end end |
.get_value(from, attribute) ⇒ Object
49 50 51 52 |
# File 'lib/story_teller/context.rb', line 49 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/story_teller/context.rb', line 66 def set(definition) @definition = definition @definition&.members&.each do |attribute| StoryTeller::Command.send(:attr_accessor, attribute) unless StoryTeller::Command.respond_to? attribute Inform::Event.send(:attr_accessor, attribute) unless Inform::Event.respond_to? attribute end @definition end |
.setter_method(attribute) ⇒ Object
56 57 58 |
# File 'lib/story_teller/context.rb', line 56 def setter_method(attribute) format(AttributeSetterMethodTemplate, attribute: attribute).to_sym end |