Class: Cheflow::Cookbook

Inherits:
Object
  • Object
show all
Defined in:
lib/cheflow/cookbook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Cookbook

Returns a new instance of Cookbook.



7
8
9
10
# File 'lib/cheflow/cookbook.rb', line 7

def initialize(options)
  @options = options
  @berksfile = Berkshelf::Berksfile.from_options(options.dup)
end

Instance Attribute Details

#berksfileObject (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_versionsObject



53
54
55
# File 'lib/cheflow/cookbook.rb', line 53

def dev_versions
  versions.select { |v| Semverse::Version.new(v).patch.odd? }
end

#frozen?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/cheflow/cookbook.rb', line 65

def frozen?
  ridley.cookbook.find(name, version).frozen?
end

#metadataObject



12
13
14
15
16
17
# File 'lib/cheflow/cookbook.rb', line 12

def 
   ||= begin
     = File.expand_path(File.join(path, 'metadata.rb'))
    Ridley::Chef::Cookbook::.from_file()
  end
end

#nameObject



23
24
25
# File 'lib/cheflow/cookbook.rb', line 23

def name
  @name ||= .name
end

#node_environment_objectsObject



37
38
39
# File 'lib/cheflow/cookbook.rb', line 37

def node_environment_objects
  @node_environments ||= ridley.search(:environment, "name:node_mongodb*")
end

#node_environmentsObject



41
42
43
44
45
46
47
# File 'lib/cheflow/cookbook.rb', line 41

def node_environments
  @node_environment_names ||= node_environment_objects.map do |e|
    env = e.name.gsub /^#{name}_/, ''
    env = env == name ? 'production' : env
    "#{env.ljust(12)} (#{e.cookbook_versions[name]})"
  end
end

#pathObject



27
28
29
# File 'lib/cheflow/cookbook.rb', line 27

def path
  @path ||= File.dirname(berksfile.filepath)
end

#prod_versionsObject



57
58
59
# File 'lib/cheflow/cookbook.rb', line 57

def prod_versions
  versions.select { |v| Semverse::Version.new(v).patch.even? }
end

#to_sObject



61
62
63
# File 'lib/cheflow/cookbook.rb', line 61

def to_s
  "#{name} v#{version}#{' (dev)' if version.patch.odd?}#{' (FROZEN)' if frozen?}"
end

#typeObject



31
32
33
34
35
# File 'lib/cheflow/cookbook.rb', line 31

def type
  if name.start_with? 'node_'
    'Node'
  end
end

#versionObject



19
20
21
# File 'lib/cheflow/cookbook.rb', line 19

def version
  @version ||= Semverse::Version.new(.version)
end

#versionsObject



49
50
51
# File 'lib/cheflow/cookbook.rb', line 49

def versions
  @versions ||= ridley.cookbook.versions(name)
end