Class: Molt::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/molt/helpers/configuration.rb

Class Method Summary collapse

Class Method Details

.apply_cli_overrides(config, options, module_name, template_set) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/molt/helpers/configuration.rb', line 28

def self.apply_cli_overrides config, options, module_name, template_set
  config["template_set"] = template_set
  config["target"] = "raw"

  config["developer"]["name"] = options.name if options.name
  config["developer"]["email"] = options.email if options.email
  config["developer"]["company"] = options.company if options.company
  config["project"]["name"] = options.project if options.project

  config["module_name"] = module_name
  config["model"] = "#{options.model}Model" || "<# Model #>"
  config["entity"] = options.model || "<# Entity #>"

  config["year"] = Time.now.strftime("%Y")
  config["date"] = Time.now.strftime("%d/%m/%Y")
  config
end

.config_for_xcode(config, options, module_name, template_set) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/molt/helpers/configuration.rb', line 46

def self.config_for_xcode config, options, module_name, template_set
  config["template_set"] = template_set
  config["target"] = "xcode"

  config["module_name"] = "___VARIABLE_productName:identifier___"
  config["model"] = "___VARIABLE_MODEL___Model"
  config["entity"] = "___VARIABLE_MODEL___"
  config
end

.defaults_from_git_configObject



19
20
21
22
23
24
25
26
# File 'lib/molt/helpers/configuration.rb', line 19

def self.defaults_from_git_config
  user = { }
  name = `git config --get user.name`.chomp
  email = `git config --get user.email`.chomp
  user["name"] = name.length > 0 ? name : "REPLACE_ME_IN_CONFIG"
  user["email"] = email.length > 0 ? email : "REPLACE_ME_IN_CONFIG"
  return { "developer" => user }
end

.load_or_initializeObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/molt/helpers/configuration.rb', line 5

def self.load_or_initialize
  config_path = nil
  [ Molt::CONFIG_PROJECT, Molt::CONFIG_GLOBAL ].each do |path|
    if File.exist? path
      config_path = path
      break
    end
  end

  return YAML.load_file(config_path) if config_path
  puts 'Please run "molt setup" first'.red
  exit
end