Class: Jack::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/jack/settings.rb

Instance Method Summary collapse

Constructor Details

#initialize(root = nil) ⇒ Settings

Returns a new instance of Settings.



3
4
5
# File 'lib/jack/settings.rb', line 3

def initialize(root=nil)
  @root = root || '.'
end

Instance Method Details

#app_name_patternObject



42
43
44
# File 'lib/jack/settings.rb', line 42

def app_name_pattern
  conventions["app_name_pattern"]
end

#conventionsObject



46
47
48
# File 'lib/jack/settings.rb', line 46

def conventions
  data["conventions"]
end

#createObject



38
39
40
# File 'lib/jack/settings.rb', line 38

def create
  data["create"]
end

#create_flagsObject



34
35
36
# File 'lib/jack/settings.rb', line 34

def create_flags
  create.inject("") {|s,(k,v)| s << %{--#{k} "#{v}" } ; s }.strip
end

#dataObject

The options from the files get merged with the following precedence:

current folder - The current folder’s jack/settings.yml values take the highest precedence. user - The user’s ~/.jack/settings.yml values take the second highest precedence. default - The default settings bundled with the tool takes the lowest precedence.

More info: jack-eb.com/docs/settings/



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jack/settings.rb', line 14

def data
  return @settings_yaml if @settings_yaml

  project_file = "#{@root}/jack/settings.yml"
  project = File.exist?(project_file) ? YAML.load_file(project_file) : {}

  user_file = "#{home}/.jack/settings.yml"
  user = File.exist?(user_file) ? YAML.load_file(user_file) : {}

  default_file = File.expand_path("../default/settings.yml", __FILE__)
  default = YAML.load_file(default_file)

  @settings_yaml = default.merge(user.merge(project))
end

#homeObject



29
30
31
32
# File 'lib/jack/settings.rb', line 29

def home
  # hack but fast
  ENV['TEST'] ? "spec/fixtures/home" : ENV['HOME']
end