Class: Liquid::Drop::Str

Inherits:
String
  • Object
show all
Defined in:
lib/liquid/drop/str.rb,
lib/liquid/drop/str/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#context=(value) ⇒ Object (writeonly)

Sets the attribute context

Parameters:

  • value

    the value to set the attribute context to.



4
5
6
# File 'lib/liquid/drop/str.rb', line 4

def context=(value)
  @context = value
end

Class Method Details

.invokable?(m) ⇒ Boolean

– This is ‘.invokable?` when it comes to Liquids own

source.  We change it to discourage users from overriding
the methods because this is a wrapper.

Returns:

  • (Boolean)


50
51
52
# File 'lib/liquid/drop/str.rb', line 50

def self.invokable?(m)
  invokable_methods.include?(m.to_s)
end

.invokable_methodsObject



55
56
57
58
59
# File 'lib/liquid/drop/str.rb', line 55

def self.invokable_methods
  @invokable_methods ||= begin
    Set.new(good.map(&:to_s))
  end
end

Instance Method Details

#invoke_drop(m) ⇒ Object Also known as: []

– Invokes a method on the drop if it exist and is

not blacklisted.  We blacklist most methods by
default if it's on `String`, `Array`, `Enumberable`
`Hash` and this own class...



31
32
33
# File 'lib/liquid/drop/str.rb', line 31

def invoke_drop(m)
  self.class.invokable?(m) ? send(m) : liquid_method_missing(m)
end

#is_a?(v) ⇒ Boolean Also known as: ===

– Mocks ‘#is_a?` so that Liquid thinks we are a

drop. If it ever decides to ask.

Returns:

  • (Boolean)


10
11
12
# File 'lib/liquid/drop/str.rb', line 10

def is_a?(v)
  v == Liquid::Drop || super(v)
end

#key?(_) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/liquid/drop/str.rb', line 41

def key?(_)
  true
end

#liquid_method_missing(method) ⇒ Object

– Liquid version of ‘method_missing`, except it only

works for Liquid and only takes the method.

Returns:

  • Error.

Raises:

  • (Liquid::UndefinedDropMethod)


19
20
21
22
23
# File 'lib/liquid/drop/str.rb', line 19

def liquid_method_missing(method)
  return nil unless @context && @context.strict_variables
  raise Liquid::UndefinedDropMethod, \
    "undefined method #{method}"
end

#to_liquidObject



36
37
38
# File 'lib/liquid/drop/str.rb', line 36

def to_liquid
  self
end