fpm-cookery 0.10.0 → 0.11.0

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.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v0.11.0 (2012-08-20)
2
+ * Add source handler to handle local source directories via file:// urls.
3
+
1
4
  # v0.10.0 (2012-08-12)
2
5
  * Add support for shar and bin files to curl source handler. (brandonmartin)
3
6
  * Support an optional basename parameter for the `install` helper.
@@ -1,6 +1,7 @@
1
1
  require 'forwardable'
2
2
  require 'fileutils'
3
3
  require 'fpm/cookery/facts'
4
+ require 'fpm/cookery/source'
4
5
  require 'fpm/cookery/source_handler'
5
6
  require 'fpm/cookery/utils'
6
7
  require 'fpm/cookery/path_helper'
@@ -79,7 +80,7 @@ module FPM
79
80
 
80
81
  def initialize(filename)
81
82
  @filename = Path.new(filename).expand_path
82
- @source_handler = SourceHandler.new(source, spec, cachedir, builddir)
83
+ @source_handler = SourceHandler.new(Source.new(source, spec), cachedir, builddir)
83
84
 
84
85
  # Set some defaults.
85
86
  vendor || self.class.vendor('fpm')
@@ -0,0 +1,41 @@
1
+ require 'uri'
2
+
3
+ module FPM
4
+ module Cookery
5
+ class Source
6
+ attr_reader :provider, :options
7
+
8
+ def initialize(url, options = nil)
9
+ options ||= {}
10
+
11
+ @url = URI(url.to_s)
12
+ @provider = options[:with]
13
+ @options = options
14
+ end
15
+
16
+ def provider?
17
+ !!@provider
18
+ end
19
+
20
+ def local?
21
+ @url.scheme.to_s.downcase == 'file'
22
+ end
23
+
24
+ def url
25
+ @url.to_s
26
+ end
27
+
28
+ def path
29
+ @url.path
30
+ end
31
+
32
+ def to_s
33
+ @url.to_s
34
+ end
35
+
36
+ def to_str
37
+ @url.to_s
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+ require 'fpm/cookery/source_handler/template'
2
+ require 'fpm/cookery/log'
3
+ require 'fileutils'
4
+
5
+ module FPM
6
+ module Cookery
7
+ class SourceHandler
8
+ class LocalPath < FPM::Cookery::SourceHandler::Template
9
+ CHECKSUM = false
10
+ NAME = :local_path
11
+
12
+ def fetch
13
+ # No need to fetch anything. The files are on the disk already.
14
+ Log.info "Local path: #{source.path}"
15
+ @local_path = source.path
16
+ end
17
+
18
+ def extract
19
+ extracted_source = (builddir/File.basename(local_path)).to_s
20
+
21
+ FileUtils.rm_rf(extracted_source)
22
+ FileUtils.cp_r(source.path, extracted_source)
23
+
24
+ extracted_source
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -20,6 +20,10 @@ module FPM
20
20
  @name = self.class::NAME
21
21
  end
22
22
 
23
+ def source
24
+ @url
25
+ end
26
+
23
27
  def fetch
24
28
  raise "#{self}#fetch not implemented!"
25
29
  end
@@ -3,44 +3,46 @@ require 'fpm/cookery/source_handler/curl'
3
3
  require 'fpm/cookery/source_handler/svn'
4
4
  require 'fpm/cookery/source_handler/git'
5
5
  require 'fpm/cookery/source_handler/hg'
6
+ require 'fpm/cookery/source_handler/local_path'
6
7
  require 'fpm/cookery/log'
7
8
 
8
9
  module FPM
9
10
  module Cookery
10
11
  class SourceHandler
11
12
  DEFAULT_HANDLER = :curl
13
+ LOCAL_HANDLER = :local_path
12
14
 
13
15
  extend Forwardable
14
16
  def_delegators :@handler, :fetch, :extract, :local_path, :checksum?
15
17
 
16
18
  attr_reader :source_url
17
19
 
18
- def initialize(source_url, options, cachedir, builddir)
19
- # The reason for these checks is related to the test cases
20
- # Test cases for individual recipe attributes
21
- # are not setting spec before hand (due to delegation chain?)
22
- # Additionally, one test actually has options being sent as a String
23
- if (options.nil? || options.class == String || options.has_key?(:with) == false)
24
- @source_provider = DEFAULT_HANDLER
25
- else
26
- @source_provider = options[:with]
27
- end
28
- @source_url = source_url
29
- @options = options
20
+ def initialize(source, cachedir, builddir)
21
+ @source = source
30
22
  @cachedir = cachedir
31
23
  @builddir = builddir
24
+
25
+ if @source.provider?
26
+ @source_provider = @source.provider
27
+ elsif @source.local?
28
+ @source_provider = LOCAL_HANDLER
29
+ else
30
+ @source_provider = DEFAULT_HANDLER
31
+ end
32
+
32
33
  @handler = get_source_handler(@source_provider)
33
34
  end
34
35
 
35
36
  private
36
37
  def get_source_handler(provider)
37
38
  klass = handler_to_class(provider)
38
- klass.new(@source_url, @options, @cachedir, @builddir)
39
+ # XXX Refactor handler to avoid passing the options.
40
+ klass.new(@source, @source.options, @cachedir, @builddir)
39
41
  end
40
42
 
41
43
  def handler_to_class(provider)
42
44
  begin
43
- self.class.const_get(provider.to_s.capitalize)
45
+ self.class.const_get(provider.to_s.split('_').map(&:capitalize).join)
44
46
  rescue NameError
45
47
  Log.error "Specified provider #{provider} does not exist."
46
48
  exit(1)
@@ -1,5 +1,5 @@
1
1
  module FPM
2
2
  module Cookery
3
- VERSION = '0.10.0'
3
+ VERSION = '0.11.0'
4
4
  end
5
5
  end
data/spec/recipe_spec.rb CHANGED
@@ -51,52 +51,131 @@ describe "Recipe" do
51
51
  #############################################################################
52
52
  # Recipe attributes
53
53
  #############################################################################
54
- def self.spec_recipe_attribute(name, value)
55
- value = Numeric === value ? value : "\"#{value}\""
56
- class_eval %Q{
57
- describe "##{name}" do
58
- it "can be set" do
59
- klass.class_eval { #{name} #{value} }
60
- klass.#{name}.must_equal #{value}
61
- recipe.#{name}.must_equal #{value}
62
- end
63
- end
64
- }
54
+ def check_attribute(attr, value, expect = nil)
55
+ expect ||= value
56
+
57
+ klass.send(attr, value)
58
+
59
+ klass.send(attr).must_equal expect
60
+ recipe.send(attr).must_equal expect
61
+ end
62
+
63
+ describe "#arch" do
64
+ it "can be set" do
65
+ check_attribute(:arch, 'i386')
66
+ end
67
+ end
68
+
69
+ describe "#description" do
70
+ it "can be set" do
71
+ check_attribute(:description, 'A nice program.')
72
+ end
73
+ end
74
+
75
+ describe "#homepage" do
76
+ it "can be set" do
77
+ check_attribute(:homepage, 'http://example.com/')
78
+ end
79
+ end
80
+
81
+ describe "#license" do
82
+ it "can be set" do
83
+ check_attribute(:license, 'MIT')
84
+ end
65
85
  end
66
86
 
67
- spec_recipe_attribute(:arch, 'i386')
68
- spec_recipe_attribute(:description, 'A nice program.')
69
- spec_recipe_attribute(:homepage, 'http://example.com')
70
- spec_recipe_attribute(:license, 'MIT')
71
- spec_recipe_attribute(:maintainer, 'John Doe <john@example.com>')
72
- spec_recipe_attribute(:sha256, '123456789abcdef')
73
- spec_recipe_attribute(:sha1, '123456789abcdef')
74
- spec_recipe_attribute(:md5, '123456789abcdef')
75
- spec_recipe_attribute(:name, 'redis')
76
- spec_recipe_attribute(:revision, 12)
77
- spec_recipe_attribute(:section, 'lang')
78
- # NOTE(lusis)
79
- # see comment in `SourceHandler#initialize` r.e. options as `String`
80
- spec_recipe_attribute(:spec, {:foo => true})
81
- spec_recipe_attribute(:vendor, 'myvendor')
82
- spec_recipe_attribute(:version, '1.2')
83
- spec_recipe_attribute(:pre_install, 'preinstall')
84
- spec_recipe_attribute(:post_install, 'postinstall')
85
- spec_recipe_attribute(:pre_uninstall, 'preuninstall')
86
- spec_recipe_attribute(:post_uninstall, 'postuninstall')
87
+ describe "#maintainer" do
88
+ it "can be set" do
89
+ check_attribute(:maintainer, 'John Doe <john@example.com>')
90
+ end
91
+ end
92
+
93
+ describe "#sha256" do
94
+ it "can be set" do
95
+ check_attribute(:sha256, '123456789abcdef')
96
+ end
97
+ end
98
+
99
+ describe "#sha1" do
100
+ it "can be set" do
101
+ check_attribute(:sha1, '123456789abcdef')
102
+ end
103
+ end
104
+
105
+ describe "#md5" do
106
+ it "can be set" do
107
+ check_attribute(:md5, '123456789abcdef')
108
+ end
109
+ end
110
+
111
+ describe "#name" do
112
+ it "can be set" do
113
+ check_attribute(:name, 'redis')
114
+ end
115
+ end
87
116
 
88
117
  describe "#revision" do
118
+ it "can be set with a string" do
119
+ check_attribute(:revision, '12')
120
+ end
121
+
89
122
  it "sets a default revision" do
90
123
  recipe.revision.must_equal 0
91
124
  end
92
125
  end
93
126
 
127
+ describe "#section" do
128
+ it "can be set" do
129
+ check_attribute(:section, 'lang')
130
+ end
131
+ end
132
+
133
+ describe "#spec" do
134
+ it "can be set" do
135
+ check_attribute(:spec, {:foo => true})
136
+ end
137
+ end
138
+
94
139
  describe "#vendor" do
140
+ it "can be set" do
141
+ check_attribute(:vendor, 'myvendor')
142
+ end
143
+
95
144
  it "sets a default vendor" do
96
145
  recipe.vendor.must_equal 'fpm'
97
146
  end
98
147
  end
99
148
 
149
+ describe "#version" do
150
+ it "can be set" do
151
+ check_attribute(:version, '1.2')
152
+ end
153
+ end
154
+
155
+ describe "#pre_install" do
156
+ it "can be set" do
157
+ check_attribute(:pre_install, 'preinstall')
158
+ end
159
+ end
160
+
161
+ describe "#post_install" do
162
+ it "can be set" do
163
+ check_attribute(:post_install, 'postinstall')
164
+ end
165
+ end
166
+
167
+ describe "#pre_uninstall" do
168
+ it "can be set" do
169
+ check_attribute(:pre_uninstall, 'preuninstall')
170
+ end
171
+ end
172
+
173
+ describe "#post_uninstall" do
174
+ it "can be set" do
175
+ check_attribute(:post_uninstall, 'postuninstall')
176
+ end
177
+ end
178
+
100
179
  def self.spec_recipe_attribute_list(name, list)
101
180
  class_eval %Q{
102
181
  describe "##{name}" do
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'fpm/cookery/source'
3
+
4
+ describe "Source" do
5
+ describe "#provider?" do
6
+ context "with a provider set" do
7
+ it "returns true" do
8
+ source = FPM::Cookery::Source.new('http://example.com/', :with => :git)
9
+
10
+ source.provider?.must_equal true
11
+ end
12
+ end
13
+
14
+ context "without a provider set" do
15
+ it "returns false" do
16
+ source = FPM::Cookery::Source.new('http://example.com/')
17
+
18
+ source.provider?.must_equal false
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "#local?" do
24
+ context "with a file:// url" do
25
+ it "returns true" do
26
+ source = FPM::Cookery::Source.new('file:///tmp')
27
+
28
+ source.local?.must_equal true
29
+ end
30
+ end
31
+
32
+ context "with no file:// url" do
33
+ it "returns false" do
34
+ source = FPM::Cookery::Source.new('https://www.example.com/')
35
+
36
+ source.local?.must_equal false
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#path" do
42
+ it "returns the url path" do
43
+ source = FPM::Cookery::Source.new('file:///opt/src/foo')
44
+
45
+ source.path.must_equal '/opt/src/foo'
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fpm-cookery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-12 00:00:00.000000000 Z
12
+ date: 2012-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fpm
@@ -121,10 +121,12 @@ files:
121
121
  - lib/fpm/cookery/path.rb
122
122
  - lib/fpm/cookery/path_helper.rb
123
123
  - lib/fpm/cookery/recipe.rb
124
+ - lib/fpm/cookery/source.rb
124
125
  - lib/fpm/cookery/source_handler.rb
125
126
  - lib/fpm/cookery/source_handler/curl.rb
126
127
  - lib/fpm/cookery/source_handler/git.rb
127
128
  - lib/fpm/cookery/source_handler/hg.rb
129
+ - lib/fpm/cookery/source_handler/local_path.rb
128
130
  - lib/fpm/cookery/source_handler/svn.rb
129
131
  - lib/fpm/cookery/source_handler/template.rb
130
132
  - lib/fpm/cookery/source_integrity_check.rb
@@ -139,6 +141,7 @@ files:
139
141
  - spec/path_spec.rb
140
142
  - spec/recipe_spec.rb
141
143
  - spec/source_integrity_check_spec.rb
144
+ - spec/source_spec.rb
142
145
  - spec/spec_helper.rb
143
146
  homepage: ''
144
147
  licenses: []
@@ -154,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
157
  version: '0'
155
158
  segments:
156
159
  - 0
157
- hash: -4411516552651280522
160
+ hash: -1591651962376197617
158
161
  required_rubygems_version: !ruby/object:Gem::Requirement
159
162
  none: false
160
163
  requirements:
@@ -163,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
166
  version: '0'
164
167
  segments:
165
168
  - 0
166
- hash: -4411516552651280522
169
+ hash: -1591651962376197617
167
170
  requirements: []
168
171
  rubyforge_project: fpm-cookery
169
172
  rubygems_version: 1.8.24