build-environment 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a75067001af37e60e254e389552e45fab4838436
4
- data.tar.gz: 32da29ef60963f838c72847c18ce393f36a1b088
3
+ metadata.gz: fe7aa5350c0a0b7f20173f1b606a53612cc8c0eb
4
+ data.tar.gz: 6927c6e07f7c74356c4169c11421a6e274caad10
5
5
  SHA512:
6
- metadata.gz: 32e81d1ac024530c33deeab102b52b8743f0c98020e08f8652c2d2428acdec97a9eb8847d9386bca9fa5730d870117b2c2de4c58c492b82417ca111775282f08
7
- data.tar.gz: aa38cf0cb47d7a114e3ac9e1a347675d1c33fd610b631f245b74794f25926b8eccefea3f2e534975c793545abc645cd7326f22de827954354d1e3598049e7af2
6
+ metadata.gz: 3ad78c5d5e9fcd2af1aa9387dea06caec6841d83cd2c57ea88969ec30990952e07ae7b82acc59f8514ea0154a243eee86d0a8dd132272d93349047042b18f1fa
7
+ data.tar.gz: 4525981ee5c236120037de512f1a32cf4a439d105b452cc190a225acd45068b84460db6a703143808edf15276cf49d8f7fe2b2d95310b5f949d80dea77c3530f
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format documentation
3
+ --backtrace
4
+ --warnings
@@ -17,8 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.6"
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rspec", "~> 3.4.0"
21
22
  spec.add_development_dependency "rake"
22
-
23
- spec.add_development_dependency "rspec", "~> 3.1.0"
24
23
  end
@@ -30,6 +30,13 @@ module Build
30
30
  end
31
31
  end
32
32
 
33
+ def freeze
34
+ @values.freeze
35
+ @parent.freeze
36
+
37
+ super
38
+ end
39
+
33
40
  def self.hash(**values)
34
41
  self.new(nil, values)
35
42
  end
@@ -63,8 +70,16 @@ module Build
63
70
  @values[key] = value
64
71
  end
65
72
 
73
+ def inspect
74
+ "#<#{self.class} #{self.to_s}>"
75
+ end
76
+
66
77
  def to_s
67
- "<#{self.class} #{self.values}>"
78
+ if @parent
79
+ "#{@parent}->#{@values}"
80
+ else
81
+ @values.to_s
82
+ end
68
83
  end
69
84
  end
70
85
  end
@@ -23,17 +23,13 @@ module Build
23
23
  Default = Struct.new(:value)
24
24
  Replace = Struct.new(:value)
25
25
 
26
- class Define
26
+ class Define < Struct.new(:klass, :block)
27
27
  def initialize(klass, &block)
28
- @klass = klass
29
- @block = block
28
+ super klass, block
30
29
  end
31
30
 
32
- attr :klass
33
- attr :block
34
-
35
31
  def to_s
36
- "<#{@klass.name} #{@block.source_location.join(':')}>"
32
+ "#<#{@klass.name} #{@block.source_location.join(':')}>"
37
33
  end
38
34
  end
39
35
 
@@ -103,10 +99,7 @@ module Build
103
99
  end
104
100
 
105
101
  def merge(&block)
106
- self.class.combine(
107
- self,
108
- self.class.new(&block)
109
- )
102
+ self.class.new(self, &block)
110
103
  end
111
104
 
112
105
  # Convert the hierarchy of environments to an array where the parent comes before the child.
@@ -55,10 +55,7 @@ module Build
55
55
  @parent.inspect(output, indent + "\t") if @parent
56
56
  end
57
57
 
58
- # This should be stable within environments that produce the same results.
59
- def checksum
60
- digester = Digest::MD5.new
61
-
58
+ def checksum(digester: Digest::MD5.new)
62
59
  checksum_recursively(digester)
63
60
 
64
61
  return digester.hexdigest
@@ -66,10 +63,14 @@ module Build
66
63
 
67
64
  protected
68
65
 
66
+ def sorted_keys
67
+ @values.keys.sort
68
+ end
69
+
69
70
  def checksum_recursively(digester)
70
- @values.each do |(key, value)|
71
+ sorted_keys.each do |key|
71
72
  digester.update(key.to_s)
72
- digester.update(value.to_s)
73
+ digester.update(@values[key].to_s)
73
74
  end
74
75
 
75
76
  @parent.checksum_recursively(digester) if @parent
@@ -62,7 +62,7 @@ module Build
62
62
 
63
63
  # Construct an environment from a given system environment:
64
64
  def self.system_environment(env = ENV)
65
- self.new(Hash[env.map{|key, value| [key.downcase.to_sym, value]}])
65
+ self.new(nil, Hash[env.map{|key, value| [key.downcase.to_sym, value]}])
66
66
  end
67
67
 
68
68
  # Make a hash appropriate for a process environment
@@ -1,5 +1,5 @@
1
1
  module Build
2
2
  class Environment
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
@@ -0,0 +1,37 @@
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'build/environment'
22
+
23
+ module Build::ChecksumSpec
24
+ describe "Build::Environment#checksum" do
25
+ it "should compute a checksum" do
26
+ e = Build::Environment.hash(a: 10, b: 20)
27
+
28
+ expect(e.checksum).to be == "0e29e95023819e0ecd2850edece5851a"
29
+ end
30
+
31
+ it "should compute same checksum when keys are in different order" do
32
+ e = Build::Environment.hash(b: 20, a: 10)
33
+
34
+ expect(e.checksum).to be == "0e29e95023819e0ecd2850edece5851a"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env rspec
2
+ #
3
+ # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'build/environment'
24
+
25
+ module Build::Environment::FreezeSpec
26
+ describe "Build::Environment#freeze" do
27
+ it "should not be frozen by default" do
28
+ a = Build::Environment.new
29
+ b = a.merge
30
+
31
+ expect(a.frozen?).to be_falsey
32
+ expect(b.frozen?).to be_falsey
33
+ expect(b.parent).to be a
34
+ end
35
+
36
+ it "should freeze an environment and it's parent" do
37
+ a = Build::Environment.new
38
+ b = a.merge
39
+
40
+ b.freeze
41
+
42
+ expect(a.frozen?).to be_truthy
43
+ expect(b.frozen?).to be_truthy
44
+ end
45
+
46
+ it "should only be partially frozen" do
47
+ a = Build::Environment.new
48
+ b = a.merge
49
+
50
+ a.freeze
51
+
52
+ expect(a.frozen?).to be_truthy
53
+ expect(b.frozen?).to be_falsey
54
+ end
55
+ end
56
+ end
@@ -49,5 +49,14 @@ module Build::Environment::SystemSpec
49
49
  expect(exported.size).to be == 1
50
50
  expect(exported).to_not include('COMPILE.FOO')
51
51
  end
52
+
53
+ it "shold load current ENV" do
54
+ ENV['TEST_KEY'] = 'test-value'
55
+
56
+ e = Build::Environment::system_environment
57
+
58
+ expect(e.values).to include(:path, :user, :home)
59
+ expect(e[:test_key]).to be == 'test-value'
60
+ end
52
61
  end
53
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: build-environment
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-13 00:00:00.000000000 Z
11
+ date: 2016-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 3.4.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 3.4.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 3.1.0
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 3.1.0
54
+ version: '0'
55
55
  description:
56
56
  email:
57
57
  - samuel.williams@oriontransfer.co.nz
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
+ - ".rspec"
63
64
  - ".simplecov"
64
65
  - ".travis.yml"
65
66
  - Gemfile
@@ -73,7 +74,9 @@ files:
73
74
  - lib/build/environment/flatten.rb
74
75
  - lib/build/environment/system.rb
75
76
  - lib/build/environment/version.rb
77
+ - spec/build/environment/checksum_spec.rb
76
78
  - spec/build/environment/environment_spec.rb
79
+ - spec/build/environment/freeze_spec.rb
77
80
  - spec/build/environment/system_spec.rb
78
81
  homepage: ''
79
82
  licenses:
@@ -95,10 +98,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
98
  version: '0'
96
99
  requirements: []
97
100
  rubyforge_project:
98
- rubygems_version: 2.2.2
101
+ rubygems_version: 2.4.6
99
102
  signing_key:
100
103
  specification_version: 4
101
104
  summary: A nested hash data structure for controlling build environments.
102
105
  test_files:
106
+ - spec/build/environment/checksum_spec.rb
103
107
  - spec/build/environment/environment_spec.rb
108
+ - spec/build/environment/freeze_spec.rb
104
109
  - spec/build/environment/system_spec.rb