Class: ActsAsCalculator::CastLiquidValue
- Inherits:
-
Object
- Object
- ActsAsCalculator::CastLiquidValue
- Defined in:
- lib/acts_as_calculator/cast_liquid_value.rb
Overview
The one gate into a template's render context. Liquid only dispatches methods on
Liquid::Drops and hash-likes, so the sandbox holds exactly as long as nothing else
is assigned — an allowlist here is what makes that a property of the code rather than
a habit every caller has to remember.
Constant Summary collapse
- PASS_THROUGH =
[ ::NilClass, ::TrueClass, ::FalseClass, ::String, ::Integer, ::Float, ::Date, ::Time, ::Liquid::Drop ].freeze
- TIME_WITH_ZONE =
The one class a Rails host will hit that is neither a Date nor a Time, since
record.created_atis the obvious thing to pass. Matched by name because the core layer must stay loadable without ActiveSupport, and named rather than duck-typed so this stays an allowlist —respond_to?(:strftime)would admit anything. "ActiveSupport::TimeWithZone"
Class Method Summary collapse
Class Method Details
.call(value) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/acts_as_calculator/cast_liquid_value.rb', line 18 def self.call(value) case value when ::Hash then value.to_h { |key, nested| [key.to_s, call(nested)] } when ::Array then value.map { |nested| call(nested) } when Result then ResultDrop.new(value) else scalar(value) end end |