activerecord-shipworks 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 532db6f8480f5e9e2df810f93d075db45457d4131f7c950318ef9a7330072cc7
4
- data.tar.gz: 9a0df08645f7e8c8ddaebe5922bb338a78bd4aa491c5f118368d0c6eda2f9a5c
3
+ metadata.gz: 2e7e874df3cf5ae84ec5850101507851ec010c0fe7a1c8e212845099e8cbaad8
4
+ data.tar.gz: dc1b3b8154af1efb5f8e92c3e030a107f7fa10282817dd0e609abb3ab66fb617
5
5
  SHA512:
6
- metadata.gz: 5cf7b128880e34d040bc17c06f7d35774a9818c92b0b348e74c0bf8ba999e44e284408eda4632385735b1d2fa02d351cb2eadd10f5ddcdd4709908287f24814c
7
- data.tar.gz: 555d1e22e4f49a23f8681789caefcc5c8e9ec47ac4ba765d30f9dd8629112a3ed9284ea4b6edfb2cdc41ebabb3b659ce92de8300b482555e05d28f7a65127f07
6
+ metadata.gz: 90ee44646ed1e8fcbffef7f826f9bdcc63cbec9e65d6db2b4f5c00016350047f7f4575f17f8951c446dcef71dd47c88547c43766dc1b15f1cd201a3ab27a4d72
7
+ data.tar.gz: 29d7f3db9f76912fcf7f769fc2e7f0c95cdae2942231a6519d3c10a62cd484bfa76257ff3280615d341f4ea0ef86c666d04df676b62b0982131421a200f4cf07
data/README.md CHANGED
@@ -13,12 +13,7 @@ And then execute:
13
13
  $ bundle
14
14
  ```
15
15
 
16
- If you are connecting Shipworks as a second database, add Shipworks database configuration to a separate file, e.g. `config/shipworks_database.yml`, and add initializer `config/initializers/shipworks_db.rb` to set the `SHIPWORKS_DB` constant:
17
-
18
- ```ruby
19
- # config/initializers/shipworks_db.rb
20
- SHIPWORKS_DB = YAML.load(ERB.new(IO.read(File.join(Rails.root, "config", "shipworks_database.yml"))).result)[Rails.env.to_s]
21
- ```
16
+ ActiveRecord Shipworks uses the main database connection by default. However, in most of the cases, you want to connect to Shipworks as a second database connection. You could do that by setting `ENV['SHIPWORKS_DATABASE_URL]` by using a configuration file called `config/shipworks_database.yml`.
22
17
 
23
18
  ## Usage
24
19
  You may query Shipworks data as any other ActiveRecord class:
@@ -1,5 +1,5 @@
1
1
  module Shipworks
2
- class OrderCharge < Shipworks::ApplicationRecord
2
+ class OrderCharge < ShipworksRecord
3
3
  belongs_to :order, foreign_key: 'OrderID'
4
4
  end
5
5
  end
@@ -1,7 +1,11 @@
1
1
  module Shipworks
2
2
  class ShipworksRecord < ActiveRecord::Base
3
3
  self.abstract_class = true
4
- establish_connection SHIPWORKS_DB if defined? SHIPWORKS_DB
4
+ shipworks_db = ENV['SHIPWORKS_DATABASE_URL']
5
+ if shipworks_db.nil? && File.exist?(File.join(Rails.root, "config", "shipworks_database.yml"))
6
+ shipworks_db = YAML.load(ERB.new(IO.read(File.join(Rails.root, "config", "shipworks_database.yml"))).result)[Rails.env.to_s]
7
+ end
8
+ establish_connection shipworks_db if shipworks_db.present?
5
9
 
6
10
  def self.table_name
7
11
  self.name.split('::').last
@@ -1,3 +1,3 @@
1
1
  module Shipworks
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-shipworks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Wu