Module: Matestack::Ui::Core::Properties
- Included in:
- Base
- Defined in:
- lib/matestack/ui/core/properties.rb
Defined Under Namespace
Modules: ClassMethods, Initializer
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
6
7
8
9
|
# File 'lib/matestack/ui/core/properties.rb', line 6
def self.included(base)
base.extend ClassMethods
base.send :prepend, Initializer
end
|
Instance Method Details
#context ⇒ Object
Also known as:
ctx
47
48
49
|
# File 'lib/matestack/ui/core/properties.rb', line 47
def context
@context ||= OpenStruct.new
end
|
#create_context ⇒ Object
60
61
62
63
|
# File 'lib/matestack/ui/core/properties.rb', line 60
def create_context
create_context_for_properties(self.required_property_keys, required: true)
create_context_for_properties(self.optional_property_keys)
end
|
#create_context_for_properties(properties, required: false) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/matestack/ui/core/properties.rb', line 65
def create_context_for_properties(properties, required: false)
properties.uniq.each do |property|
if property.is_a? Hash
property.each do |key, value|
method_name = value[:as] || key
raise "required property '#{key}' is missing for '#{self.class}'" if required && self.options[key].nil?
context.send(:"#{method_name}=", self.options.delete(key))
end
else
raise "required property '#{property}' is missing for '#{self.class}'" if required && self.options[property].nil?
context.send(:"#{property}=", self.options.delete(property))
end
end if properties
end
|
#optional_property_keys ⇒ Object
56
57
58
|
# File 'lib/matestack/ui/core/properties.rb', line 56
def optional_property_keys
self.class.optional_property_keys || []
end
|
#required_property_keys ⇒ Object
52
53
54
|
# File 'lib/matestack/ui/core/properties.rb', line 52
def required_property_keys
self.class.required_property_keys || []
end
|
#set_text ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/matestack/ui/core/properties.rb', line 80
def set_text
self.text = self.options.delete(:text) if self.options.has_key?(:text)
self.context.text = self.text
end
|