Module: Vundabar::ModelHelper::ClassMethods

Defined in:
lib/vundabar/orm/model_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_table_fields(properties) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/vundabar/orm/model_helper.rb', line 46

def build_table_fields(properties)
  all_properties = []
  properties.each do |field_name, constraints|
    column = []
    column << field_name.to_s
    parse_constraint(constraints, column)
    all_properties << column.join(" ")
  end
  all_properties
end

#get_model_object(row) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/vundabar/orm/model_helper.rb', line 75

def get_model_object(row)
  return nil unless row
  model_name = new
  properties.keys.each_with_index do |key, index|
    model_name.send("#{key}=", row[index])
  end
  model_name
end

#make_methodsObject



40
41
42
43
44
# File 'lib/vundabar/orm/model_helper.rb', line 40

def make_methods
  properties.keys.each do |column_name|
    attr_accessor column_name
  end
end

#nullable(value) ⇒ Object



71
72
73
# File 'lib/vundabar/orm/model_helper.rb', line 71

def nullable(value)
  "NOT NULL" unless value
end

#parse_constraint(constraints, column) ⇒ Object



57
58
59
60
61
# File 'lib/vundabar/orm/model_helper.rb', line 57

def parse_constraint(constraints, column)
  constraints.each do |attribute, value|
    column << send(attribute.to_s, value)
  end
end

#primary_key(value) ⇒ Object



67
68
69
# File 'lib/vundabar/orm/model_helper.rb', line 67

def primary_key(value)
  "PRIMARY KEY AUTOINCREMENT" if value
end

#table_nameObject



36
37
38
# File 'lib/vundabar/orm/model_helper.rb', line 36

def table_name
  @table
end

#type(value) ⇒ Object



63
64
65
# File 'lib/vundabar/orm/model_helper.rb', line 63

def type(value)
  value.to_s
end