Class: Webhookdb::Liquid::Liquification

Inherits:
Object
  • Object
show all
Defined in:
lib/webhookdb/liquid/liquification.rb

Overview

Liquification provides a to_liquid method that returns a wrapped object, so that any object can be used in a liquid template (normally only things like basic types, and objects with to_liquid, can be used in templates). This allows us to use Liquid filters for rendering custom types, rather than presenters. We prefer filters because it keeps display logic in the view, rather than the backing ‘template’ having to choose the presenter.

Instance Method Summary collapse

Constructor Details

#initialize(wrapped) ⇒ Liquification

Returns a new instance of Liquification.



11
12
13
# File 'lib/webhookdb/liquid/liquification.rb', line 11

def initialize(wrapped)
  @wrapped = wrapped
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m) ⇒ Object



15
16
17
# File 'lib/webhookdb/liquid/liquification.rb', line 15

def method_missing(m, *, &)
  return @wrapped.respond_to?(m) ? @wrapped.send(m, *, &) : super
end

Instance Method Details

#respond_to_missing?(m, include_private: false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/webhookdb/liquid/liquification.rb', line 19

def respond_to_missing?(m, include_private: false)
  return super || @wrapped.respond_to?(m)
end

#to_liquidObject



23
24
25
# File 'lib/webhookdb/liquid/liquification.rb', line 23

def to_liquid
  return self
end