Class: Model

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#table_nameObject

Returns the value of attribute table_name.



5
6
7
# File 'lib/atchu/model.rb', line 5

def table_name
  @table_name
end

Class Method Details

.for_table(table_name) ⇒ Object



7
8
9
10
11
# File 'lib/atchu/model.rb', line 7

def self.for_table table_name
  model = Model.new
  model.table_name = table_name
  model
end

Instance Method Details

#class_nameObject



13
14
15
# File 'lib/atchu/model.rb', line 13

def class_name
  table_name.classify
end

#file_nameObject



17
18
19
# File 'lib/atchu/model.rb', line 17

def file_name
  table_name.classify.underscore
end

#primary_keyObject



21
22
23
24
25
26
# File 'lib/atchu/model.rb', line 21

def primary_key
  query = Atchu::Queries.primary_key table_name
  keys = Atchu::Connection.get.select_all(query).rows
  return "" if keys.eql? []
  keys.reduce(:+).map{|x|x.intern}.to_s.gsub("[","").gsub("]","")
end