Class: Germinate::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/germinate/application.rb

Overview

The Application ties all the other componts together. It has public methods roughly corresponding commands that the ‘germ’ command-line tool supports.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, errors) ⇒ Application

Returns a new instance of Application.



8
9
10
11
12
13
# File 'lib/germinate/application.rb', line 8

def initialize(output, errors)
  @output       = output
  @error_output = errors
  @log          = Germinate.logger
  @plugins      = []
end

Instance Attribute Details

#formatter=(value) ⇒ Object (writeonly)

Sets the attribute formatter

Parameters:

  • value

    the value to set the attribute formatter to.



6
7
8
# File 'lib/germinate/application.rb', line 6

def formatter=(value)
  @formatter = value
end

Instance Method Details

#format(source, path) ⇒ Object



28
29
30
31
32
# File 'lib/germinate/application.rb', line 28

def format(source, path)
  librarian = load_librarian(source, path)
  publisher = Germinate::SimplePublisher.new("simple", librarian)
  publisher.publish!(@output)
end

#list(source, path, collection) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/germinate/application.rb', line 34

def list(source, path, collection)
  librarian = load_librarian(source, path)
  case collection
  when "sections"
    @output.puts(librarian.section_names.join("\n"))
  when "samples"
    @output.puts(librarian.sample_names.join("\n"))
  when "processes"
    @output.puts(librarian.process_names.join("\n"))
  when "publishers"
    @output.puts(*librarian.publisher_names)
  when "all_publishers"
    Germinate::Publisher.registered_publishers.keys do |p|
      @output.puts(p)
    end
  when "variables"
    librarian.variables.each_pair do |name, value|
      @output.puts("%-20s %s" % [name, value.to_s])
    end
  when "plugins"
    @plugins.each do |plugin|
      puts(plugin)
    end
  else
    raise "I don't know how to list '#{collection}'"
  end
end

#load_plugins!Object

Search Rubygems for Germinate plugins and load them



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/germinate/application.rb', line 16

def load_plugins!
  $LOAD_PATH.each do |dir|
    plugin_init = Pathname(dir) + 'germinate_plugin_v0_init.rb'
    if plugin_init.readable?
      load_plugin!(plugin_init.to_s)
    end
  end
  Gem.find_files('germinate_plugin_v0_init').each do |file|
    load_plugin!(file)
  end
end

#publish(source, path, publisher, options = {}) ⇒ Object



83
84
85
86
87
# File 'lib/germinate/application.rb', line 83

def publish(source, path, publisher, options={})
  librarian = load_librarian(source, path)
  librarian.publisher(publisher).publish!(@output, options)
  librarian.store_changes!
end

#select(source, path, selector, options, origin = "command line") ⇒ Object



78
79
80
81
# File 'lib/germinate/application.rb', line 78

def select(source, path, selector, options, origin="command line")
  librarian = load_librarian(source, path)
  @output.puts(*librarian[selector, origin, options])
end

#set(source, path, name, value) ⇒ Object



89
90
91
92
93
# File 'lib/germinate/application.rb', line 89

def set(source, path, name, value)
  librarian = load_librarian(source, path)
  librarian.variables[name] = value
  librarian.store_changes!
end

#show(source, path, item_type, item) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/germinate/application.rb', line 62

def show(source, path, item_type, item)
  librarian = load_librarian(source, path)
  case item_type
  when "section"
    @output.puts(librarian.section(item))
  when "sample"
    @output.puts(librarian.sample(item))
  when "process"
    @output.puts(librarian.process(item).command)
  when "publisher"
    @output.puts(librarian.publisher(item))
  else
    raise "I don't know how to show '#{item_type}'"
  end
end