declarative 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/CHANGES.md +5 -1
- data/lib/declarative/heritage.rb +12 -5
- data/lib/declarative/version.rb +1 -1
- data/test/heritage_test.rb +16 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ab032b5544502fa2a01df856e3428cbe833c319
|
4
|
+
data.tar.gz: 1fa86db96bf352a9c19077e9f873524556d7977f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ec13db2b7873e515bd79ecf88c666cb60ad0236f51f00c154a1fe26cd8a54f524a619821545fc4f543cd2109ff75899ef3abf635393c09fa5fe78a037cb03fd
|
7
|
+
data.tar.gz: 144864e4b5ea0b6ae8d8429a61b28814ae3764dfa588c64224459c29e99d4f10dc5f944fbb84f1f8026a9ea4ab679d85d91376085d47082b501095eafb1eb30b
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 0.0.6
|
2
|
+
|
3
|
+
* `Heritage#call` now accepts a block that allows processing the arguments for every recorded statement before replaying them. This provides a hook to inject or change parameters, e.g. to mark a replay as an inheritance.
|
4
|
+
|
1
5
|
# 0.0.5
|
2
6
|
|
3
7
|
* Introduce `Schema::build_definition` as a central entry point for building `Definition` without any heritage involved.
|
@@ -14,4 +18,4 @@
|
|
14
18
|
|
15
19
|
* First usable version with `Declarative::Schema` and friends.
|
16
20
|
|
17
|
-
TODO: default_nested_class RM
|
21
|
+
TODO: default_nested_class RM
|
data/lib/declarative/heritage.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
module Declarative
|
2
2
|
class Heritage < Array
|
3
|
+
# Record inheritable assignments for replay in an inheriting class.
|
3
4
|
def record(method, *args, &block)
|
4
5
|
self << {method: method, args: DeepDup.(args), block: block} # DISCUSS: options.dup.
|
5
6
|
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
# Replay the recorded assignments on inheritor.
|
9
|
+
# Accepts a block that will allow processing the arguments for every recorded statement.
|
10
|
+
def call(inheritor, &block)
|
11
|
+
each { |cfg| call!(inheritor, cfg, &block) }
|
11
12
|
end
|
12
13
|
|
14
|
+
private
|
15
|
+
def call!(inheritor, cfg)
|
16
|
+
yield cfg if block_given? # allow messing around with recorded arguments.
|
17
|
+
|
18
|
+
inheritor.send(cfg[:method], *cfg[:args], &cfg[:block])
|
19
|
+
end
|
13
20
|
|
14
21
|
module DSL
|
15
22
|
def heritage
|
@@ -33,4 +40,4 @@ module Declarative
|
|
33
40
|
end
|
34
41
|
end
|
35
42
|
end
|
36
|
-
end
|
43
|
+
end
|
data/lib/declarative/version.rb
CHANGED
data/test/heritage_test.rb
CHANGED
@@ -31,4 +31,19 @@ class HeritageTest < Minitest::Spec
|
|
31
31
|
|
32
32
|
it { B.heritage.inspect.must_equal "[{:method=>:property, :args=>[:name, {:render=>true, :nested=>{:render=>false}}], :block=>#<Proc:@heritage_test.rb:4>}]" }
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
|
+
describe "#call with block" do
|
36
|
+
let (:heritage) { Declarative::Heritage.new.record(:property, :id, {}) }
|
37
|
+
|
38
|
+
class CallWithBlock
|
39
|
+
def self.property(name, options)
|
40
|
+
@args = [name, options]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it do
|
45
|
+
heritage.(CallWithBlock) { |cfg| cfg[:args].last.merge!(_inherited: true) }
|
46
|
+
CallWithBlock.instance_variable_get(:@args).must_equal [:id, {:_inherited=>true}]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: declarative
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uber
|