Module: Sail::ValueCast
- Included in:
- Setting
- Defined in:
- lib/sail/value_cast.rb
Overview
ValueCast This module was made to be extended by the Setting model. It contains all setting type value casts so that the model itself can use dynamic invocation
Instance Method Summary collapse
- #ab_test_get(value) ⇒ Object
- #ab_test_set(value) ⇒ Object
- #array_get(value) ⇒ Object
- #array_set(value) ⇒ Object
- #boolean_get(value) ⇒ Object
- #boolean_set(value) ⇒ Object
- #cron_get(value) ⇒ Object
- #cron_set(value) ⇒ Object
- #date_get(value) ⇒ Object
- #date_set(value) ⇒ Object
- #float_get(value) ⇒ Object
- #float_set(value) ⇒ Object
-
#integer_get(value) ⇒ Object
Section for get value casts.
-
#integer_set(value) ⇒ Object
Section for set value casts.
- #obj_model_get(value) ⇒ Object
- #obj_model_set(value) ⇒ Object
- #range_get(value) ⇒ Object
- #range_set(value) ⇒ Object
- #string_get(value) ⇒ Object
- #string_set(value) ⇒ Object
- #throttle_get(value) ⇒ Object
- #throttle_set(value) ⇒ Object
- #uri_get(value) ⇒ Object
- #uri_set(value) ⇒ Object
Instance Method Details
#ab_test_get(value) ⇒ Object
37 38 39 |
# File 'lib/sail/value_cast.rb', line 37 def ab_test_get(value) value == Sail::ConstantCollection::TRUE ? Sail::ConstantCollection::BOOLEANS.sample : false end |
#ab_test_set(value) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/sail/value_cast.rb', line 89 def ab_test_set(value) if value.is_a?(String) check_for_on_or_boolean(value) elsif value.nil? Sail::ConstantCollection::FALSE else value.to_s end end |
#array_get(value) ⇒ Object
33 34 35 |
# File 'lib/sail/value_cast.rb', line 33 def array_get(value) value.split(Sail.configuration.array_separator) end |
#array_set(value) ⇒ Object
99 100 101 |
# File 'lib/sail/value_cast.rb', line 99 def array_set(value) value.is_a?(String) ? value : value.join(Sail.configuration.array_separator) end |
#boolean_get(value) ⇒ Object
29 30 31 |
# File 'lib/sail/value_cast.rb', line 29 def boolean_get(value) value == Sail::ConstantCollection::TRUE end |
#boolean_set(value) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/sail/value_cast.rb', line 79 def boolean_set(value) if value.is_a?(String) check_for_on_or_boolean(value) elsif value.nil? Sail::ConstantCollection::FALSE else value.to_s end end |
#cron_get(value) ⇒ Object
41 42 43 |
# File 'lib/sail/value_cast.rb', line 41 def cron_get(value) Fugit::Cron.new(value).match?(DateTime.now.utc.change(sec: 0)) end |
#cron_set(value) ⇒ Object
107 108 109 |
# File 'lib/sail/value_cast.rb', line 107 def cron_set(value) value end |
#date_get(value) ⇒ Object
21 22 23 |
# File 'lib/sail/value_cast.rb', line 21 def date_get(value) DateTime.parse(value) end |
#date_set(value) ⇒ Object
71 72 73 |
# File 'lib/sail/value_cast.rb', line 71 def date_set(value) value end |
#float_get(value) ⇒ Object
25 26 27 |
# File 'lib/sail/value_cast.rb', line 25 def float_get(value) value.to_f end |
#float_set(value) ⇒ Object
75 76 77 |
# File 'lib/sail/value_cast.rb', line 75 def float_set(value) value.to_f end |
#integer_get(value) ⇒ Object
Section for get value casts
13 14 15 |
# File 'lib/sail/value_cast.rb', line 13 def integer_get(value) value.to_i end |
#integer_set(value) ⇒ Object
Section for set value casts
63 64 65 |
# File 'lib/sail/value_cast.rb', line 63 def integer_set(value) value.to_i end |
#obj_model_get(value) ⇒ Object
45 46 47 |
# File 'lib/sail/value_cast.rb', line 45 def obj_model_get(value) value.constantize end |
#obj_model_set(value) ⇒ Object
103 104 105 |
# File 'lib/sail/value_cast.rb', line 103 def obj_model_set(value) value end |
#range_get(value) ⇒ Object
17 18 19 |
# File 'lib/sail/value_cast.rb', line 17 def range_get(value) value.to_i end |
#range_set(value) ⇒ Object
67 68 69 |
# File 'lib/sail/value_cast.rb', line 67 def range_set(value) value.to_i end |
#string_get(value) ⇒ Object
49 50 51 |
# File 'lib/sail/value_cast.rb', line 49 def string_get(value) value end |
#string_set(value) ⇒ Object
111 112 113 |
# File 'lib/sail/value_cast.rb', line 111 def string_set(value) value end |
#throttle_get(value) ⇒ Object
57 58 59 |
# File 'lib/sail/value_cast.rb', line 57 def throttle_get(value) 100 * rand <= value.to_f end |
#throttle_set(value) ⇒ Object
119 120 121 |
# File 'lib/sail/value_cast.rb', line 119 def throttle_set(value) value end |
#uri_get(value) ⇒ Object
53 54 55 |
# File 'lib/sail/value_cast.rb', line 53 def uri_get(value) URI(value) end |
#uri_set(value) ⇒ Object
115 116 117 |
# File 'lib/sail/value_cast.rb', line 115 def uri_set(value) value end |