Class: Skmz::Table

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/skmz/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/skmz/table.rb', line 4

def name
  @name
end

Instance Method Details

#as_jsonObject



6
7
8
# File 'lib/skmz/table.rb', line 6

def as_json
  { name: name, columns: columns.as_json }
end

#columnsObject



10
11
12
13
14
15
16
# File 'lib/skmz/table.rb', line 10

def columns
  @columns ||= [].tap do |columns|
    ActiveRecord::Base.connection.columns(name).each do |column|
      columns << Column.new(name: column.name, type: column.type)
    end
  end
end