Class: Fhcap::Tasks::Chef::Cookbook::UpdateArtifact

Inherits:
Fhcap::Tasks::Chef::ChefTaskBase show all
Defined in:
lib/fhcap/tasks/chef/cookbook/update_artifact.rb

Instance Attribute Summary collapse

Attributes inherited from TaskBase

#config, #options, #thor, #verbose

Instance Method Summary collapse

Methods inherited from Fhcap::Tasks::Chef::ChefTaskBase

#knife_config_dir, #knife_config_file_for, #run_chef_client_cmd, #run_knife_cmd, #run_knife_ssh_cmd

Methods inherited from TaskBase

#ask_config, #color_pad, #exit_with_error, #set_color, #suppress_stdout, #table_header, #table_row, #with_progress

Methods included from KnifeHelper

#chef_server_config_for, #chef_server_config_hash_for, #chef_server_names, #knife_config, #knife_config_dir, #knife_config_file_for

Methods included from ProvidersHelper

#provider_availability_zones, #provider_config, #provider_credentials, #provider_for, #provider_names, #provider_names_for, #provider_regions, #provider_type, #providers_config

Methods included from ReposHelper

#find_cluster, #find_cluster_pwds, #find_cluster_pwds_with_repo, #find_cluster_with_repo, #find_data_bag, #find_data_bag_item, #find_environment, #find_repo_item, #find_role, #get_cookbook_deps, #get_cookbook_meta, #get_cookbook_versions, #get_cookbooks, #get_entry_dependencies, #get_modified_cookbooks, #is_dirty?, #modified?, #repo_cfg, #repo_clusters_dir, #repo_cookbook_paths, #repo_dir, #repo_names, #repo_paths, #repos_config, #repos_dir, #run_inside_repo_dir

Methods included from FhcapHelper

#cluster_template_names

Constructor Details

#initialize(options) ⇒ UpdateArtifact

Returns a new instance of UpdateArtifact.



11
12
13
14
15
16
# File 'lib/fhcap/tasks/chef/cookbook/update_artifact.rb', line 11

def initialize(options)
  super
  @name = options[:cookbook]
  @version = options[:version]
  @build = options[:build]
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



9
10
11
# File 'lib/fhcap/tasks/chef/cookbook/update_artifact.rb', line 9

def build
  @build
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/fhcap/tasks/chef/cookbook/update_artifact.rb', line 9

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/fhcap/tasks/chef/cookbook/update_artifact.rb', line 9

def version
  @version
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fhcap/tasks/chef/cookbook/update_artifact.rb', line 18

def run
  thor.say "Chef::Cookbook::UpdateArtifact cookbook = #{name}, version = #{version}, build = #{build}", :yellow
  cookbook = cookbook_loader.cookbooks_by_name[name]

  artifact_attribute_filepath = cookbook.attribute_filenames.find { |e| /artifact.rb/ =~ e }

  if artifact_attribute_filepath
    text = File.read(artifact_attribute_filepath)
    replace = text.gsub(/default\['#{name}'\]\['version'\] = .+$/, "default['#{name}']['version'] = '#{version}'")
    replace = replace.gsub(/default\['#{name}'\]\['build'\] = .+$/, "default['#{name}']['build'] = '#{build}'")
    thor.create_file(artifact_attribute_filepath, replace, {force: !options[:interactive]})
  else
    thor.say_status("error", "No artifact file found for #{name}", :red)
  end

end