Class: Diecut::Mediator

Inherits:
Object
  • Object
show all
Defined in:
lib/diecut/mediator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMediator

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

#pluginsObject (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

Returns:

  • (Boolean)


19
20
21
# File 'lib/diecut/mediator.rb', line 19

def activated?(plug_name)
  @activated[plug_name]
end

#activated_pluginsObject



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_uiObject

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 = Class.new(UIConfig)

  handler = ContextHandler.new
  handler.context_class = Class.new(Configurable)
  handler.ui_class = ui_class
  handler.plugins = @plugins

  handler.backfill_options_to_context
  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 = Class.new(UIConfig)

  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