Class: Cheflow::Cookbook
- Inherits:
-
Object
- Object
- Cheflow::Cookbook
- Defined in:
- lib/cheflow/cookbook.rb
Instance Attribute Summary collapse
-
#berksfile ⇒ Object
readonly
Returns the value of attribute berksfile.
Instance Method Summary collapse
- #dev_versions ⇒ Object
- #frozen? ⇒ Boolean
-
#initialize(options) ⇒ Cookbook
constructor
A new instance of Cookbook.
- #metadata ⇒ Object
- #name ⇒ Object
- #node_cookbook? ⇒ Boolean
- #node_environment_objects ⇒ Object
- #node_environments(with_versions = false) ⇒ Object
-
#node_name ⇒ Object
The name of the Node cookbook without the “node_” prefix.
- #path ⇒ Object
- #prod_versions ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
- #upload ⇒ Object
- #version ⇒ Object
- #versions ⇒ Object
Constructor Details
#initialize(options) ⇒ Cookbook
Returns a new instance of Cookbook.
7 8 9 10 |
# File 'lib/cheflow/cookbook.rb', line 7 def initialize() = @berksfile = Berkshelf::Berksfile.(.dup) end |
Instance Attribute Details
#berksfile ⇒ Object (readonly)
Returns the value of attribute berksfile.
4 5 6 |
# File 'lib/cheflow/cookbook.rb', line 4 def berksfile @berksfile end |
Instance Method Details
#dev_versions ⇒ Object
72 73 74 |
# File 'lib/cheflow/cookbook.rb', line 72 def dev_versions versions.select { |v| Semverse::Version.new(v).patch.odd? } end |
#frozen? ⇒ Boolean
84 85 86 |
# File 'lib/cheflow/cookbook.rb', line 84 def frozen? ridley.cookbook.find(name, version).frozen? end |
#metadata ⇒ Object
12 13 14 15 16 17 |
# File 'lib/cheflow/cookbook.rb', line 12 def ||= begin = File.(File.join(path, 'metadata.rb')) Ridley::Chef::Cookbook::Metadata.from_file() end end |
#name ⇒ Object
23 24 25 |
# File 'lib/cheflow/cookbook.rb', line 23 def name @name ||= .name end |
#node_cookbook? ⇒ Boolean
44 45 46 |
# File 'lib/cheflow/cookbook.rb', line 44 def node_cookbook? type == :node end |
#node_environment_objects ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/cheflow/cookbook.rb', line 48 def node_environment_objects @node_environment_objects ||= begin if node_cookbook? ridley.search(:environment, "name:#{name}*") else ridley.search(:environment, "cookbook_versions:#{name}") end end end |
#node_environments(with_versions = false) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/cheflow/cookbook.rb', line 58 def node_environments(with_versions=false) @node_environments ||= node_environment_objects.map do |e| env = e.name.gsub /^#{name}_/, '' env = env == name ? 'production' : env out = with_versions ? env.ljust(12) : env out += " (#{e.cookbook_versions[name]})" if with_versions out end.compact.sort end |
#node_name ⇒ Object
The name of the Node cookbook without the “node_” prefix.
28 29 30 |
# File 'lib/cheflow/cookbook.rb', line 28 def node_name @node_name ||= node_cookbook? ? name.sub(/^node_/, '') : name end |
#path ⇒ Object
32 33 34 |
# File 'lib/cheflow/cookbook.rb', line 32 def path @path ||= File.dirname(berksfile.filepath) end |
#prod_versions ⇒ Object
76 77 78 |
# File 'lib/cheflow/cookbook.rb', line 76 def prod_versions versions.select { |v| Semverse::Version.new(v).patch.even? } end |
#to_s ⇒ Object
80 81 82 |
# File 'lib/cheflow/cookbook.rb', line 80 def to_s "#{name} v#{version}#{' (dev)' if version.patch.odd?}#{' (FROZEN)' if frozen?}" end |
#type ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/cheflow/cookbook.rb', line 36 def type @type ||= if name.start_with? 'node_' :node else :non_node end end |
#upload ⇒ Object
88 89 90 |
# File 'lib/cheflow/cookbook.rb', line 88 def upload ridley.cookbook.upload path, freeze: !version.patch.odd? end |
#version ⇒ Object
19 20 21 |
# File 'lib/cheflow/cookbook.rb', line 19 def version @version ||= Semverse::Version.new(.version) end |
#versions ⇒ Object
68 69 70 |
# File 'lib/cheflow/cookbook.rb', line 68 def versions @versions ||= ridley.cookbook.versions(name) end |