berkshelf 2.0.18 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,36 +1,32 @@
1
- require 'chozo/config'
1
+ require 'buff/config/json'
2
2
 
3
3
  module Berkshelf
4
- class Config < Chozo::Config::JSON
5
- LOCATIONS = [
6
- File.join('.', '.berkshelf', 'config.json').freeze,
7
- File.join('.', 'berkshelf', 'config.json').freeze,
8
- File.join('.', 'berkshelf-config.json').freeze,
9
- File.join('.', 'config.json').freeze
10
- ].freeze
11
-
4
+ class Config < Buff::Config::JSON
12
5
  class << self
13
6
  # @return [String]
14
- def default_location
7
+ def store_location
15
8
  File.join(Berkshelf.berkshelf_path, 'config.json')
16
9
  end
17
10
 
11
+ # @return [String]
12
+ def local_location
13
+ ENV['BERKSHELF_CONFIG'] || File.join('.', '.berkshelf', 'config.json')
14
+ end
15
+
18
16
  # @return [String]
19
17
  def path
20
- @path ||= begin
21
- location = LOCATIONS.find do |file|
22
- path = File.expand_path(file)
23
- File.exists?(path)
24
- end
18
+ path = File.exists?(local_location) ? local_location : store_location
19
+ File.expand_path(path)
20
+ end
25
21
 
26
- File.expand_path(location || default_location)
27
- end
22
+ # @param [Berkshelf::Config] config
23
+ def set_config(config)
24
+ @instance = config
28
25
  end
29
26
 
30
27
  # @param [String] new_path
31
28
  def set_path(new_path)
32
29
  @instance = nil
33
- @path = File.expand_path(new_path)
34
30
  end
35
31
 
36
32
  # @return [String, nil]
@@ -62,35 +58,35 @@ module Berkshelf
62
58
 
63
59
  # @param [String] path
64
60
  # @param [Hash] options
65
- # @see {Chozo::Config::JSON}
61
+ # @see {Buff::Config::JSON}
66
62
  def initialize(path = self.class.path, options = {})
67
63
  super(path, options)
68
64
  end
69
65
 
70
66
  attribute 'chef.chef_server_url',
71
67
  type: String,
72
- default: Berkshelf.chef_config[:chef_server_url]
68
+ default: Berkshelf.chef_config.chef_server_url
73
69
  attribute 'chef.validation_client_name',
74
70
  type: String,
75
- default: Berkshelf.chef_config[:validation_client_name]
71
+ default: Berkshelf.chef_config.validation_client_name
76
72
  attribute 'chef.validation_key_path',
77
73
  type: String,
78
- default: Berkshelf.chef_config[:validation_key]
74
+ default: Berkshelf.chef_config.validation_key
79
75
  attribute 'chef.client_key',
80
76
  type: String,
81
- default: Berkshelf.chef_config[:client_key]
77
+ default: Berkshelf.chef_config.client_key
82
78
  attribute 'chef.node_name',
83
79
  type: String,
84
- default: Berkshelf.chef_config[:node_name]
80
+ default: Berkshelf.chef_config.node_name
85
81
  attribute 'cookbook.copyright',
86
82
  type: String,
87
- default: Berkshelf.chef_config[:cookbook_copyright]
83
+ default: Berkshelf.chef_config.cookbook_copyright
88
84
  attribute 'cookbook.email',
89
85
  type: String,
90
- default: Berkshelf.chef_config[:cookbook_email]
86
+ default: Berkshelf.chef_config.cookbook_email
91
87
  attribute 'cookbook.license',
92
88
  type: String,
93
- default: Berkshelf.chef_config[:cookbook_license]
89
+ default: Berkshelf.chef_config.cookbook_license
94
90
  attribute 'allowed_licenses',
95
91
  type: Array,
96
92
  default: Array.new
@@ -45,21 +45,20 @@ module Berkshelf
45
45
 
46
46
  class_option :license,
47
47
  type: :string,
48
- default: Berkshelf::Config.instance.cookbook.license
48
+ default: Berkshelf.config.cookbook.license
49
49
 
50
50
  class_option :maintainer,
51
51
  type: :string,
52
- default: Berkshelf::Config.instance.cookbook.copyright
52
+ default: Berkshelf.config.cookbook.copyright
53
53
 
54
54
  class_option :maintainer_email,
55
55
  type: :string,
56
- default: Berkshelf::Config.instance.cookbook.email
56
+ default: Berkshelf.config.cookbook.email
57
57
 
58
58
  def generate
59
59
  empty_directory target.join('files/default')
60
60
  empty_directory target.join('templates/default')
61
61
  empty_directory target.join('attributes')
62
- empty_directory target.join('definitions')
63
62
  empty_directory target.join('libraries')
64
63
  empty_directory target.join('providers')
65
64
  empty_directory target.join('recipes')
@@ -2,6 +2,35 @@ require 'fileutils'
2
2
 
3
3
  module Berkshelf
4
4
  class CookbookStore
5
+ class << self
6
+ # The default path to the cookbook store relative to the Berkshelf path.
7
+ #
8
+ # @return [String]
9
+ def default_path
10
+ File.join(Berkshelf.berkshelf_path, 'cookbooks')
11
+ end
12
+
13
+ # @return [Berkshelf::CookbookStore]
14
+ def instance
15
+ @instance ||= new(default_path)
16
+ end
17
+
18
+ # Import a cookbook found on the local filesystem into the current instance of
19
+ # the cookbook store.
20
+ #
21
+ # @param [String] name
22
+ # name of the cookbook
23
+ # @param [String] version
24
+ # verison of the cookbook
25
+ # @param [String] path
26
+ # location on disk of the cookbook
27
+ #
28
+ # @return [Berkshelf::CachedCookbook]
29
+ def import(name, version, path)
30
+ instance.import(name, version, path)
31
+ end
32
+ end
33
+
5
34
  # @return [String]
6
35
  # filepath to where cookbooks are stored
7
36
  attr_reader :storage_path
@@ -17,6 +46,30 @@ module Berkshelf
17
46
  initialize_filesystem
18
47
  end
19
48
 
49
+ # Destroy the contents of the initialized storage path.
50
+ def clean!
51
+ FileUtils.rm_rf(Dir.glob(File.join(storage_path, '*')))
52
+ end
53
+
54
+ # Import a cookbook found on the local filesystem into this instance of the cookbook store.
55
+ #
56
+ # @param [String] name
57
+ # name of the cookbook
58
+ # @param [String] version
59
+ # verison of the cookbook
60
+ # @param [String] path
61
+ # location on disk of the cookbook
62
+ #
63
+ # @return [Berkshelf::CachedCookbook]
64
+ def import(name, version, path)
65
+ destination = cookbook_path(name, version)
66
+ FileUtils.mv(path, destination)
67
+ cookbook(name, version)
68
+ rescue => ex
69
+ FileUtils.rm_f(destination)
70
+ raise
71
+ end
72
+
20
73
  # Returns an instance of CachedCookbook representing the
21
74
  # Cookbook of your given name and version.
22
75
  #
@@ -41,15 +94,20 @@ module Berkshelf
41
94
  #
42
95
  # @return [Array<Berkshelf::CachedCookbook>]
43
96
  def cookbooks(filter = nil)
44
- cookbooks = storage_path.children.collect do |path|
45
- CachedCookbook.from_store_path(path)
46
- end.compact
97
+ cookbooks = []
47
98
 
48
- return cookbooks unless filter
99
+ storage_path.each_child.map do |path|
100
+ Celluloid::Future.new do
101
+ cached_cookbook = CachedCookbook.from_store_path(path)
49
102
 
50
- cookbooks.select do |cookbook|
51
- cookbook.cookbook_name == filter
52
- end
103
+ next unless cached_cookbook
104
+ next if filter && cached_cookbook.cookbook_name != filter
105
+
106
+ cookbooks << cached_cookbook
107
+ end
108
+ end.each(&:value)
109
+
110
+ cookbooks
53
111
  end
54
112
 
55
113
  # Returns an expanded path to the location on disk where the Cookbook
@@ -63,6 +121,15 @@ module Berkshelf
63
121
  storage_path.join("#{name}-#{version}")
64
122
  end
65
123
 
124
+ def initialize_filesystem
125
+ FileUtils.mkdir_p(storage_path, mode: 0755)
126
+
127
+ unless File.writable?(storage_path)
128
+ raise InsufficientPrivledges, "You do not have permission to write to '#{storage_path}'!" +
129
+ " Please either chown the directory or use a different Cookbook Store."
130
+ end
131
+ end
132
+
66
133
  # Return a CachedCookbook matching the best solution for the given name and
67
134
  # constraint. Nil is returned if no matching CachedCookbook is found.
68
135
  #
@@ -80,15 +147,5 @@ module Berkshelf
80
147
  rescue Solve::Errors::NoSolutionError
81
148
  nil
82
149
  end
83
-
84
- private
85
-
86
- def initialize_filesystem
87
- FileUtils.mkdir_p(storage_path, mode: 0755)
88
-
89
- unless File.writable?(storage_path)
90
- raise InsufficientPrivledges, "You do not have permission to write to '#{storage_path}'! Please either chown the directory or use a different Cookbook Store."
91
- end
92
- end
93
150
  end
94
151
  end
@@ -1,13 +1,13 @@
1
1
  class File
2
2
  class << self
3
- # Returns true or false if the given path contains a Chef Cookbook
3
+ # Returns true or false if the given path is a Chef Cookbook
4
4
  #
5
5
  # @param [#to_s] path
6
6
  # path of directory to reflect on
7
7
  #
8
8
  # @return [Boolean]
9
9
  def cookbook?(path)
10
- File.exists?(File.join(path, "metadata.json")) || File.exists?(File.join(path, "metadata.rb"))
10
+ File.exists?(File.join(path, 'metadata.rb'))
11
11
  end
12
12
  alias_method :chef_cookbook?, :cookbook?
13
13
  end
@@ -1,18 +1,20 @@
1
1
  class Pathname
2
- # Returns true or false if the path contains a "metadata.json" or a "metadata.rb" file.
2
+ # Returns true or false if the path of the instantiated
3
+ # Pathname or a parent directory contains a Tryhard Pack
4
+ # data directory.
3
5
  #
4
6
  # @return [Boolean]
5
7
  def cookbook?
6
- join("metadata.json").exist? || join("metadata.rb").exist?
8
+ self.join('metadata.rb').exist?
7
9
  end
8
10
  alias_method :chef_cookbook?, :cookbook?
9
11
 
10
- # Ascend the directory structure from the given path to find the root of a
11
- # Cookbook. If no Cookbook is found, nil is returned.
12
+ # Ascend the directory structure from the given path to find a
13
+ # the root of a Chef Cookbook. If no Cookbook is found, nil is returned
12
14
  #
13
15
  # @return [Pathname, nil]
14
16
  def cookbook_root
15
- ascend do |potential_root|
17
+ self.ascend do |potential_root|
16
18
  if potential_root.cookbook?
17
19
  return potential_root
18
20
  end
@@ -1,5 +1,5 @@
1
1
  module Berkshelf
2
- class CookbookSource
2
+ class Dependency
3
3
  class << self
4
4
  @@valid_options = [:constraint, :locations, :group, :locked_version]
5
5
  @@location_keys = Hash.new
@@ -13,7 +13,7 @@ module Berkshelf
13
13
 
14
14
  # Returns an array of the registered source location keys. Every source
15
15
  # location is identified by a key (symbol) to differentiate which class
16
- # to instantiate for the location of a CookbookSource at initialization.
16
+ # to instantiate for the location of a Dependency at initialization.
17
17
  #
18
18
  # @return [Array<Symbol>]
19
19
  def location_keys
@@ -31,7 +31,7 @@ module Berkshelf
31
31
  @@valid_options
32
32
  end
33
33
 
34
- # Register a location key with the CookbookSource class
34
+ # Register a location key with the Dependency class
35
35
  # @see #location_keys
36
36
  #
37
37
  # @param [Symbol] location
@@ -53,19 +53,20 @@ module Berkshelf
53
53
 
54
54
  unless invalid_options.empty?
55
55
  invalid_options.collect! { |opt| "'#{opt}'" }
56
- raise InternalError, "Invalid options for Cookbook Source: #{invalid_options.join(', ')}."
56
+ raise InternalError, "Invalid options for dependency: #{invalid_options.join(', ')}."
57
57
  end
58
58
 
59
- if (options.keys & [:site, :path, :git]).size > 1
60
- invalid = (options.keys & [:site, :path, :git]).map { |opt| "'#{opt}" }
61
- raise InternalError, "Cannot specify #{invalid.to_sentence} for a Cookbook Source!"
59
+ if (options.keys & location_keys.keys).size > 1
60
+ invalid = (options.keys & location_keys.keys).map { |opt| "'#{opt}'" }
61
+ raise InternalError, "Cannot specify #{invalid.join(' and ')} for a dependency!"
62
62
  end
63
63
 
64
64
  true
65
65
  end
66
66
  end
67
67
 
68
- DEFAULT_CONSTRAINT = '>= 0.0.0'
68
+ DEFAULT_CONSTRAINT = '>= 0.0.0'.freeze
69
+ SCM_LOCATIONS = [ :git, :github ].freeze
69
70
 
70
71
  # @return [Berkshelf::Berksfile]
71
72
  attr_reader :berksfile
@@ -81,16 +82,14 @@ module Berkshelf
81
82
  attr_accessor :cached_cookbook
82
83
 
83
84
  # @param [Berkshelf::Berksfile] berksfile
84
- # the berksfile this source belongs to
85
+ # the berksfile this dependency belongs to
85
86
  # @param [String] name
86
- # the name of source
87
+ # the name of dependency
87
88
  #
88
89
  # @option options [String, Solve::Constraint] :constraint
89
- # version constraint to resolve for this source
90
+ # version constraint for this dependency
90
91
  # @option options [String] :git
91
92
  # the Git URL to clone
92
- # @option options [String] :site
93
- # a URL pointing to a community API endpoint
94
93
  # @option options [String] :path
95
94
  # a filepath to the cookbook on your local disk
96
95
  # @option options [String] :metadata
@@ -105,17 +104,15 @@ module Berkshelf
105
104
  # same as tag
106
105
  # @option options [String] :locked_version
107
106
  def initialize(berksfile, name, options = {})
108
- @options = options
109
-
110
107
  self.class.validate_options(options)
111
108
 
109
+ @options = options
112
110
  @berksfile = berksfile
113
111
  @name = name
112
+ @location = Location.init(self, options)
114
113
  @locked_version = Solve::Version.new(options[:locked_version]) if options[:locked_version]
115
114
  @version_constraint = Solve::Constraint.new(options[:constraint] || DEFAULT_CONSTRAINT)
116
115
 
117
- @cached_cookbook, @location = cached_and_location(options)
118
-
119
116
  add_group(options[:group]) if options[:group]
120
117
  add_group(:default) if groups.empty?
121
118
  end
@@ -129,22 +126,29 @@ module Berkshelf
129
126
  end
130
127
  end
131
128
 
132
- # Determine the CachedCookbook and Location information from the given options.
133
- #
134
- # @return [Array<CachedCookbook, Location>]
135
- def cached_and_location(options = {})
136
- from_path(options) || from_default(options)
129
+ # @return [Berkshelf::CachedCookbook]
130
+ def cached_cookbook
131
+ @cached_cookbook ||= if location
132
+ location.download
133
+ else
134
+ Berkshelf::CookbookStore.instance.satisfy(name, version_constraint)
135
+ end
136
+ end
137
+
138
+ # @return [Berkshelf::CachedCookbook]
139
+ def download
140
+ @cached_cookbook = location.download
137
141
  end
138
142
 
139
- # Returns true if the cookbook source has already been downloaded. A cookbook
140
- # source is downloaded when a cached cookbook is present.
143
+ # Returns true if the dependency has already been downloaded. A dependency is downloaded when a
144
+ # cached cookbook is present.
141
145
  #
142
146
  # @return [Boolean]
143
147
  def downloaded?
144
- !self.cached_cookbook.nil?
148
+ !cached_cookbook.nil?
145
149
  end
146
150
 
147
- # Returns true if this CookbookSource has the given group.
151
+ # Returns true if this dependency has the given group.
148
152
  #
149
153
  # @return [Boolean]
150
154
  def has_group?(group)
@@ -160,10 +164,10 @@ module Berkshelf
160
164
  # @return [Solve::Version, nil]
161
165
  # the locked version of this cookbook
162
166
  def locked_version
163
- @locked_version ||= cached_cookbook.try(:version)
167
+ @locked_version ||= cached_cookbook ? cached_cookbook.version : nil
164
168
  end
165
169
 
166
- # The location for this CookbookSource, such as a remote Chef Server, the
170
+ # The location for this dependency, such as a remote Chef Server, the
167
171
  # community API, :git, or a :path location. By default, this will be the
168
172
  # community API.
169
173
  #
@@ -172,21 +176,30 @@ module Berkshelf
172
176
  @location
173
177
  end
174
178
 
175
- # The list of groups this CookbookSource belongs to.
179
+ # The list of groups this dependency belongs to.
176
180
  #
177
181
  # @return [Array<Symbol>]
178
182
  def groups
179
183
  @groups ||= []
180
184
  end
181
185
 
186
+ # @return [Boolean]
187
+ def scm_location?
188
+ if location.nil?
189
+ return false
190
+ end
191
+
192
+ SCM_LOCATIONS.include?(location.class.location_key)
193
+ end
194
+
182
195
  def to_s
183
- "#<Berkshelf::CookbookSource: #{name} (#{version_constraint})>"
196
+ "#{name} (#{version_constraint})"
184
197
  end
185
198
 
186
199
  def inspect
187
- '#<Berkshelf::CookbookSource: ' << [
200
+ '#<Berkshelf::Dependency: ' << [
188
201
  "#{name} (#{version_constraint})",
189
- "locked_version: #{locked_version ? locked_version.to_s : 'nil'}",
202
+ "locked_version: #{locked_version.inspect}",
190
203
  "groups: #{groups}",
191
204
  "location: #{location || 'default'}>"
192
205
  ].join(', ')
@@ -198,8 +211,8 @@ module Berkshelf
198
211
  h[:locked_version] = locked_version.to_s
199
212
  end
200
213
 
201
- if location.kind_of?(SiteLocation)
202
- h[:site] = location.api_uri if location.api_uri != CommunityREST::V1_API
214
+ unless version_constraint.to_s == DEFAULT_CONSTRAINT
215
+ h[:constraint] = version_constraint.to_s
203
216
  end
204
217
 
205
218
  if location.kind_of?(PathLocation)
@@ -217,38 +230,5 @@ module Berkshelf
217
230
  def to_json(options = {})
218
231
  JSON.pretty_generate(to_hash, options)
219
232
  end
220
-
221
- private
222
- # Attempt to load a CachedCookbook from a local file system path (if the :path
223
- # option was given). If one is found, the location and cached_cookbook is
224
- # updated. Otherwise, this method will raise a CookbookNotFound exception.
225
- #
226
- # @raise [Berkshelf::CookbookNotFound]
227
- # if no CachedCookbook exists at the given path
228
- #
229
- # @return [Berkshelf::CachedCookbook]
230
- def from_path(options = {})
231
- return nil unless options[:path]
232
-
233
- location = PathLocation.new(name, version_constraint, options)
234
-
235
- [ location.cookbook, location ]
236
- rescue IOError => ex
237
- raise Berkshelf::CookbookNotFound, ex
238
- end
239
-
240
- # Use the default location, and a nil CachedCookbook. If there is no location
241
- # specified,
242
- #
243
- # @return [Array<nil, Location>]
244
- def from_default(options = {})
245
- if (options.keys & self.class.location_keys.keys).empty?
246
- location = nil
247
- else
248
- location = Location.init(name, version_constraint, options)
249
- end
250
-
251
- [ nil, location ]
252
- end
253
233
  end
254
234
  end