Class: Tefoji::DeclaredValue
- Inherits:
-
Object
- Object
- Tefoji::DeclaredValue
- Defined in:
- lib/tefoji/declared_value.rb
Instance Method Summary collapse
- #%(other) ⇒ Object
- #falsey? ⇒ Boolean
-
#initialize(user_value = nil) ⇒ DeclaredValue
constructor
A new instance of DeclaredValue.
- #prepend(*prepended_things) ⇒ Object
-
#simple? ⇒ Boolean
For most DeclaredValues that aren’t Structs that have their one ‘value` method.
- #to_a ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
- #truthy? ⇒ Boolean
-
#unset? ⇒ Boolean
When querying @value, we don’t want to invoke @value.computed_value because it may have unwanted side-effects.
- #value ⇒ Object
Constructor Details
#initialize(user_value = nil) ⇒ DeclaredValue
Returns a new instance of DeclaredValue.
3 4 5 6 7 8 9 10 |
# File 'lib/tefoji/declared_value.rb', line 3 def initialize(user_value = nil) @value = if user_value.is_a? DeclaredValue # prevent recursive DeclaredValues user_value.value else user_value end end |
Instance Method Details
#%(other) ⇒ Object
46 47 48 |
# File 'lib/tefoji/declared_value.rb', line 46 def %(other) value % other end |
#falsey? ⇒ Boolean
56 57 58 |
# File 'lib/tefoji/declared_value.rb', line 56 def falsey? simple? && (@value.nil? || @value.empty? || @value.downcase == 'false' || @value == false) end |
#prepend(*prepended_things) ⇒ Object
25 26 27 |
# File 'lib/tefoji/declared_value.rb', line 25 def prepend(*prepended_things) value.prepend(*prepended_things) end |
#simple? ⇒ Boolean
For most DeclaredValues that aren’t Structs that have their one ‘value` method
13 14 15 |
# File 'lib/tefoji/declared_value.rb', line 13 def simple? !@value.respond_to?(:computed_value) end |
#to_a ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/tefoji/declared_value.rb', line 37 def to_a current = value if current.is_a? Array current else [current] end end |
#to_i ⇒ Object
29 30 31 |
# File 'lib/tefoji/declared_value.rb', line 29 def to_i value.to_i end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/tefoji/declared_value.rb', line 33 def to_s value.to_s end |
#truthy? ⇒ Boolean
60 61 62 |
# File 'lib/tefoji/declared_value.rb', line 60 def truthy? !falsey? end |
#unset? ⇒ Boolean
When querying @value, we don’t want to invoke @value.computed_value because it may have unwanted side-effects.
52 53 54 |
# File 'lib/tefoji/declared_value.rb', line 52 def unset? @value.nil? end |
#value ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/tefoji/declared_value.rb', line 17 def value if simple? @value else @value.computed_value end end |