Class: Berkshelf::CookbookSource
- Inherits:
-
Object
- Object
- Berkshelf::CookbookSource
- Extended by:
- Forwardable
- Defined in:
- lib/berkshelf/cookbook_source.rb
Overview
Constant Summary collapse
- @@valid_options =
[:constraint, :locations, :group, :locked_version]
- @@location_keys =
Hash.new
Instance Attribute Summary collapse
-
#cached_cookbook ⇒ Object
Returns the value of attribute cached_cookbook.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version_constraint ⇒ Object
readonly
Returns the value of attribute version_constraint.
Class Method Summary collapse
-
.add_location_key(location, klass) ⇒ Array<Symbol>
Register a location key with the CookbookSource class.
-
.add_valid_option(option) ⇒ Array<Symbol>
Add a option to the list of valid options.
-
.location_keys ⇒ Array<Symbol>
Returns an array of the registered source location keys.
-
.valid_options ⇒ Array<Symbol>
Returns an array of valid options to pass to the initializer.
- .validate_options(options) ⇒ Object
Instance Method Summary collapse
- #add_group(*groups) ⇒ Object
-
#downloaded? ⇒ Boolean
Returns true if the cookbook source has already been downloaded.
- #has_group?(group) ⇒ Boolean
-
#initialize(name, options = {}) ⇒ CookbookSource
constructor
@param [String] name @param [Hash] options.
- #to_hash ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ CookbookSource
@param [String] name
@param [Hash] options
@option options [String, Solve::Constraint] constraint
version constraint to resolve for this source
@option options [String] :git
the Git URL to clone
@option options [String] :site
a URL pointing to a community API endpoint
@option options [String] :path
a filepath to the cookbook on your local disk
@option options [Symbol, Array] :group
the group or groups that the cookbook belongs to
@option options [String] :ref
the commit hash or an alias to a commit hash to clone
@option options [String] :branch
same as ref
@option options [String] :tag
same as tag
@option options [String] :locked_version
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/berkshelf/cookbook_source.rb', line 94 def initialize(name, = {}) @name = name @version_constraint = Solve::Constraint.new([:constraint] || ">= 0.0.0") @groups = [] @cached_cookbook = nil @location = nil self.class.() unless (.keys & self.class.location_keys.keys).empty? @location = Location.init(name, version_constraint, ) end if @location.is_a?(PathLocation) @cached_cookbook = CachedCookbook.from_path(location.path) end @locked_version = Solve::Version.new([:locked_version]) if [:locked_version] add_group([:group]) if [:group] add_group(:default) if groups.empty? end |
Instance Attribute Details
#cached_cookbook ⇒ Object
Returns the value of attribute cached_cookbook.
70 71 72 |
# File 'lib/berkshelf/cookbook_source.rb', line 70 def cached_cookbook @cached_cookbook end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
68 69 70 |
# File 'lib/berkshelf/cookbook_source.rb', line 68 def groups @groups end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
69 70 71 |
# File 'lib/berkshelf/cookbook_source.rb', line 69 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
66 67 68 |
# File 'lib/berkshelf/cookbook_source.rb', line 66 def name @name end |
#version_constraint ⇒ Object (readonly)
Returns the value of attribute version_constraint.
67 68 69 |
# File 'lib/berkshelf/cookbook_source.rb', line 67 def version_constraint @version_constraint end |
Class Method Details
.add_location_key(location, klass) ⇒ Array<Symbol>
Register a location key with the CookbookSource class
43 44 45 46 47 48 49 50 |
# File 'lib/berkshelf/cookbook_source.rb', line 43 def add_location_key(location, klass) unless @@location_keys.has_key?(location) add_valid_option(location) @@location_keys[location] = klass end @@location_keys end |
.add_valid_option(option) ⇒ Array<Symbol>
Add a option to the list of valid options
30 31 32 33 |
# File 'lib/berkshelf/cookbook_source.rb', line 30 def add_valid_option(option) @@valid_options.push(option) unless @@valid_options.include?(option) @@valid_options end |
.location_keys ⇒ Array<Symbol>
Returns an array of the registered source location keys. Every source location is identified by a key (symbol) to differentiate which class to instantiate for the location of a CookbookSource at initialization.
20 21 22 |
# File 'lib/berkshelf/cookbook_source.rb', line 20 def location_keys @@location_keys end |
.valid_options ⇒ Array<Symbol>
Returns an array of valid options to pass to the initializer
11 12 13 |
# File 'lib/berkshelf/cookbook_source.rb', line 11 def @@valid_options end |
.validate_options(options) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/berkshelf/cookbook_source.rb', line 52 def () = (.keys - ) unless .empty? .collect! { |opt| "'#{opt}'" } raise InternalError, "Invalid options for Cookbook Source: #{.join(', ')}." end true end |
Instance Method Details
#add_group(*groups) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/berkshelf/cookbook_source.rb', line 117 def add_group(*groups) groups = groups.first if groups.first.is_a?(Array) groups.each do |group| group = group.to_sym @groups << group unless @groups.include?(group) end end |
#downloaded? ⇒ Boolean
Returns true if the cookbook source has already been downloaded. A cookbook source is downloaded when a cached cookbooked is present.
129 130 131 |
# File 'lib/berkshelf/cookbook_source.rb', line 129 def downloaded? !self.cached_cookbook.nil? end |
#has_group?(group) ⇒ Boolean
133 134 135 |
# File 'lib/berkshelf/cookbook_source.rb', line 133 def has_group?(group) groups.include?(group.to_sym) end |
#to_hash ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/berkshelf/cookbook_source.rb', line 143 def to_hash {}.tap do |h| h[:name] = self.name h[:locked_version] = self.locked_version h[:location] = self.location.to_hash if self.location end end |
#to_json ⇒ Object
151 152 153 |
# File 'lib/berkshelf/cookbook_source.rb', line 151 def to_json MultiJson.dump(self.to_hash, pretty: true) end |
#to_s ⇒ Object
137 138 139 140 141 |
# File 'lib/berkshelf/cookbook_source.rb', line 137 def to_s msg = "#{self.name} (#{self.version_constraint}) groups: #{self.groups}" msg << " location: #{self.location}" if self.location msg end |