Class: Datagrid::Helper::HtmlRow

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

Overview

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

Examples:

row = datagrid_row(grid, user)
row.class      # => Datagrid::Helper::HtmlRow
row.first_name # => "<strong>Bogdan</strong>"
row.grid       # => Grid object
row.asset      # => User object
row.each do |value|
  puts value
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



148
149
150
151
152
153
154
# File 'lib/datagrid/renderer.rb', line 148

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.



116
117
118
# File 'lib/datagrid/renderer.rb', line 116

def asset
  @asset
end

#gridObject (readonly)

Returns the value of attribute grid.



116
117
118
# File 'lib/datagrid/renderer.rb', line 116

def grid
  @grid
end

#optionsObject (readonly)

Returns the value of attribute options.



116
117
118
# File 'lib/datagrid/renderer.rb', line 116

def options
  @options
end

Instance Method Details

#each(&block) ⇒ Object

Iterates over all column values that are available in the row param block [Proc] column value iterator



133
134
135
136
137
# File 'lib/datagrid/renderer.rb', line 133

def each(&block)
  (@options[:columns] || @grid.html_columns).each do |column|
    block.call(get(column))
  end
end

#get(column) ⇒ Object

Returns a column value for given column name.

Returns:

  • (Object)

    a column value for given column name



127
128
129
# File 'lib/datagrid/renderer.rb', line 127

def get(column)
  @renderer.format_value(@grid, column, @asset)
end

#to_sObject



139
140
141
142
143
144
145
# File 'lib/datagrid/renderer.rb', line 139

def to_s
  @renderer.send(:_render_partial, 'row', options[:partials], {
    :grid => grid,
    :options => options,
    :asset => asset
  })
end