class Minicron::Hub::App

Public Class Methods

new() click to toggle source

Called on class initilisation, sets up the database and requires all the application files

Calls superclass method
# File lib/minicron/hub/app.rb, line 72
def initialize
  super

  # Initialize the db
  Minicron::Hub::App.setup_db

  # Load all our model serializers
  Dir[File.dirname(__FILE__) + '/serializers/*.rb'].each do |serializer|
    require serializer
  end

  # Load all our models
  Dir[File.dirname(__FILE__) + '/models/*.rb'].each do |model|
    require model
  end

  # Load all our controllers
  Dir[File.dirname(__FILE__) + '/controllers/**/*.rb'].each do |controller|
    require controller
  end
end
setup_db() click to toggle source

Used to set up the database connection

# File lib/minicron/hub/app.rb, line 95
def self.setup_db
  # Configure the database
  case Minicron.config['database']['type']
  when /mysql|postgresql/
    set :database,
        :adapter => Minicron.config['database']['type'],
        :host => Minicron.config['database']['host'],
        :database => Minicron.config['database']['database'],
        :username => Minicron.config['database']['username'],
        :password => Minicron.config['database']['password']
  when 'sqlite'
    # Calculate the realtive path to the db because sqlite or activerecord is
    # weird and doesn't seem to handle abs paths correctly
    root = Pathname.new(Dir.pwd)
    db = Pathname.new(Minicron::HUB_PATH + '/db')
    db_rel_path = db.relative_path_from(root)

    ActiveRecord::Base.establish_connection(
      :adapter => 'sqlite3',
      :database => "#{db_rel_path}/minicron.sqlite3" # TODO: Allow configuring this but default to this value
    )
  else
    fail Exception, "The database #{Minicron.config['database']['type']} is not supported"
  end

  # Enable ActiveRecord logging if in verbose mode
  ActiveRecord::Base.logger = Minicron.config['verbose'] ? Logger.new(STDOUT) : nil
end