Module: Formatron::Generators::Instance

Defined in:
lib/formatron/generators/instance.rb,
lib/formatron/generators/instance/config.rb,
lib/formatron/generators/instance/formatronfile.rb

Overview

generates an instance configuration

Defined Under Namespace

Modules: Config, Formatronfile

Class Method Summary collapse

Class Method Details

.generate(directory, params) ⇒ Object

rubocop:disable Metrics/MethodLength



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/formatron/generators/instance.rb', line 48

def self.generate(directory, params)
  validate_params params
  Util::Readme.write directory, params[:name]
  Util::Gitignore.write directory
  Formatronfile.write directory, params
  Config.write directory
  generate_targets(
    directory,
    params[:targets],
    params[:instance_name]
  )
  generate_cookbooks directory, params[:instance_name]
end

.generate_cookbooks(directory, name) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/formatron/generators/instance.rb', line 39

def self.generate_cookbooks(directory, name)
  Util::Cookbook.write(
    directory,
    "#{name}_instance",
    "#{name} instance"
  )
end

.generate_targets(directory, targets, name) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/formatron/generators/instance.rb', line 29

def self.generate_targets(directory, targets, name)
  targets.each do |target|
    Config.write(
      directory,
      target,
      name
    )
  end
end

.validate_hash_params(hash, params) ⇒ Object



11
12
13
14
15
# File 'lib/formatron/generators/instance.rb', line 11

def self.validate_hash_params(hash, params)
  params.each do |param|
    fail "params should contain #{param}" if hash[param].nil?
  end
end

.validate_params(params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/formatron/generators/instance.rb', line 17

def self.validate_params(params)
  validate_hash_params params, [
    :name,
    :instance_name,
    :s3_bucket,
    :bootstrap_configuration,
    :vpc,
    :subnet,
    :targets
  ]
end