Class: Datagrid::Helper::HtmlRow

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/datagrid/helper.rb

Overview

Represents a datagrid row that provides access to column values for the given asset

row = datagrid_row(grid, user)
row.first_name # => "<strong>Bogdan</strong>"
row.grid       # => Grid object
row.asset      # => User object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, grid, asset) ⇒ HtmlRow

:nodoc:



136
137
138
139
140
# File 'lib/datagrid/helper.rb', line 136

def initialize(context, grid, asset) # :nodoc:
  @context = context
  @grid = grid
  @asset = asset
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object (protected)



155
156
157
158
159
160
161
# File 'lib/datagrid/helper.rb', line 155

def method_missing(method, *args, &blk)
  if column = @grid.column_by_name(method)
    get(column)
  else
    super
  end
end

Instance Attribute Details

#assetObject (readonly)

Returns the value of attribute asset.



134
135
136
# File 'lib/datagrid/helper.rb', line 134

def asset
  @asset
end

#gridObject (readonly)

Returns the value of attribute grid.



134
135
136
# File 'lib/datagrid/helper.rb', line 134

def grid
  @grid
end

Instance Method Details

#eachObject

Iterates over all column values that are available in the row



148
149
150
151
152
# File 'lib/datagrid/helper.rb', line 148

def each
  @grid.columns.each do |column|
    yield(get(column))
  end
end

#get(column) ⇒ Object

Return a column value for given column name



143
144
145
# File 'lib/datagrid/helper.rb', line 143

def get(column)
  @context.datagrid_value(@grid, column, @asset)
end