Module: Kanagata::Util

Included in:
Base
Defined in:
lib/kanagata/util.rb

Instance Method Summary collapse

Instance Method Details

#info(text) ⇒ Object



31
32
33
# File 'lib/kanagata/util.rb', line 31

def info(text)
  puts "\t#{text}"
end

#load_and_validate(target, config_file) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/kanagata/util.rb', line 3

def load_and_validate(target, config_file)
  yaml = YAML.load_file(File.expand_path(config_file))
  validate(yaml, target)
  config = yaml[target]
  validate(config, 'templates')
  config['templates'].each do |file|
    validate(file, 'path')
  end
  config
end

#merge_attributes(config_attributes, args_attributes) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/kanagata/util.rb', line 14

def merge_attributes(config_attributes, args_attributes)
  args_attributes.each do |value|
    k, v = value.split(':')
    config_attributes[k] = v
  end
  config_attributes
end

#relative_path_of(file) ⇒ Object



26
27
28
29
# File 'lib/kanagata/util.rb', line 26

def relative_path_of(file)
  pwd = File.expand_path('.')
  Pathname.new(file).relative_path_from(Pathname.new(pwd))
end

#validate(hash, key) ⇒ Object



22
23
24
# File 'lib/kanagata/util.rb', line 22

def validate(hash, key)
  raise "Error: config file format is invalid -- '#{key}' is not found." unless hash.key?(key)
end