Module: Stellar::ClaimPredicate::FactoryMethods
- Included in:
- Stellar::ClaimPredicate
- Defined in:
- lib/stellar/claim_predicate.rb
Instance Method Summary collapse
-
#after(time) ⇒ ClaimPredicate
Constructs a negated predicate from either relative or absolute time based on the type of the input.
-
#before(time) ⇒ ClaimPredicate
Constructs either relative or absolute time predicate based on the type of the input.
-
#before_absolute_time(timestamp) ⇒ ClaimPredicate
Constructs an ‘before_absolute_time` claim predicate.
-
#before_relative_time(seconds) ⇒ ClaimPredicate
Constructs a ‘before_relative_time` claim predicate.
-
#compose(&block) ⇒ ClaimPredicate
Compose a complex predicate by calling DSL methods from the block.
-
#unconditional ⇒ ClaimPredicate
Constructs an ‘unconditional` claim predicate.
Instance Method Details
#after(time) ⇒ ClaimPredicate
Constructs a negated predicate from either relative or absolute time based on the type of the input.
73 74 75 |
# File 'lib/stellar/claim_predicate.rb', line 73 def after(time) ~before(time) end |
#before(time) ⇒ ClaimPredicate
Constructs either relative or absolute time predicate based on the type of the input.
If input is an instance of ‘ActiveSupport::Duration` class it will be handled as a relative time (seconds since close time of the ledger), otherwise it will be treated as an absolute time.
It is intended to work with time helpers provided by ActiveSupport, like ‘1.day` (relative) or `2.weeks.from_now` (absolute).
64 65 66 |
# File 'lib/stellar/claim_predicate.rb', line 64 def before(time) ActiveSupport::Duration === time ? before_relative_time(time.to_i) : before_absolute_time(time) end |
#before_absolute_time(timestamp) ⇒ ClaimPredicate
Constructs an ‘before_absolute_time` claim predicate.
This predicate will be fulfilled if the closing time of the ledger that includes the Stellar::CreateClaimableBalance operation is less than provided timestamp.
41 42 43 44 45 |
# File 'lib/stellar/claim_predicate.rb', line 41 def before_absolute_time() = .to_time if .respond_to?(:to_time) ClaimPredicate.new(ClaimPredicateType::BEFORE_ABSOLUTE_TIME, Integer()) end |
#before_relative_time(seconds) ⇒ ClaimPredicate
Constructs a ‘before_relative_time` claim predicate.
This predicate will be fulfilled if the closing time of the ledger that includes the Stellar::CreateClaimableBalance operation plus this relative time delta (in seconds) is less than the current time.
29 30 31 |
# File 'lib/stellar/claim_predicate.rb', line 29 def before_relative_time(seconds) ClaimPredicate.new(ClaimPredicateType::BEFORE_RELATIVE_TIME, Integer(seconds)) end |
#compose(&block) ⇒ ClaimPredicate
Compose a complex predicate by calling DSL methods from the block.
86 87 88 89 |
# File 'lib/stellar/claim_predicate.rb', line 86 def compose(&block) result = instance_eval(&block) result.nil? ? unconditional : result end |
#unconditional ⇒ ClaimPredicate
Constructs an ‘unconditional` claim predicate.
This predicate will be always fulfilled.
16 17 18 |
# File 'lib/stellar/claim_predicate.rb', line 16 def unconditional ClaimPredicate.new(ClaimPredicateType::UNCONDITIONAL) end |