berkshelf 2.0.18 → 3.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. data/.ruby-version +1 -1
  2. data/.travis.yml +4 -1
  3. data/CHANGELOG.md +2 -26
  4. data/Gemfile +12 -2
  5. data/README.md +9 -1
  6. data/berkshelf.gemspec +9 -18
  7. data/bin/berks +3 -13
  8. data/features/apply_command.feature +11 -9
  9. data/features/berksfile.feature +8 -10
  10. data/features/config.feature +1 -2
  11. data/features/configure_command.feature +13 -14
  12. data/features/contingent_command.feature +13 -1
  13. data/features/cookbook_command.feature +2 -4
  14. data/features/groups_install.feature +10 -2
  15. data/features/help.feature +1 -1
  16. data/features/init_command.feature +5 -7
  17. data/features/install_command.feature +157 -228
  18. data/features/json_formatter.feature +27 -15
  19. data/features/licenses.feature +18 -12
  20. data/features/list_command.feature +6 -1
  21. data/features/lockfile.feature +116 -72
  22. data/features/outdated_command.feature +3 -47
  23. data/features/package_command.feature +10 -7
  24. data/features/shelf/show.feature +2 -2
  25. data/features/shelf/uninstall.feature +2 -2
  26. data/features/show_command.feature +10 -3
  27. data/features/step_definitions/chef/config_steps.rb +12 -0
  28. data/features/step_definitions/chef_server_steps.rb +16 -16
  29. data/features/step_definitions/cli_steps.rb +3 -79
  30. data/features/step_definitions/config_steps.rb +43 -0
  31. data/features/step_definitions/environment_steps.rb +7 -0
  32. data/features/step_definitions/filesystem_steps.rb +12 -57
  33. data/features/step_definitions/gem_steps.rb +1 -2
  34. data/features/step_definitions/json_steps.rb +3 -1
  35. data/features/step_definitions/lockfile_steps.rb +4 -0
  36. data/features/step_definitions/utility_steps.rb +0 -19
  37. data/features/support/aruba.rb +12 -0
  38. data/features/support/env.rb +52 -57
  39. data/features/update_command.feature +37 -23
  40. data/features/upload_command.feature +96 -160
  41. data/generator_files/Berksfile.erb +2 -1
  42. data/generator_files/Vagrantfile.erb +3 -0
  43. data/generator_files/default_test.rb.erb +1 -1
  44. data/generator_files/helpers.rb.erb +1 -1
  45. data/lib/berkshelf.rb +43 -24
  46. data/lib/berkshelf/api_client.rb +67 -0
  47. data/lib/berkshelf/api_client/remote_cookbook.rb +42 -0
  48. data/lib/berkshelf/berksfile.rb +232 -420
  49. data/lib/berkshelf/cached_cookbook.rb +22 -10
  50. data/lib/berkshelf/chef/config.rb +1 -0
  51. data/lib/berkshelf/cli.rb +66 -68
  52. data/lib/berkshelf/commands/shelf.rb +1 -1
  53. data/lib/berkshelf/community_rest.rb +10 -17
  54. data/lib/berkshelf/config.rb +23 -27
  55. data/lib/berkshelf/cookbook_generator.rb +3 -4
  56. data/lib/berkshelf/cookbook_store.rb +74 -17
  57. data/lib/berkshelf/core_ext/file.rb +2 -2
  58. data/lib/berkshelf/core_ext/pathname.rb +7 -5
  59. data/lib/berkshelf/{cookbook_source.rb → dependency.rb} +47 -67
  60. data/lib/berkshelf/downloader.rb +49 -106
  61. data/lib/berkshelf/errors.rb +64 -71
  62. data/lib/berkshelf/formatters.rb +11 -9
  63. data/lib/berkshelf/formatters/human_readable.rb +9 -9
  64. data/lib/berkshelf/formatters/json.rb +14 -4
  65. data/lib/berkshelf/init_generator.rb +3 -3
  66. data/lib/berkshelf/installer.rb +136 -0
  67. data/lib/berkshelf/location.rb +91 -131
  68. data/lib/berkshelf/locations/git_location.rb +9 -11
  69. data/lib/berkshelf/locations/github_location.rb +1 -1
  70. data/lib/berkshelf/locations/path_location.rb +10 -27
  71. data/lib/berkshelf/lockfile.rb +92 -70
  72. data/lib/berkshelf/logger.rb +4 -7
  73. data/lib/berkshelf/mixin/config.rb +21 -4
  74. data/lib/berkshelf/resolver.rb +60 -150
  75. data/lib/berkshelf/resolver/graph.rb +44 -0
  76. data/lib/berkshelf/source.rb +55 -0
  77. data/lib/berkshelf/source_uri.rb +38 -0
  78. data/lib/berkshelf/version.rb +1 -1
  79. data/spec/config/knife.rb +1 -1
  80. data/spec/fixtures/cassettes/Berkshelf_Resolver/_initialize/adds_the_dependencies_of_the_dependency_as_dependencies.yml +3694 -0
  81. data/spec/fixtures/cookbooks/example_cookbook/Berksfile.lock +1 -1
  82. data/spec/fixtures/lockfiles/default.lock +1 -1
  83. data/spec/spec_helper.rb +20 -121
  84. data/spec/support/chef_api.rb +3 -4
  85. data/spec/support/chef_server.rb +20 -11
  86. data/spec/support/git.rb +127 -0
  87. data/spec/support/kitchen.rb +12 -0
  88. data/spec/support/path_helpers.rb +69 -0
  89. data/spec/unit/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
  90. data/spec/unit/berkshelf/api_client_spec.rb +57 -0
  91. data/spec/unit/berkshelf/berksfile_spec.rb +206 -324
  92. data/spec/unit/berkshelf/cached_cookbook_spec.rb +73 -38
  93. data/spec/unit/berkshelf/community_rest_spec.rb +30 -71
  94. data/spec/unit/berkshelf/config_spec.rb +3 -14
  95. data/spec/unit/berkshelf/cookbook_generator_spec.rb +1 -2
  96. data/spec/unit/berkshelf/cookbook_store_spec.rb +12 -7
  97. data/spec/unit/berkshelf/dependency_spec.rb +285 -0
  98. data/spec/unit/berkshelf/downloader_spec.rb +4 -183
  99. data/spec/unit/berkshelf/formatters/null_spec.rb +1 -1
  100. data/spec/unit/berkshelf/formatters_spec.rb +4 -2
  101. data/spec/unit/berkshelf/git_spec.rb +15 -15
  102. data/spec/unit/berkshelf/installer_spec.rb +39 -0
  103. data/spec/unit/berkshelf/location_spec.rb +87 -114
  104. data/spec/unit/berkshelf/locations/git_location_spec.rb +41 -53
  105. data/spec/unit/berkshelf/locations/path_location_spec.rb +13 -23
  106. data/spec/unit/berkshelf/lockfile_spec.rb +38 -40
  107. data/spec/unit/berkshelf/resolver/graph_spec.rb +44 -0
  108. data/spec/unit/berkshelf/resolver_spec.rb +34 -83
  109. data/spec/unit/berkshelf/source_spec.rb +23 -0
  110. data/spec/unit/berkshelf/source_uri_spec.rb +29 -0
  111. metadata +149 -188
  112. checksums.yaml +0 -7
  113. data/features/default_locations.feature +0 -127
  114. data/features/step_definitions/berksfile_steps.rb +0 -8
  115. data/features/step_definitions/configure_cli_steps.rb +0 -19
  116. data/features/vendor_install.feature +0 -19
  117. data/lib/berkshelf/core_ext/openuri.rb +0 -36
  118. data/lib/berkshelf/core_ext/rbzip2.rb +0 -8
  119. data/lib/berkshelf/locations/chef_api_location.rb +0 -228
  120. data/lib/berkshelf/locations/site_location.rb +0 -92
  121. data/lib/berkshelf/test.rb +0 -35
  122. data/spec/knife.rb.sample +0 -12
  123. data/spec/support/test_generators.rb +0 -27
  124. data/spec/unit/berkshelf/cli_spec.rb +0 -16
  125. data/spec/unit/berkshelf/cookbook_source_spec.rb +0 -358
  126. data/spec/unit/berkshelf/core_ext/pathname_spec.rb +0 -46
  127. data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +0 -139
  128. data/spec/unit/berkshelf/locations/site_location_spec.rb +0 -19
@@ -6,15 +6,14 @@ module Berkshelf
6
6
  register_formatter :json
7
7
 
8
8
  def initialize
9
- Berkshelf.ui.mute!
10
-
11
9
  @output = {
12
10
  cookbooks: Array.new,
13
11
  errors: Array.new,
14
12
  messages: Array.new
15
13
  }
16
14
  @cookbooks = Hash.new
17
- super
15
+
16
+ Berkshelf.ui.mute { super }
18
17
  end
19
18
 
20
19
  def cleanup_hook
@@ -26,6 +25,13 @@ module Berkshelf
26
25
  print ::JSON.pretty_generate(output)
27
26
  end
28
27
 
28
+ # @param [Berkshelf::Dependency] dependency
29
+ def fetch(dependency)
30
+ cookbooks[dependency] ||= {}
31
+ cookbooks[dependency][:version] = dependency.cached_cookbook.version
32
+ cookbooks[dependency][:location] = dependency.location
33
+ end
34
+
29
35
  # Add a Cookbook installation entry to delayed output
30
36
  #
31
37
  # @param [String] cookbook
@@ -34,7 +40,11 @@ module Berkshelf
34
40
  def install(cookbook, version, location)
35
41
  cookbooks[cookbook] ||= {}
36
42
  cookbooks[cookbook][:version] = version
37
- cookbooks[cookbook][:location] = location.to_s
43
+
44
+ if location && location.is_a?(PathLocation)
45
+ cookbooks[cookbook][:metadata] = true if location.metadata?
46
+ cookbooks[cookbook][:location] = location.relative_path
47
+ end
38
48
  end
39
49
 
40
50
  # Add a Cookbook use entry to delayed output
@@ -113,7 +113,7 @@ module Berkshelf
113
113
  private
114
114
 
115
115
  def berkshelf_config
116
- Berkshelf::Config.instance
116
+ Berkshelf.config
117
117
  end
118
118
 
119
119
  # Read the cookbook name from the metadata.rb
@@ -135,8 +135,8 @@ module Berkshelf
135
135
  #
136
136
  # @return [nil]
137
137
  def validate_configuration
138
- unless Config.instance.valid?
139
- raise InvalidConfiguration.new Config.instance.errors
138
+ unless Berkshelf.config.valid?
139
+ raise InvalidConfiguration.new Berkshelf.config.errors
140
140
  end
141
141
  end
142
142
 
@@ -0,0 +1,136 @@
1
+ module Berkshelf
2
+ class Installer
3
+ extend Forwardable
4
+
5
+ attr_reader :berksfile
6
+ attr_reader :downloader
7
+
8
+ def_delegator :berksfile, :lockfile
9
+
10
+ # @param [Berkshelf::Berksfile] berksfile
11
+ def initialize(berksfile)
12
+ @berksfile = berksfile
13
+ @downloader = Downloader.new(berksfile)
14
+ end
15
+
16
+ def build_universe
17
+ berksfile.sources.map(&:universe)
18
+ end
19
+
20
+ # @option options [Array<String>, String] cookbooks
21
+ #
22
+ # @return [Array<Berkshelf::CachedCookbook>]
23
+ def run(options = {})
24
+ dependencies = lockfile_reduce(berksfile.dependencies(options.slice(:except, :only)))
25
+ resolver = Resolver.new(berksfile, dependencies)
26
+
27
+ dependencies.each do |dependency|
28
+ next unless dependency.scm_location?
29
+ Berkshelf.formatter.fetch(dependency)
30
+ downloader.download(dependency)
31
+ end
32
+
33
+ dependencies.each do |dependency|
34
+ next unless dependency.cached_cookbook
35
+ resolver.add_explicit_dependencies(dependency)
36
+ end
37
+
38
+ Berkshelf.formatter.msg("building universe...")
39
+ build_universe
40
+
41
+ lock_deps = []
42
+
43
+ cached_cookbooks = resolver.resolve.collect do |name, version, dependency|
44
+ lock_deps << dependency
45
+ if dependency.downloaded?
46
+ Berkshelf.formatter.use(dependency.name, dependency.cached_cookbook.version, dependency.location)
47
+ dependency.cached_cookbook
48
+ else
49
+ Berkshelf.formatter.install(name, version, dependency)
50
+ temp_filepath = downloader.download(name, version)
51
+ CookbookStore.import(name, version, temp_filepath)
52
+ end
53
+ end
54
+
55
+ verify_licenses!(lock_deps)
56
+ lockfile.update(lock_deps)
57
+ cached_cookbooks
58
+ end
59
+
60
+ # Verify that the licenses of all the cached cookbooks fall in the realm of
61
+ # allowed licenses from the Berkshelf Config.
62
+ #
63
+ # @param [Array<Berkshelf::Dependencies>] dependencies
64
+ #
65
+ # @raise [Berkshelf::LicenseNotAllowed]
66
+ # if the license is not permitted and `raise_license_exception` is true
67
+ def verify_licenses!(dependencies)
68
+ licenses = Array(Berkshelf.config.allowed_licenses)
69
+ return if licenses.empty?
70
+
71
+ dependencies.each do |dependency|
72
+ next if dependency.location.is_a?(Berkshelf::PathLocation)
73
+ cached = dependency.cached_cookbook
74
+
75
+ begin
76
+ unless licenses.include?(cached.metadata.license)
77
+ raise Berkshelf::LicenseNotAllowed.new(cached)
78
+ end
79
+ rescue Berkshelf::LicenseNotAllowed => e
80
+ if Berkshelf.config.raise_license_exception
81
+ FileUtils.rm_rf(cached.path)
82
+ raise
83
+ end
84
+
85
+ Berkshelf.ui.warn(e.to_s)
86
+ end
87
+ end
88
+ end
89
+
90
+ private
91
+
92
+ def dependency_from_lockfile(dependency)
93
+ locked_dependency = lockfile.find(dependency)
94
+
95
+ return nil unless locked_dependency
96
+
97
+ # If there's a locked_version, make sure it's still satisfied
98
+ # by the constraint
99
+ if locked_dependency.locked_version
100
+ unless dependency.version_constraint.satisfies?(locked_dependency.locked_version)
101
+ raise Berkshelf::OutdatedDependency.new(locked_dependency, dependency)
102
+ end
103
+ end
104
+
105
+ # Update to the new constraint (it might have changed, but still be satisfied)
106
+ locked_dependency.version_constraint = dependency.version_constraint
107
+ locked_dependency
108
+ end
109
+
110
+ # Merge the locked dependencies against the given dependencies.
111
+ #
112
+ # For each the given dependencies, check if there's a locked version that
113
+ # still satisfies the version constraint. If it does, "lock" that dependency
114
+ # because we should just use the locked version.
115
+ #
116
+ # If a locked dependency exists, but doesn't satisfy the constraint, raise a
117
+ # {Berkshelf::OutdatedDependency} and tell the user to run update.
118
+ def lockfile_reduce(dependencies = [])
119
+ dependencies.collect do |dependency|
120
+ dependency_from_lockfile(dependency) || dependency
121
+ end
122
+ end
123
+
124
+ # The list of dependencies "locked" by the lockfile.
125
+ #
126
+ # @return [Array<Berkshelf::Dependency>]
127
+ # the list of dependencies in this lockfile
128
+ def locked_dependencies
129
+ lockfile.dependencies
130
+ end
131
+
132
+ def reduce_scm_locations(dependencies)
133
+ dependencies.select { |dependency| SCM_LOCATIONS.include?(dependency.class.location_key) }
134
+ end
135
+ end
136
+ end
@@ -1,75 +1,12 @@
1
1
  module Berkshelf
2
2
  module Location
3
- OPSCODE_COMMUNITY_API = 'http://cookbooks.opscode.com/api/v1/cookbooks'.freeze
4
-
5
- module ClassMethods
6
- require_relative 'cookbook_source'
7
-
8
- # Returns the location identifier key for the class
9
- #
10
- # @return [Symbol]
11
- attr_reader :location_key
12
-
13
- # Register the location key for the including source location with CookbookSource
14
- #
15
- # @param [Symbol] key
16
- def set_location_key(key)
17
- CookbookSource.add_location_key(key, self)
18
- @location_key = key
19
- end
20
-
21
- # Register a valid option or multiple options with the CookbookSource class
22
- #
23
- # @param [Symbol] opts
24
- def set_valid_options(*opts)
25
- Array(opts).each do |opt|
26
- CookbookSource.add_valid_option(opt)
27
- end
28
- end
29
-
30
- # Returns an array where the first element is string representing the best version
31
- # for the given constraint and the second element is the URI to where the corresponding
32
- # version of the Cookbook can be downloaded from
33
- #
34
- # @example:
35
- # constraint = Solve::Constraint.new('~> 0.101.2')
36
- # versions = {
37
- # '1.0.0' => 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/1_0_0',
38
- # '2.0.0' => 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/2_0_0'
39
- # }
40
- #
41
- # subject.solve_for_constraint(versions, constraint) =>
42
- # [ '2.0.0', 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/2_0_0' ]
43
- #
44
- # @param [String, Solve::Constraint] constraint
45
- # version constraint to solve for
46
- #
47
- # @param [Hash] versions
48
- # a hash where the keys are a string representing a cookbook version and the values
49
- # are the download URL for the cookbook version.
50
- #
51
- # @return [Array, nil]
52
- def solve_for_constraint(constraint, versions)
53
- version = Solve::Solver.satisfy_best(constraint, versions.keys).to_s
54
-
55
- [ version, versions[version] ]
56
- rescue Solve::Errors::NoSolutionError
57
- nil
58
- end
59
- end
60
-
61
3
  class << self
62
- def included(base)
63
- base.send :extend, ClassMethods
64
- end
65
-
66
4
  # Creates a new instance of a Class implementing Location with the given name and
67
5
  # constraint. Which Class to instantiated is determined by the values in the given
68
6
  # options Hash. Source Locations have an associated location_key registered with
69
- # CookbookSource. If your options Hash contains a key matching one of these location_keys
7
+ # Berkshelf::Dependency. If your options Hash contains a key matching one of these location_keys
70
8
  # then the Class who registered that location_key will be instantiated. If you do not
71
- # provide an option with a matching location_key a SiteLocation class will be
72
- # instantiated.
9
+ # provide an option with a matching location_key nil will be returned.
73
10
  #
74
11
  # @example
75
12
  # Location.init('nginx', '>= 0.0.0', git: 'git://github.com/RiotGames/artifact-cookbook.git') =>
@@ -78,97 +15,120 @@ module Berkshelf
78
15
  # Location.init('nginx', '>= 0.0.0', path: '/Users/reset/code/nginx-cookbook') =>
79
16
  # instantiates a PathLocation
80
17
  #
81
- # Location.init('nginx', '>= 0.0.0', site: 'http://cookbooks.opscode.com/api/v1/cookbooks') =>
82
- # instantiates a SiteLocation
83
- #
84
- # Location.init('nginx', '>= 0.0.0', chef_api: 'https://api.opscode.com/organizations/vialstudios') =>
85
- # instantiates a ChefAPILocation
86
- #
87
- # Location.init('nginx', '>= 0.0.0') =>
88
- # instantiates a SiteLocation
89
- #
90
- # @param [String] name
91
- # @param [String, Solve::Constraint] constraint
18
+ # @param [Dependency] dependency
92
19
  # @param [Hash] options
93
20
  #
94
- # @return [SiteLocation, PathLocation, GitLocation, ChefAPILocation]
95
- def init(name, constraint, options = {})
96
- klass = klass_from_options(options)
97
-
98
- klass.new(name, constraint, options)
21
+ # @return [~Location::Base, nil]
22
+ def init(dependency, options = {})
23
+ if klass = klass_from_options(options)
24
+ klass.new(dependency, options)
25
+ end
99
26
  end
100
27
 
101
28
  private
102
29
 
103
30
  def klass_from_options(options)
104
- location_keys = (options.keys & CookbookSource.location_keys.keys)
31
+ location_keys = (options.keys & Berkshelf::Dependency.location_keys.keys)
105
32
  if location_keys.length > 1
106
33
  location_keys.collect! { |opt| "'#{opt}'" }
107
- raise InternalError, "Only one location key (#{CookbookSource.location_keys.keys.join(', ')}) may be specified. You gave #{location_keys.join(', ')}."
34
+ raise InternalError, "Only one location key (#{Berkshelf::Dependency.location_keys.keys.join(', ')}) " +
35
+ "may be specified. You gave #{location_keys.join(', ')}."
108
36
  end
109
37
 
110
- if location_keys.empty?
111
- SiteLocation
112
- else
113
- CookbookSource.location_keys[location_keys.first]
38
+ if location_key = location_keys.first
39
+ Berkshelf::Dependency.location_keys[location_key]
114
40
  end
115
41
  end
116
42
  end
117
43
 
118
- attr_reader :name
119
- attr_reader :version_constraint
44
+ class Base
45
+ class << self
46
+ # Returns the location identifier key for the class
47
+ #
48
+ # @return [Symbol]
49
+ attr_reader :location_key
50
+
51
+ # Register the location key for the including source location with Berkshelf::Dependency
52
+ #
53
+ # @param [Symbol] key
54
+ def set_location_key(key)
55
+ Berkshelf::Dependency.add_location_key(key, self)
56
+ @location_key = key
57
+ end
120
58
 
121
- # @param [#to_s] name
122
- # @param [Solve::Constraint] version_constraint
123
- # @param [Hash] options
124
- def initialize(name, version_constraint, options = {})
125
- @name = name
126
- @version_constraint = version_constraint
127
- @downloaded_status = false
128
- end
59
+ # Register a valid option or multiple options with the Berkshelf::Dependency class
60
+ #
61
+ # @param [Symbol] opts
62
+ def set_valid_options(*opts)
63
+ Array(opts).each do |opt|
64
+ Berkshelf::Dependency.add_valid_option(opt)
65
+ end
66
+ end
67
+ end
129
68
 
130
- # @param [#to_s] destination
131
- #
132
- # @return [Berkshelf::CachedCookbook]
133
- def download(destination)
134
- raise AbstractFunction
135
- end
69
+ extend Forwardable
70
+
71
+ attr_reader :dependency
72
+ def_delegator :dependency, :name
136
73
 
137
- # Ensure the retrieved CachedCookbook is valid
138
- #
139
- # @param [CachedCookbook] cached_cookbook
140
- # the downloaded cookbook to validate
141
- #
142
- # @raise [CookbookValidationFailure] if given CachedCookbook does not satisfy the constraint of the location
143
- #
144
- # @todo Change MismatchedCookbookName to raise instead of warn
145
- #
146
- # @return [Boolean]
147
- def validate_cached(cached_cookbook)
148
- unless version_constraint.satisfies?(cached_cookbook.version)
149
- raise CookbookValidationFailure.new(self, cached_cookbook)
74
+ # @param [Berkshelf::Dependency] dependency
75
+ # @param [Hash] options
76
+ def initialize(dependency, options = {})
77
+ @dependency = dependency
78
+ @@cached_cookbook = nil
150
79
  end
151
80
 
152
- unless self.name == cached_cookbook.cookbook_name
153
- Berkshelf.ui.warn(MismatchedCookbookName.new(self, cached_cookbook).to_s)
81
+ # @param [#to_s] destination
82
+ #
83
+ # @return [Berkshelf::CachedCookbook]
84
+ def download
85
+ return @cached_cookbook if @cached_cookbook
86
+
87
+ cached_cookbook = do_download
88
+ validate_cached(cached_cookbook)
89
+ @cached_cookbook = cached_cookbook
154
90
  end
155
91
 
156
- true
157
- end
92
+ # @param [#to_s] destination
93
+ #
94
+ # @return [Berkshelf::CachedCookbook]
95
+ def do_download
96
+ raise AbstractFunction
97
+ end
158
98
 
159
- def to_hash
160
- {
161
- type: self.class.location_key
162
- }
163
- end
99
+ # Ensure the retrieved CachedCookbook is valid
100
+ #
101
+ # @param [CachedCookbook] cached_cookbook
102
+ # the downloaded cookbook to validate
103
+ #
104
+ # @raise [CookbookValidationFailure] if given CachedCookbook does not satisfy the constraint of the location
105
+ #
106
+ # @todo Change MismatchedCookbookName to raise instead of warn
107
+ #
108
+ # @return [Boolean]
109
+ def validate_cached(cached_cookbook)
110
+ unless dependency.version_constraint.satisfies?(cached_cookbook.version)
111
+ raise CookbookValidationFailure.new(dependency, cached_cookbook)
112
+ end
113
+
114
+ unless dependency.name == cached_cookbook.cookbook_name
115
+ Berkshelf.ui.warn(MismatchedCookbookName.new(dependency, cached_cookbook).to_s)
116
+ end
164
117
 
165
- def to_json(options = {})
166
- JSON.pretty_generate(to_hash, options)
118
+ true
119
+ end
120
+
121
+ def to_hash
122
+ { type: self.class.location_key }
123
+ end
124
+
125
+ def to_json(options = {})
126
+ JSON.pretty_generate(to_hash, options)
127
+ end
167
128
  end
168
129
  end
169
130
  end
170
131
 
171
- require_relative 'locations/chef_api_location'
172
- require_relative 'locations/git_location'
173
- require_relative 'locations/github_location'
174
- require_relative 'locations/site_location'
132
+ Dir["#{File.dirname(__FILE__)}/locations/*.rb"].sort.each do |path|
133
+ require_relative "locations/#{File.basename(path, '.rb')}"
134
+ end