build-environment 1.7.0 → 1.8.0

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
  SHA256:
3
- metadata.gz: 477225cdb8e76a563c7bde99e75e070a652c9a0ce44fc39d4de168174cc3a63b
4
- data.tar.gz: 445e04d9e753aa2c48def0d5783060b045c76221aab9b5d015422fb24df3215f
3
+ metadata.gz: d765ae7137acd3261bc930cef2d36665960fde94d0a3c847bfc0933d6c6c7f72
4
+ data.tar.gz: 3e0855da0b94f31d73577e296635eb0836978d7b80f871cdced5174f670a316e
5
5
  SHA512:
6
- metadata.gz: bd143a1777f2c706f6a151a677974a7ea968e4fd843c82725de43dbdea5ba5ae0c778573e7580fccc0c7f6488d084c54fd615b61ae6efdca4231ca360ca1076d
7
- data.tar.gz: 3c4a6ac1d0bc84ba9ee6ec41366b1e981446572495ce9ff2a5920c54b851ab188a8fd0663602f8fe37a0456073c7df3218bd55251a617747bc2ed269684d1f55
6
+ metadata.gz: 1c4bbdc188210aaaa92b7cddcecbad102bc2dd572015f706ccd599504c0dc62c6a129f29e604a9dedd291b69bcde96f14ced273e0abf4de5934bd4daecee45fb
7
+ data.tar.gz: 44b7e72c085b8a0321ea4de298424fb7dd84ba6a09e98cf3bc23f88e99e48c10c9db502ce89cdb0bb7b0eabf2ad2a6f9880bd734df5469368a07195fcb015fc7
@@ -74,6 +74,18 @@ module Build
74
74
  @values.size + (@parent ? @parent.size : 0)
75
75
  end
76
76
 
77
+ def fetch(key, *default, &block)
78
+ if environment = lookup(key)
79
+ return environment.values[key]
80
+ elsif block_given?
81
+ yield(key, *default)
82
+ elsif !default.empty?
83
+ return default.first
84
+ else
85
+ raise KeyError.new("Environment missing #{key}")
86
+ end
87
+ end
88
+
77
89
  def [](key)
78
90
  environment = lookup(key)
79
91
 
@@ -53,11 +53,15 @@ module Build
53
53
 
54
54
  def method_missing(name, *args, **options, &block)
55
55
  if options.empty?
56
- if block_given? and args.empty?
57
- @environment[name] = block
58
-
59
- return name
60
- elsif !block_given? and !args.empty?
56
+ if args.empty?
57
+ if block_given?
58
+ @environment[name] = block
59
+
60
+ return name
61
+ else
62
+ return @environment.fetch(name)
63
+ end
64
+ elsif !block_given?
61
65
  if args.count == 1
62
66
  @environment[name] = args.first
63
67
  else
@@ -1,5 +1,5 @@
1
1
  module Build
2
2
  class Environment
3
- VERSION = "1.7.0"
3
+ VERSION = "1.8.0"
4
4
  end
5
5
  end
@@ -52,4 +52,13 @@ RSpec.describe Build::Environment::Constructor do
52
52
 
53
53
  subject.build library: 'bar', &a_block
54
54
  end
55
+
56
+ it "can get environment value" do
57
+ subject.foo :bar
58
+ expect(subject.foo).to be == :bar
59
+ end
60
+
61
+ it "raises error when trying to access non-existant value" do
62
+ expect{subject.foo}.to raise_error(KeyError)
63
+ end
55
64
  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.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-05 00:00:00.000000000 Z
11
+ date: 2019-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: covered
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubygems_version: 3.0.2
119
+ rubygems_version: 3.0.3
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: A nested hash data structure for controlling build environments.