Module: Hirb::Views::Rails

Defined in:
lib/hirb/views/rails.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#active_record__base_view(obj) ⇒ Object



2
3
4
# File 'lib/hirb/views/rails.rb', line 2

def active_record__base_view(obj)
  {:fields=>get_active_record_fields(obj)}
end

#get_active_record_fields(obj) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/hirb/views/rails.rb', line 6

def get_active_record_fields(obj)
  fields = obj.class.column_names.map {|e| e.to_sym }
  # if query used select
  if obj.attributes.keys.compact.sort != obj.class.column_names.sort
    selected_columns = obj.attributes.keys.compact
    sorted_columns = obj.class.column_names.dup.delete_if {|e| !selected_columns.include?(e) }
    sorted_columns += (selected_columns - sorted_columns)
    fields = sorted_columns.map {|e| e.to_sym}
  end
  fields
end