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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fdc4811d1bc11bebe8a39516580f1e7e5969212
4
- data.tar.gz: f12960019b725cf6337073927796867987030e2e
3
+ metadata.gz: 9ab032b5544502fa2a01df856e3428cbe833c319
4
+ data.tar.gz: 1fa86db96bf352a9c19077e9f873524556d7977f
5
5
  SHA512:
6
- metadata.gz: 7bf1836d15d1a5953b37d299e40f8213a1b774f4026d87b28ed0a37eb05e3c325f81aa543d2de607569578ce215a53b680c1a27420eed5c3b752a4fb26afe8d0
7
- data.tar.gz: 83bee84f05b7fe7331e7d745aecf124fbe8c152f480cd5c51698bc172c1f0fb8058833f6c1d1f6ff4fd2e593934a41d68feee6a36d20d8445c1e6a7c5c788925
6
+ metadata.gz: 4ec13db2b7873e515bd79ecf88c666cb60ad0236f51f00c154a1fe26cd8a54f524a619821545fc4f543cd2109ff75899ef3abf635393c09fa5fe78a037cb03fd
7
+ data.tar.gz: 144864e4b5ea0b6ae8d8429a61b28814ae3764dfa588c64224459c29e99d4f10dc5f944fbb84f1f8026a9ea4ab679d85d91376085d47082b501095eafb1eb30b
@@ -5,4 +5,6 @@ rvm:
5
5
  - 2.0.0
6
6
  - 1.9.3
7
7
  gemfile:
8
- - Gemfile
8
+ - Gemfile
9
+ before_install:
10
+ - gem install bundler
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
@@ -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
- def call(inheritor)
8
- each do |cfg|
9
- inheritor.send(cfg[:method], *cfg[:args], &cfg[:block])
10
- end
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
@@ -1,3 +1,3 @@
1
1
  module Declarative
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -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
- end
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.5
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: 2015-11-07 00:00:00.000000000 Z
11
+ date: 2016-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber