Module: Inform::Context
- Included in:
- Ephemeral::Object
- Defined in:
- lib/story_teller/context.rb
Overview
Define Context module
Constant Summary collapse
- AttributeFieldReferenceTemplate =
'@%<attribute>s'.freeze
- AttributeSetterMethodTemplate =
'%<attribute>s='.freeze
Class Attribute Summary collapse
-
.definition ⇒ Object
(also: get)
readonly
Returns the value of attribute definition.
Class Method Summary collapse
- .each_attribute(obj) ⇒ Object
- .get_value(from, attribute) ⇒ Object
- .set(definition) ⇒ Object
- .setter_method(attribute) ⇒ Object
Class Attribute Details
.definition ⇒ Object (readonly) Also known as: get
Returns the value of attribute definition.
43 44 45 |
# File 'lib/story_teller/context.rb', line 43 def definition @definition end |
Class Method Details
.each_attribute(obj) ⇒ Object
55 56 57 58 59 |
# File 'lib/story_teller/context.rb', line 55 def each_attribute(obj) @definition&.members&.each do |attribute| yield(attribute, get_value(obj, attribute)) end end |
.get_value(from, attribute) ⇒ Object
46 47 48 49 |
# File 'lib/story_teller/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
61 62 63 64 65 66 67 68 |
# File 'lib/story_teller/context.rb', line 61 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
51 52 53 |
# File 'lib/story_teller/context.rb', line 51 def setter_method(attribute) format(AttributeSetterMethodTemplate, attribute: attribute).to_sym end |