Module: Formatron::Generators::Instance::Config

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

Overview

generates an empty config

Class Method Summary collapse

Class Method Details

.write(directory, target = nil, name = nil) ⇒ Object

rubocop:disable Metrics/MethodLength



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/formatron/generators/instance/config.rb', line 24

def self.write(
  directory,
  target = nil,
  name = nil
)
  target_directory = File.join(
    directory,
    'config',
    target.nil? ? '_default' : target.to_s
  )
  FileUtils.mkdir_p target_directory
  file = File.join target_directory, '_default.json'
  write_default(file) if target.nil?
  write_target(
    file,
    target,
    name
  ) unless target.nil?
end

.write_default(file) ⇒ Object



6
7
8
9
10
11
# File 'lib/formatron/generators/instance/config.rb', line 6

def self.write_default(file)
  File.write file, <<-EOH.gsub(/^ {12}/, '')
    {
    }
  EOH
end

.write_target(file, target, name) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/formatron/generators/instance/config.rb', line 13

def self.write_target(file, target, name)
  File.write file, <<-EOH.gsub(/^ {12}/, '')
    {
      "#{name}": {
        "sub_domain": "#{name}-#{target}"
      }
    }
  EOH
end