Class: Universa::StoredContractBase
- Inherits:
-
Object
- Object
- Universa::StoredContractBase
- Defined in:
- lib/universa/stored_contract.rb
Overview
under construction, pls don’t use.
this is a base class for a contract stored in some contract chain. The implementation must inherit and implement its #load and #save methods at least. To do it, inherit and implement ChainStore to work with it.
Notable features:
-
contract could be assigned only once, no matter how, so its fields could be cached.
-
origin, hash_id and parent are cached. So other contract parameters should be.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#chain_store ⇒ Object
readonly
ChainStore instance to which it is connected.
-
#contract ⇒ Object
Contract instance stored in it.
- #hash_id ⇒ Object readonly
Instance Method Summary collapse
-
#has_contract? ⇒ Boolean
For implementation logic, in particular, to make lazy loads.
-
#initialize(chain_store) ⇒ StoredContractBase
constructor
Construct implementation connected to a given store.
-
#load(hash_id) ⇒ Object
override it to load the contract from the connected contract chain.
-
#origin ⇒ HashId
#contract.origin.
-
#packed_contract ⇒ String
Shortcut for ‘contract.packed`.
-
#packed_contract=(new_packed_contract) ⇒ Object
Convenience method.
-
#parent ⇒ HashId
#contract.origin.
-
#save ⇒ Object
override it to save the contract in the connected contract chain.
Constructor Details
#initialize(chain_store) ⇒ StoredContractBase
Construct implementation connected to a given store
35 36 37 38 39 |
# File 'lib/universa/stored_contract.rb', line 35 def initialize(chain_store) @chain_store = chain_store @chain_store.is_a?(ChainStore) or raise ArgumentError, "ChainStore instance required" @chain_store = chain_store end |
Instance Attribute Details
#chain_store ⇒ Object (readonly)
ChainStore instance to which it is connected
17 18 19 |
# File 'lib/universa/stored_contract.rb', line 17 def chain_store @chain_store end |
#contract ⇒ Object
Contract instance stored in it. Can be lazy-loaded
19 20 21 |
# File 'lib/universa/stored_contract.rb', line 19 def contract @contract end |
Instance Method Details
#has_contract? ⇒ Boolean
For implementation logic, in particular, to make lazy loads.
43 44 45 |
# File 'lib/universa/stored_contract.rb', line 43 def has_contract? !@contract.nil? end |
#load(hash_id) ⇒ Object
override it to load the contract from the connected contract chain.
59 60 61 |
# File 'lib/universa/stored_contract.rb', line 59 def load hash_id raise NotFoundError end |
#origin ⇒ HashId
Returns #contract.origin. See Contract#origin.
24 25 26 |
# File 'lib/universa/stored_contract.rb', line 24 def origin @origin ||= @contract.origin end |
#packed_contract ⇒ String
Shortcut for ‘contract.packed`. See Contract#packed
49 50 51 |
# File 'lib/universa/stored_contract.rb', line 49 def packed_contract @contract.packed end |
#packed_contract=(new_packed_contract) ⇒ Object
Convenience method. Unoacks and stores the contract.
73 74 75 |
# File 'lib/universa/stored_contract.rb', line 73 def packed_contract=(new_packed_contract) self.contract = Contract.from_packed(new_packed_contract) end |
#parent ⇒ HashId
Returns #contract.origin. See Contract#parent.
29 30 31 |
# File 'lib/universa/stored_contract.rb', line 29 def parent @parent ||= @contract.parent end |
#save ⇒ Object
override it to save the contract in the connected contract chain.
54 55 56 |
# File 'lib/universa/stored_contract.rb', line 54 def save raise NotFoundError end |