Class: Diecut::Mill

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind) ⇒ Mill

Returns a new instance of Mill.



8
9
10
# File 'lib/diecut/mill.rb', line 8

def initialize(kind)
  @kind = kind
end

Instance Attribute Details

#issue_handler=(value) ⇒ Object (writeonly)

Sets the attribute issue_handler

Parameters:

  • value

    the value to set the attribute issue_handler to.



12
13
14
# File 'lib/diecut/mill.rb', line 12

def issue_handler=(value)
  @issue_handler = value
end

#kindObject (readonly)

Returns the value of attribute kind.



11
12
13
# File 'lib/diecut/mill.rb', line 11

def kind
  @kind
end

#mediatorObject



14
15
16
# File 'lib/diecut/mill.rb', line 14

def mediator
  @mediator ||= Diecut.mediator(kind)
end

#templatesObject



18
19
20
# File 'lib/diecut/mill.rb', line 18

def templates
  @templates ||= TemplateSet.new
end

#valiseObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/diecut/mill.rb', line 32

def valise
  @valise ||=
    begin
      stems = mediator.activated_plugins.map do |plugin|
        plugin.stem_for(kind)
      end
      Valise::Set.define do
        stems.each do |stem|
          ro stem.template_dir
        end
      end
    end
end

Instance Method Details

#activate_pluginsObject



22
23
24
25
26
27
28
29
30
# File 'lib/diecut/mill.rb', line 22

def activate_plugins
  mediator.plugins.map(&:name).each do |name|
    if yield(name)
      mediator.activate(name)
    else
      mediator.deactivate(name)
    end
  end
end

#churn(ui) ⇒ Object



67
68
69
70
71
72
# File 'lib/diecut/mill.rb', line 67

def churn(ui)
  templates.context = mediator.apply_user_input(ui, templates.context_class)
  templates.results do |path, contents|
    yield(path, contents)
  end
end

#context_classObject



52
53
54
# File 'lib/diecut/mill.rb', line 52

def context_class
  templates.context_class
end

#load_filesObject



46
47
48
49
50
# File 'lib/diecut/mill.rb', line 46

def load_files
  valise.filter('**', %i[extended dotmatch]).files do |file|
    templates.add(file.rel_path.to_s, file.contents)
  end
end

#ui_classObject



56
57
58
# File 'lib/diecut/mill.rb', line 56

def ui_class
  mediator.build_ui_class(context_class)
end

#user_interfaceObject



60
61
62
63
64
65
# File 'lib/diecut/mill.rb', line 60

def user_interface
  load_files
  templates.prepare

  ui_class.new
end