atacama 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57d7c04c5890cdf6985a82af71ac69e32739a3eb
4
- data.tar.gz: 891d78acb5338faf7785095d141428805e7bc292
3
+ metadata.gz: e1dd85acd949dc1261176c76b76e38add8ab8772
4
+ data.tar.gz: 3d0006d2e584122ca3534748f620e0a335acad5b
5
5
  SHA512:
6
- metadata.gz: 43c1eeb7e3f30baf02bd20439e13524d5ee945a85cb6445ec6458d4578341d64a8e0def14361e3c13794a25616b0784822360c19da0fef5c046cec2425059735
7
- data.tar.gz: d656e76622ecff876f02f9b826dc112fe38adea3f5ae444945f4bbde08a60381a9cfa53b8f4e5b5434b19c865eb3d48090ea19d0a989c060f655f01f11dd8b2e
6
+ metadata.gz: f3938b99da71d5b9994c8993b01b42847c9e09dff9523b7d9650a7abe977d91aff71a60169378d9207ad65e1a8eb1cd51c0846b33bda4d4724396d61815115b2
7
+ data.tar.gz: 1bd1146d793105404d1ea9e5f27b7c310c695ac378babb683d1cae83dace8af5a0ad1b017fc743c0ba1fd4f3e3d2011c40f1bb9d0684d3f24d29fe2c4c146782
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atacama (0.1.1)
4
+ atacama (0.1.3)
5
5
  dry-types (~> 0.13.2)
6
6
 
7
7
  GEM
@@ -41,4 +41,4 @@ DEPENDENCIES
41
41
  rake (~> 10.0)
42
42
 
43
43
  BUNDLED WITH
44
- 1.16.2
44
+ 1.16.3
@@ -8,9 +8,8 @@ module Atacama
8
8
  alias key? respond_to?
9
9
 
10
10
  def merge!(hash)
11
- hash.each do |(key, value)|
12
- self[key] = value
13
- end
11
+ hash.each { |(key, value)| self[key] = value }
12
+ self
14
13
  end
15
14
  end
16
15
  end
@@ -21,6 +21,14 @@ module Atacama
21
21
  ContextInterface = Types::Strict::Hash | Types.Instance(Context)
22
22
 
23
23
  class << self
24
+ def injected=(hash)
25
+ @injected = Types::Strict::Hash[hash]
26
+ end
27
+
28
+ def injected
29
+ @injected || {}
30
+ end
31
+
24
32
  def options
25
33
  @options ||= {}
26
34
  end
@@ -28,8 +36,7 @@ module Atacama
28
36
  # Define an initializer value.
29
37
  # @param [Symbol] name of the argument
30
38
  def option(name, **kwargs)
31
- NameInterface[name] # Validate type
32
- options[name] = Parameter.new(name: name, **kwargs)
39
+ options[NameInterface[name]] = Parameter.new(name: name, **kwargs)
33
40
 
34
41
  define_method(name) { @context[name] }
35
42
  define_method("#{name}?") { !!@context[name] }
@@ -38,13 +45,23 @@ module Atacama
38
45
  def call(context = {})
39
46
  new(context: context).call
40
47
  end
48
+
49
+ def inject(injected)
50
+ Class.new(self) do
51
+ self.injected = injected
52
+ end
53
+ end
41
54
  end
42
55
 
43
56
  attr_reader :context
44
57
 
45
58
  def initialize(context: {}, **)
46
59
  ContextInterface[context] # Validate the type
47
- @context = context.is_a?(Context) ? context : Context.new(context)
60
+
61
+ @context = Context.new(self.class.injected).tap do |ctx|
62
+ ctx.merge!(context.is_a?(Context) ? context.to_h : context)
63
+ end
64
+
48
65
  Validator.call(options: self.class.options, context: @context)
49
66
  end
50
67
 
@@ -1,3 +1,3 @@
1
1
  module Atacama
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atacama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Johnston
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-01 00:00:00.000000000 Z
11
+ date: 2018-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-types