class Matrack::BaseModel
Public Class Methods
create(field_hash)
click to toggle source
# File lib/orm/base_model.rb, line 40 def create(field_hash) passwordify(field_hash) attributes = "#{field_hash.keys}".gsub(/:/, "").gsub(/\[|\]/,"") values = "#{field_hash.values}".gsub(/\[|\]/,"").gsub(/\"/,"'") db_conn.execute "INSERT INTO #{table_name} (#{attributes}) VALUES (#{ values});" end
create_table()
click to toggle source
# File lib/orm/base_model.rb, line 12 def create_table query_string = @@query_string.sub(/,[\s]$/,"") create_table_fields(table_name,query_string) @@query_string = "" end
get_and_set_property(name)
click to toggle source
# File lib/orm/base_model.rb, line 31 def get_and_set_property(name) define_method(name) do instance_variable_get("@#{name}") end define_method("#{name}=") do |value| instance_variable_set("@#{name}", "#{value}") end end
new(hash = {})
click to toggle source
# File lib/orm/base_model.rb, line 3 def initialize(hash = {}) hash.each_pair { |k,v| send("#{k}=", v) } self end
passwordify(field_hash)
click to toggle source
# File lib/orm/base_model.rb, line 48 def passwordify(field_hash) if field_hash.keys.include? :password hashed_pass = password_hash(field_hash[:password]) field_hash[:password] = hashed_pass end field_hash end
property(name, type = "str", desc = {} )
click to toggle source
# File lib/orm/base_model.rb, line 18 def property(name, type = "str", desc = {} ) field_hash = { name => type } if verify_col_type(field_hash) == true db_str = DataUtility.type_mapper(field_hash) @@query_string += query_builder(db_str.keys, db_str.values, desc) @@query_string += ", " unless @@query_string == "" get_and_set_property(name) else puts db_error(verify_col_type(field_hash)) exit end end