Class: DataContract::Scatter
- Inherits:
-
Object
- Object
- DataContract::Scatter
- Includes:
- Initializer
- Defined in:
- lib/data_contract/scatter.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.!(list, receiver, contract_module) ⇒ Object
7 8 9 10 11 |
# File 'lib/data_contract/scatter.rb', line 7 def self.!(list, receiver, contract_module) assignable_contracts = list.assignable(receiver) instance = new list, list.obj, receiver, assignable_contracts, contract_module instance.! end |
Instance Method Details
#! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/data_contract/scatter.rb', line 13 def ! if assignable_contracts.empty? raise ContractError, "#{receiver.class.name} cannot be assigned from #{source.class.name} without a shared or compatible contract" end if contract_module @assignable_contracts = specific_contract end assignable_contracts.each do |contract| copy_data contract end receiver end |
#copy_data(contract) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/data_contract/scatter.rb', line 39 def copy_data(contract) contract.setters.each do |setter| getter = setter[0...-1] val = source.send getter receiver.send setter, val end receiver end |
#specific_contract ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/data_contract/scatter.rb', line 29 def specific_contract contract = list[contract_module] unless assignable_contracts.include? contract raise ContractError, "#{receiver.class.name} cannot be assigned from #{contract_module.name} without a shared or compatible contract" end [contract] end |