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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8578d4e2bac5649c5c7151ba5bd12fe72129ff5b
4
- data.tar.gz: aacdb343d6a2af0d1afa97c3f4b6d57bdda8f430
3
+ metadata.gz: e708facb4e75c251034eaf360f25718cca5962ba
4
+ data.tar.gz: 92dfe406b28d3254d9048a9a15cbd20703697698
5
5
  SHA512:
6
- metadata.gz: cf3068a09d339ae0dada6f14ab9e293304a29ff2c17b22ef294c67f1d05f6e8e301b34b7c041574300f080e501064d55bc0833dff4c9b6b0155de37db80ba447
7
- data.tar.gz: f459919bc8ed89c4989b207afc692c74d501221490737e770c1e268f37bd6c5905b71e0ca8f0ff1351373e3cdfaa505238dc795afe1ca4e043a0c4d329d91fb9
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
@@ -6,7 +6,7 @@ class DataContract < Module
6
6
  @data_contracts = ContractList.new self
7
7
 
8
8
  data_contract_modules.each do |contract_module|
9
- @data_contracts << Contract.new(contract_module)
9
+ @data_contracts << Contract.new(contract_module, self)
10
10
  end
11
11
 
12
12
  @data_contracts
@@ -2,11 +2,11 @@ class DataContract < Module
2
2
  class Scatter
3
3
  include Initializer
4
4
 
5
- initializer :list, :source, :receiver, :assignable_contracts, :contract_module
5
+ initializer :contract_list, :source, :receiver, :assignable_contracts, :contract_module
6
6
 
7
- def self.!(list, receiver, contract_module)
8
- assignable_contracts = list.assignable(receiver)
9
- instance = new list, list.obj, receiver, assignable_contracts, contract_module
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
- copy_data contract
23
+ contract.scatter receiver
24
24
  end
25
25
 
26
26
  receiver
27
27
  end
28
28
 
29
29
  def specific_contract
30
- contract = list[contract_module]
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.3
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-25 00:00:00.000000000 Z
11
+ date: 2013-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: initializer