Module: InlineTransforms
- Included in:
- Object
- Defined in:
- lib/inline_transforms.rb,
lib/inline_transforms/version.rb
Overview
Defines only_if, unless, and transform, which we'll then want to make available in Object instances.
Constant Summary collapse
- VERSION =
'0.3.0'.freeze
Instance Method Summary collapse
-
#only_if(good_value, **options) ⇒ Object
Returns
selfonly if it matches a "good" value; otherwise returns an alternate (else:) value. -
#transform(**options) ⇒ Object
Returns
self... -
#unless(bad_value, **options) ⇒ Object
Returns
self...
Instance Method Details
#only_if(good_value, **options) ⇒ Object
Returns self only if it matches a "good" value; otherwise returns an alternate (else:) value.
(NOTE: this takes an else: nil named param, but is defined as taking (**options) because else is reserved.)
26 27 28 29 30 |
# File 'lib/inline_transforms.rb', line 26 def only_if(good_value, **) return self if inline_transforms_equality? good_value inline_transforms_response_processor [:else] end |
#transform(**options) ⇒ Object
Returns self ... unless it matches one of the keys in the given "transformation hash", in which case the
corresponding hash value is returned. If no matching hash key is found, this returns a fallback (else:) value.
(NOTE: this takes an else: nil named param, but is defined as taking (**options) because else is reserved.)
68 69 70 71 72 73 |
# File 'lib/inline_transforms.rb', line 68 def transform(**) default = .delete :else .each { |key, value| return inline_transforms_response_processor value if inline_transforms_equality? key } inline_transforms_response_processor default end |
#unless(bad_value, **options) ⇒ Object
Returns self ... unless it matches a "bad" value, in which case it returns an alternate (then:) value.
(NOTE: this takes a then: nil named param, but is defined as taking (**options) because then is reserved.)
47 48 49 50 51 |
# File 'lib/inline_transforms.rb', line 47 def unless(bad_value, **) return self unless inline_transforms_equality? bad_value inline_transforms_response_processor [:then] end |