Class: Diecut::ContextHandler
- Inherits:
-
Object
- Object
- Diecut::ContextHandler
- Defined in:
- lib/diecut/context-handler.rb
Instance Attribute Summary collapse
-
#context_class ⇒ Object
Returns the value of attribute context_class.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
-
#ui_class ⇒ Object
Returns the value of attribute ui_class.
Instance Method Summary collapse
- #apply_option_to_ui(option) ⇒ Object
- #apply_simple_default(default) ⇒ Object
- #apply_simple_defaults ⇒ Object
- #apply_to_ui ⇒ Object
- #backfill_options_to_context ⇒ Object
- #backfill_to_context(option) ⇒ Object
Instance Attribute Details
#context_class ⇒ Object
Returns the value of attribute context_class.
4 5 6 |
# File 'lib/diecut/context-handler.rb', line 4 def context_class @context_class end |
#plugins ⇒ Object
Returns the value of attribute plugins.
4 5 6 |
# File 'lib/diecut/context-handler.rb', line 4 def plugins @plugins end |
#ui_class ⇒ Object
Returns the value of attribute ui_class.
4 5 6 |
# File 'lib/diecut/context-handler.rb', line 4 def ui_class @ui_class end |
Instance Method Details
#apply_option_to_ui(option) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/diecut/context-handler.rb', line 56 def apply_option_to_ui(option) ui_class.[option.name] = option if option.has_context_path? = context_class.walk_path(option.context_path).last. if option.has_default? ui_class.setting(option.name, option.default_value) elsif .is?(:defaulting) ui_class.setting(option.name, .default_value) else ui_class.setting(option.name) end else if option.has_default? ui_class.setting(option.name, option.default_value) else ui_class.setting(option.name) end end end |
#apply_simple_default(default) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/diecut/context-handler.rb', line 46 def apply_simple_default(default) target = context_class.walk_path(default.context_path).last if target..nil? raise UnusedDefault, "No template uses a value at #{default.context_path.inspect}" else target..default_value = default.value target..is(:defaulting) end end |
#apply_simple_defaults ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/diecut/context-handler.rb', line 6 def apply_simple_defaults plugins.each do |plugin| plugin.context_defaults.each do |default| next unless default.simple? begin apply_simple_default(default) rescue Error raise Error, "Plugin #{plugin.name.inspect} failed" end end end end |
#apply_to_ui ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/diecut/context-handler.rb', line 19 def apply_to_ui plugins.each do |plugin| plugin..each do |option| apply_option_to_ui(option) end end end |
#backfill_options_to_context ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/diecut/context-handler.rb', line 27 def plugins.each do |plugin| plugin..each do |option| backfill_to_context(option) end end end |
#backfill_to_context(option) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/diecut/context-handler.rb', line 35 def backfill_to_context(option) return unless option.has_context_path? segment = context_class.walk_path(option.context_path).last if option.has_default? segment.klass.setting(segment.name, option.default_value) else segment.klass.setting(segment.name) end end |