forked from ib-ruby/ib-ruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial plumbing for db-backed Models
- Loading branch information
Showing
10 changed files
with
80 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# By requiring this file, we make all IB:Models database-backed ActiveRecord subclasses | ||
|
||
module IB | ||
module DB | ||
|
||
# Establish DB connection and do other plumbing here | ||
def self.connect config | ||
log.warn "Starting Database connection" | ||
ActiveRecord::Base.establish_connection(config) | ||
ActiveRecord::Base.logger = log | ||
#ActiveRecord.colorize_logging = false | ||
|
||
# Get rid of nasty conversion issues | ||
ActiveRecord::Base.default_timezone = :utc | ||
Time.zone = 'UTC' | ||
end | ||
end # module DB | ||
end | ||
|
||
require 'ib-ruby' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
require 'ib-ruby/models/model' | ||
|
||
module IB | ||
module Models | ||
module Contracts | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'ib-ruby/models/model_properties' | ||
|
||
module IB | ||
module Models | ||
|
||
# Base IB Model class derived from ActiveRecord | ||
class DBModel < ActiveRecord::Base | ||
extend ModelProperties | ||
|
||
attr_reader :created_at | ||
|
||
DEFAULT_PROPS = {} | ||
|
||
# If a opts hash is given, keys are taken as attribute names, values as data. | ||
# The model instance fields are then set automatically from the opts Hash. | ||
def initialize(opts={}) | ||
|
||
check_that_match_all props, columns | ||
|
||
error "Argument must be a Hash", :args unless opts.is_a?(Hash) | ||
@created_at = Time.now | ||
|
||
props = self.class::DEFAULT_PROPS.merge(opts) | ||
props.keys.each { |key| self.send("#{key}=", props[key]) } | ||
end | ||
|
||
end # Model | ||
end # module Models | ||
end # module IB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
require 'ib-ruby/models/model' | ||
|
||
module IB | ||
module Models | ||
# This is IB Order execution report. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
puts 'TODO: Run rspec with ActiveRecord version. Use:' | ||
puts '$ rspec -rdb spec' | ||
|
||
require 'ib-ruby/db' | ||
|
||
# Do other DB plumbing, like establishing connection to test DB | ||
# Set RSpec metadata to run AR-specific specs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters