Method: Huck.run

Defined in:
lib/huck.rb

.run(kwargs = {}) ⇒ Object

Main method to run Huck and dump info. If a block is given, the block will be used as the generator code. If no block is passed, then the configured generator will be invoked instead.

Parameters:

config_file

Configuration file path

config

Configuration hash to use in place of a config file



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
61
62
63
64
65
66
# File 'lib/huck.rb', line 36

def self.run kwargs = {}
  config = Huck::getarg kwargs, :config, nil
  if config.nil?
    conf_file = Huck::getarg kwargs, :config_file, nil
    config = Huck::config :path => conf_file
  end

  # Prep the sender
  if config.has_key? 'sender'
    send_name = config['sender']
  end
  send_arg = Huck::getarg kwargs, :sender, nil
  send_name = send_arg if !send_arg.nil?
  s = Sender::factory :name => send_name, :config => config

  # Create an array of generators to execute
  gen_list = config.has_key?('generators') ? config['generators'] : ['basic']
  generators = Array.new
  Huck::parse_providers gen_list do |gen_name, gen_config|
    generators << Generator::factory(:name => gen_name, :config => gen_config)
  end

  # Execute the generators and send their output
  generators.each do |g|
    data = block_given? ? yield : g.generate
    if !data.kind_of? String
      raise Error, "generator produced non-string result: #{data.class}"
    end
    s.send data
  end
end