Class: CookbookBumper::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cookbook_bumper/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Config

Returns a new instance of Config.

Yields:

  • (_self)

Yield Parameters:



7
8
9
10
11
12
# File 'lib/cookbook_bumper/config.rb', line 7

def initialize
  @exclude_environments = %w[development]
  @knife_path = File.expand_path('.chef/knife.rb')
  @repo_root = File.expand_path('.')
  yield(self) if block_given?
end

Instance Attribute Details

#cookbook_pathObject



14
15
16
# File 'lib/cookbook_bumper/config.rb', line 14

def cookbook_path
  @cookbook_path || Array(fetch_chef_config(:cookbook_path)).map { |p| File.expand_path(p) }
end

#environment_pathObject



18
19
20
# File 'lib/cookbook_bumper/config.rb', line 18

def environment_path
  @environment_path || Array(fetch_chef_config(:environment_path)).map { |p| File.expand_path(p) }
end

#exclude_environmentsObject

Returns the value of attribute exclude_environments.



5
6
7
# File 'lib/cookbook_bumper/config.rb', line 5

def exclude_environments
  @exclude_environments
end

#knife_pathObject

Returns the value of attribute knife_path.



5
6
7
# File 'lib/cookbook_bumper/config.rb', line 5

def knife_path
  @knife_path
end

#repo_rootObject

Returns the value of attribute repo_root.



5
6
7
# File 'lib/cookbook_bumper/config.rb', line 5

def repo_root
  @repo_root
end

Instance Method Details

#config_already_read?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/cookbook_bumper/config.rb', line 27

def config_already_read?
  @knife_path == @knife_path_read
end

#fetch_chef_config(config_name) ⇒ Object



22
23
24
25
# File 'lib/cookbook_bumper/config.rb', line 22

def fetch_chef_config(config_name)
  read_chef_config unless config_already_read?
  Chef::Config.send(config_name)
end

#read_chef_configObject



31
32
33
34
# File 'lib/cookbook_bumper/config.rb', line 31

def read_chef_config
  Chef::Config.from_file(@knife_path)
  @knife_path_read = @knife_path
end