Module: KnifeSolo::CookbookManager::InstanceMethods

Defined in:
lib/knife-solo/cookbook_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



40
41
42
# File 'lib/knife-solo/cookbook_manager.rb', line 40

def config
  @config
end

#uiObject (readonly)

Returns the value of attribute ui.



40
41
42
# File 'lib/knife-solo/cookbook_manager.rb', line 40

def ui
  @ui
end

Instance Method Details

#bootstrap(base) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/knife-solo/cookbook_manager.rb', line 101

def bootstrap(base)
  ui.msg "Setting up #{name}..."
  unless conf_file_exists?(base)
    File.open(conf_file(base), 'w') { |f| f.puts(initial_config) }
  end
  if KnifeSolo::Tools.config_value(config, :git, true) && gitignores
    KnifeSolo::Gitignore.new(base).add(gitignores)
  end
end

#conf_file(base = nil) ⇒ Object



66
67
68
# File 'lib/knife-solo/cookbook_manager.rb', line 66

def conf_file(base = nil)
  base ? File.join(base, self.class.conf_file_name) : self.class.conf_file_name
end

#conf_file_exists?(base = nil) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/knife-solo/cookbook_manager.rb', line 74

def conf_file_exists?(base = nil)
  File.exist?(conf_file(base))
end

#enabled_by_chef_config?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/knife-solo/cookbook_manager.rb', line 70

def enabled_by_chef_config?
  KnifeSolo::Tools.config_value(config, self.class.config_key)
end

#gem_installed?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
# File 'lib/knife-solo/cookbook_manager.rb', line 59

def gem_installed?
  self.class.load_gem
  true
rescue LoadError
  false
end

#gem_nameObject



55
56
57
# File 'lib/knife-solo/cookbook_manager.rb', line 55

def gem_name
  self.class.gem_name
end

#gitignoresObject

Returns an array of strings to gitignore when bootstrapping



117
118
119
# File 'lib/knife-solo/cookbook_manager.rb', line 117

def gitignores
  nil
end

#initial_configObject

Returns content for configuration file when bootstrapping



112
113
114
# File 'lib/knife-solo/cookbook_manager.rb', line 112

def initial_config
  raise "Must be overridden by the including class"
end

#initialize(config, ui) ⇒ Object



42
43
44
45
# File 'lib/knife-solo/cookbook_manager.rb', line 42

def initialize(config, ui)
  @config = config
  @ui = ui
end

#installObject

Runs installer if the configuration file is found and gem installed Returns the cookbook path or nil



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/knife-solo/cookbook_manager.rb', line 85

def install
  if !conf_file_exists?
    Chef::Log.debug "#{conf_file} not found"
  else
    begin
      self.class.load_gem
      return install!
    rescue LoadError => e
      ui.warn e.inspect
      ui.warn "#{name} could not be loaded"
      ui.warn "Please add the #{gem_name} gem to your Gemfile or install it manually with `gem install #{gem_name}`"
    end
  end
  nil
end

#install!Object

Runs the manager and returns the path to the cookbook directory



79
80
81
# File 'lib/knife-solo/cookbook_manager.rb', line 79

def install!
  raise "Must be overridden by the including class"
end

#nameObject



51
52
53
# File 'lib/knife-solo/cookbook_manager.rb', line 51

def name
  self.class.name.split('::').last
end

#to_sObject



47
48
49
# File 'lib/knife-solo/cookbook_manager.rb', line 47

def to_s
  name
end