jimmy 0.3.1 → 0.3.2

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: 8e19cc9c83e2881cb849f0e706878b4768171fcf
4
- data.tar.gz: b0700ff1202645eb217e13ea2ae65bdccc043f89
3
+ metadata.gz: 9a528bcad0fb42079b9497df793dd18e00303651
4
+ data.tar.gz: e33cea2e53c93a02f99e875b23ff7dda1c54bce3
5
5
  SHA512:
6
- metadata.gz: 00dd76c52214222acca04a4bfe638f4a969c00484969c269d31b436c7cb77c53a2acda9cb61eefff14391d03899f0e12581beba3c3eb60775f0331ad4b13307c
7
- data.tar.gz: 5ddeef3280aecdfd8598d027a0d3810dbca2440dce29fc90f599a78668e9f1a5f7310708fdc84a2246a41c09b437e8b740027a094a0b6eab4ae8b474d2570e12
6
+ metadata.gz: 8789d546ee5e8353f21393331ba1c00bb96d737e2dff463e93d874a895904993870a36d273709215fce5922ec79b53ad3b83e2f3c55f5269a37861be85664eae
7
+ data.tar.gz: 3d6505a992d4b0239fb737f540a1a30563a00ac62f88ac27a9ef5fcaa87f6bfdb68bd57382980907014516df65d77fefa88205bfcfd2bef63d5376a24682bb2a
@@ -3,12 +3,16 @@ require_relative 'schema_types'
3
3
  module Jimmy
4
4
  class Combination < Array
5
5
 
6
- attr_reader :condition, :domain
6
+ attr_reader :condition, :schema
7
7
 
8
8
  # @param [Symbol] condition One of :one, :all, or :any
9
- def initialize(condition, domain)
9
+ def initialize(condition, schema)
10
10
  @condition = condition
11
- @domain = domain
11
+ @schema = schema
12
+ end
13
+
14
+ def domain
15
+ schema.domain
12
16
  end
13
17
 
14
18
  def evaluate(types_proc)
@@ -16,7 +20,11 @@ module Jimmy
16
20
  end
17
21
 
18
22
  def compile
19
- {"#{condition}Of" => map(&:compile)}
23
+ data.merge "#{condition}Of" => map(&:compile)
24
+ end
25
+
26
+ def data
27
+ @data ||= {}
20
28
  end
21
29
 
22
30
  SchemaCreation.apply_to(self) { |schema| push schema }
@@ -18,6 +18,10 @@ module Jimmy
18
18
  map { |k, v| [k.to_s, v.compile] }.to_h
19
19
  end
20
20
 
21
+ def data
22
+ schema.data
23
+ end
24
+
21
25
  def [](key)
22
26
  super || (schema.parent && schema.parent.definitions[key])
23
27
  end
@@ -11,17 +11,17 @@ module Jimmy
11
11
  @handlers[klass] = handler
12
12
  %i(one all any).each do |condition|
13
13
  klass.__send__ :define_method, :"#{condition}_of" do |*args, &inner_block|
14
- Combination.new(condition, domain).tap do |combo|
14
+ Combination.new(condition, schema).tap do |combo|
15
15
  combo.with_locals(locals) { combo.evaluate inner_block }
16
16
  instance_exec combo, *args, &handler
17
17
  end
18
18
  end
19
19
  end
20
- klass.include MissingMethods
20
+ klass.include DefiningMethods
21
21
  end
22
22
  end
23
23
 
24
- module MissingMethods
24
+ module DefiningMethods
25
25
 
26
26
  def locals
27
27
  @locals ||= {}
@@ -40,6 +40,12 @@ module Jimmy
40
40
  locals.key?(method) || reserved?(method, false) || super
41
41
  end
42
42
 
43
+ def set(**values)
44
+ values.each { |k, v| data[k.to_s] = v }
45
+ end
46
+
47
+ %i[title description default].each { |k| define_method(k) { |v| set k => v } }
48
+
43
49
  def method_missing(method, *args, &block)
44
50
  return locals[method] if locals.key?(method)
45
51
 
@@ -63,10 +63,6 @@ module Jimmy
63
63
  end
64
64
  end
65
65
 
66
- def set(**values)
67
- values.each { |k, v| schema.data[k.to_s] = v }
68
- end
69
-
70
66
  def definitions(&block)
71
67
  schema.definitions.evaluate &block
72
68
  end
@@ -75,7 +71,9 @@ module Jimmy
75
71
  definitions { __send__ type, *args, &block }
76
72
  end
77
73
 
78
- %i[title description default].each { |k| define_method(k) { |v| set k => v } }
74
+ def data
75
+ schema.data
76
+ end
79
77
 
80
78
  def ref(*args, uri)
81
79
  handler = SchemaCreation.handlers[self.class]
data/lib/jimmy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jimmy
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jimmy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil E. Pearson