Class: Diecut::Mediator
- Inherits:
-
Object
- Object
- Diecut::Mediator
- Defined in:
- lib/diecut/mediator.rb
Instance Attribute Summary collapse
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
- #activate(plug_name) ⇒ Object
- #activated?(plug_name) ⇒ Boolean
- #activated_plugins ⇒ Object
- #add_plugin(plug) ⇒ Object
- #apply_user_input(ui, context_class) ⇒ Object
-
#build_example_ui ⇒ Object
Set up context default settings set up ui settings from context.
- #build_ui_class(context_class) ⇒ Object
- #deactivate(plug_name) ⇒ Object
-
#initialize ⇒ Mediator
constructor
A new instance of Mediator.
Constructor Details
#initialize ⇒ Mediator
Returns a new instance of Mediator.
8 9 10 11 |
# File 'lib/diecut/mediator.rb', line 8 def initialize @plugins = [] @activated = {} end |
Instance Attribute Details
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
12 13 14 |
# File 'lib/diecut/mediator.rb', line 12 def plugins @plugins end |
Instance Method Details
#activate(plug_name) ⇒ Object
23 24 25 |
# File 'lib/diecut/mediator.rb', line 23 def activate(plug_name) @activated[plug_name] = true end |
#activated?(plug_name) ⇒ Boolean
19 20 21 |
# File 'lib/diecut/mediator.rb', line 19 def activated?(plug_name) @activated[plug_name] end |
#activated_plugins ⇒ Object
31 32 33 34 35 |
# File 'lib/diecut/mediator.rb', line 31 def activated_plugins @plugins.find_all do |plugin| @activated[plugin.name] end end |
#add_plugin(plug) ⇒ Object
14 15 16 17 |
# File 'lib/diecut/mediator.rb', line 14 def add_plugin(plug) @activated[plug.name] = plug.default_activated @plugins << plug end |
#apply_user_input(ui, context_class) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/diecut/mediator.rb', line 70 def apply_user_input(ui, context_class) applier = UIApplier.new applier.plugins = activated_plugins applier.ui = ui applier.context = context_class.new applier.apply end |
#build_example_ui ⇒ Object
Set up context default settings set up ui settings from context
< User gets involved >
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/diecut/mediator.rb', line 42 def build_example_ui ui_class = UIConfig.build_subclass("Example UI") handler = ContextHandler.new handler.context_class = Configurable.build_subclass("dummy context") handler.ui_class = ui_class handler.plugins = @plugins handler. handler.apply_to_ui handler.ui_class end |
#build_ui_class(context_class) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/diecut/mediator.rb', line 56 def build_ui_class(context_class) ui_class = UIConfig.build_subclass("User Interface") handler = ContextHandler.new handler.context_class = context_class handler.ui_class = ui_class handler.plugins = activated_plugins handler.apply_simple_defaults handler.apply_to_ui handler.ui_class end |
#deactivate(plug_name) ⇒ Object
27 28 29 |
# File 'lib/diecut/mediator.rb', line 27 def deactivate(plug_name) @activated[plug_name] = false end |