Class: MachineShop::Database
- Inherits:
-
Configuration
- Object
- Configuration
- MachineShop::Database
- Defined in:
- lib/machineshop/database.rb
Overview
require ‘machineshop/configuration’
Instance Attribute Summary collapse
-
#con ⇒ Object
Returns the value of attribute con.
-
#db_connected ⇒ Object
Returns the value of attribute db_connected.
-
#rs ⇒ Object
Returns the value of attribute rs.
Attributes inherited from Configuration
#base_version, #custom_endpoints_cache_time, #db_host, #db_name, #db_password, #db_username, #enable_caching, #expiry_time
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Database
constructor
A new instance of Database.
Constructor Details
#initialize ⇒ Database
Returns a new instance of Database.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/machineshop/database.rb', line 15 def initialize() # @db_connected=true begin ActiveRecord::Base.establish_connection( adapter: 'mysql', # or 'postgresql' or 'sqlite3' host: MachineShop.configuration.db_host, database: MachineShop.configuration.db_name, username: MachineShop.configuration.db_username, password: MachineShop.configuration.db_password, ) begin load 'machineshop/models/schema.rb' rescue Mysql::Error => e # raise SchemaError.new(e.message) rescue StandardError => e # raise SchemaError.new(e.message) end rescue Mysql::Error =>e raise DatabaseError.new("Mysql error ") rescue StandardError =>e raise DatabaseError.new("Database Error #1") rescue Exception => e # @db_connected=false raise DatabaseError.new("Connection to Database refused") # load schema file end end |
Instance Attribute Details
#con ⇒ Object
Returns the value of attribute con.
13 14 15 |
# File 'lib/machineshop/database.rb', line 13 def con @con end |
#db_connected ⇒ Object
Returns the value of attribute db_connected.
13 14 15 |
# File 'lib/machineshop/database.rb', line 13 def db_connected @db_connected end |
#rs ⇒ Object
Returns the value of attribute rs.
13 14 15 |
# File 'lib/machineshop/database.rb', line 13 def rs @rs end |
Class Method Details
.serialize_data(data) ⇒ Object
52 53 54 |
# File 'lib/machineshop/database.rb', line 52 def self.serialize_data(data) Marshal.dump(data) end |