Class: Phlexi::Table::WrappedObject

Inherits:
Object
  • Object
show all
Defined in:
lib/phlexi/table/wrapped_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, index:, display_class:) ⇒ WrappedObject

Returns a new instance of WrappedObject.



8
9
10
11
12
# File 'lib/phlexi/table/wrapped_object.rb', line 8

def initialize(object, index:, display_class:)
  @unwrapped = object
  @index = index
  @display_class = display_class
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



4
5
6
# File 'lib/phlexi/table/wrapped_object.rb', line 4

def index
  @index
end

#unwrappedObject (readonly)

Returns the value of attribute unwrapped.



4
5
6
# File 'lib/phlexi/table/wrapped_object.rb', line 4

def unwrapped
  @unwrapped
end

Instance Method Details

#as_displayObject



22
23
24
# File 'lib/phlexi/table/wrapped_object.rb', line 22

def as_display
  @as_display ||= @display_class.new(unwrapped)
end

#identifierObject



14
15
16
# File 'lib/phlexi/table/wrapped_object.rb', line 14

def identifier
  @identifier ||= Phlexi::Field.object_primary_key(unwrapped) || (index + 1)
end

#value_of(key) ⇒ Object



18
19
20
# File 'lib/phlexi/table/wrapped_object.rb', line 18

def value_of(key)
  @unwrapped.try(key)
end