data_contract 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/data_contract/contract.rb +17 -1
- data/lib/data_contract/data_contracts_impl.rb +1 -1
- data/lib/data_contract/scatter.rb +6 -15
- 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: e708facb4e75c251034eaf360f25718cca5962ba
|
4
|
+
data.tar.gz: 92dfe406b28d3254d9048a9a15cbd20703697698
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 418142349c27fcdd96c41a6e88f86fc2a3b95d253a079f489d1b3daa677ceaf946fb13865008ed413874d8fde8f613de061be92f106bf7a815b56b4480431dda
|
7
|
+
data.tar.gz: 52f74d2b236ea7b5cf239262e9ddd310f74e3ba516c58221704a084ef81609d95df3ddcdc1699abccf3707a18dcf02c452d019c453b16447c5225c0592897b18
|
@@ -1,9 +1,11 @@
|
|
1
1
|
class DataContract < Module
|
2
2
|
class Contract
|
3
3
|
attr_reader :mod
|
4
|
+
attr_reader :obj
|
4
5
|
|
5
|
-
def initialize(mod)
|
6
|
+
def initialize(mod, obj)
|
6
7
|
@mod = mod
|
8
|
+
@obj = obj
|
7
9
|
end
|
8
10
|
|
9
11
|
def setters
|
@@ -33,5 +35,19 @@ class DataContract < Module
|
|
33
35
|
end
|
34
36
|
true
|
35
37
|
end
|
38
|
+
|
39
|
+
def scatter(receiver)
|
40
|
+
getters.each do |attribute|
|
41
|
+
val = obj.send attribute
|
42
|
+
assign val, receiver, attribute
|
43
|
+
end
|
44
|
+
receiver
|
45
|
+
end
|
46
|
+
|
47
|
+
def assign(val, receiver, attribute)
|
48
|
+
setter = "#{attribute}="
|
49
|
+
raise ContractError, "The #{attribute} attribute cannot be assigned to #{receiver.class.name}" unless receiver.respond_to? setter
|
50
|
+
receiver.send setter, val
|
51
|
+
end
|
36
52
|
end
|
37
53
|
end
|
@@ -2,11 +2,11 @@ class DataContract < Module
|
|
2
2
|
class Scatter
|
3
3
|
include Initializer
|
4
4
|
|
5
|
-
initializer :
|
5
|
+
initializer :contract_list, :source, :receiver, :assignable_contracts, :contract_module
|
6
6
|
|
7
|
-
def self.!(
|
8
|
-
assignable_contracts =
|
9
|
-
instance = new
|
7
|
+
def self.!(contract_list, receiver, contract_module)
|
8
|
+
assignable_contracts = contract_list.assignable(receiver)
|
9
|
+
instance = new contract_list, contract_list.obj, receiver, assignable_contracts, contract_module
|
10
10
|
instance.!
|
11
11
|
end
|
12
12
|
|
@@ -20,14 +20,14 @@ class DataContract < Module
|
|
20
20
|
end
|
21
21
|
|
22
22
|
assignable_contracts.each do |contract|
|
23
|
-
|
23
|
+
contract.scatter receiver
|
24
24
|
end
|
25
25
|
|
26
26
|
receiver
|
27
27
|
end
|
28
28
|
|
29
29
|
def specific_contract
|
30
|
-
contract =
|
30
|
+
contract = contract_list[contract_module]
|
31
31
|
|
32
32
|
unless assignable_contracts.include? contract
|
33
33
|
raise ContractError, "#{receiver.class.name} cannot be assigned from #{contract_module.name} without a shared or compatible contract"
|
@@ -35,14 +35,5 @@ class DataContract < Module
|
|
35
35
|
|
36
36
|
[contract]
|
37
37
|
end
|
38
|
-
|
39
|
-
def copy_data(contract)
|
40
|
-
contract.setters.each do |setter|
|
41
|
-
getter = setter[0...-1]
|
42
|
-
val = source.send getter
|
43
|
-
receiver.send setter, val
|
44
|
-
end
|
45
|
-
receiver
|
46
|
-
end
|
47
38
|
end
|
48
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_contract
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Sans Collective
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: initializer
|