Class: Slim::Wrapper Private

Inherits:
Object
  • Object
show all
Defined in:
lib/slim/wrapper.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

For logic-less mode, objects can be encased in the Wrapper class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, parent = nil) ⇒ Wrapper

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Wrapper.



7
8
9
# File 'lib/slim/wrapper.rb', line 7

def initialize(value, parent = nil)
  @value, @parent = value, parent
end

Instance Attribute Details

#parentObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



5
6
7
# File 'lib/slim/wrapper.rb', line 5

def parent
  @parent
end

#valueObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



5
6
7
# File 'lib/slim/wrapper.rb', line 5

def value
  @value
end

Instance Method Details

#[](name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

To find the reference, first check for standard method access by using respond_to?.

If not found, check to see if the value is a hash and if the the name is a key on the hash.

Not a hash, or not a key on the hash, then check to see if there is an instance variable with the name.

If the instance variable doesn’t exist and there is a parent object, go through the same steps on the parent object. This is useful when you are iterating over objects.



23
24
25
26
27
28
29
30
31
# File 'lib/slim/wrapper.rb', line 23

def [](name)
  return wrap(value.send(name)) if value.respond_to?(name)
  if value.respond_to?(:has_key?)
    return wrap(value[name.to_sym]) if value.has_key?(name.to_sym)
    return wrap(value[name.to_s]) if value.has_key?(name.to_s)
  end
  return wrap(value.instance_variable_get("@#{name}")) if value.instance_variable_defined?("@#{name}")
  parent[name] if parent
end

#empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Empty objects must appear empty for inverted sections

Returns:

  • (Boolean)


34
35
36
# File 'lib/slim/wrapper.rb', line 34

def empty?
  value.respond_to?(:empty) && value.empty?
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Used for output



39
40
41
# File 'lib/slim/wrapper.rb', line 39

def to_s
  value.to_s
end