Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/array_extjs.rb

Overview

Part of the ExtJS sequel plugin, this will allow us to use the .to_extjs after .all in the filter chain

Instance Method Summary collapse

Instance Method Details

#to_extjs(id = "id", overwrite_count = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/array_extjs.rb', line 28

def to_extjs(id = "id", overwrite_count = nil)
  data = self
  return '{}' if data.size == 0
  unless overwrite_count
    overwrite_count = data.size
  end

  if block_given?
    data.map! {|rec| yield rec}
  end
  fields = data.first.keys.map{|a| {:name => a}}
  {
    :totalCount => overwrite_count,
    :metaData => {
      :totalProperty => 'totalCount',
      :root => 'result',
      :id => id,
      :fields => fields
    },
    :result => data
  }.to_json
end