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

Examples:

row = datagrid_row(grid, user)
row.class      # => Datagrid::Helper::HtmlRow
row.first_name # => "<strong>Bogdan</strong>"
row.grid       # => Datagrid::Base 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)



512
513
514
515
516
517
518
# File 'lib/datagrid/helper.rb', line 512

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.



478
479
480
# File 'lib/datagrid/helper.rb', line 478

def asset
  @asset
end

#gridObject (readonly)

Returns the value of attribute grid.



478
479
480
# File 'lib/datagrid/helper.rb', line 478

def grid
  @grid
end

#optionsObject (readonly)

Returns the value of attribute options.



478
479
480
# File 'lib/datagrid/helper.rb', line 478

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



495
496
497
498
499
# File 'lib/datagrid/helper.rb', line 495

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



489
490
491
# File 'lib/datagrid/helper.rb', line 489

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

#to_sString

Returns HTML row format.

Returns:

  • (String)

    HTML row format



502
503
504
505
506
507
508
# File 'lib/datagrid/helper.rb', line 502

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