wd_sinatra_active_record 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # WdSinatraActiveRecord
2
2
 
3
- Some code to avoid reinventing the wheel every time you want to use
4
- ActiveRecord in a WeaselDiesel app backed by Sinatra.
3
+ A Ruby gem to avoid reinventing the wheel every time you want to use
4
+ `ActiveRecord` in a [WeaselDiesel](https://github.com/mattetti/Weasel-Diesel) app backed by Sinatra ([wd_sinatra](https://github.com/mattetti/wd-sinatra)).
5
+
6
+ Use this gem to easily get connected to one or multiple databases and to
7
+ enjoy some of the common ActiveRecord Rake tasks available in Rails.
5
8
 
6
9
 
7
10
  ## Installation
@@ -22,13 +25,18 @@ Or install it yourself as:
22
25
  Don't forget to set a gem dependency for the DB adapter you need.
23
26
  For instance:
24
27
 
25
- activerecord-mysql2-adapter
28
+ mysql2
26
29
 
27
30
 
28
31
  ## Usage
29
32
 
30
33
  Add an ActiveRecord `database.yml` file in your config folder and then require this
31
- gem in your `app.rb` file.
34
+ gem in your `app.rb` file and connect to the DB:
35
+
36
+ require 'wd_sinatra_active_record'
37
+ WdSinatraActiveRecord::DBConnector.set_db_connection
38
+ WdSinatraActiveRecord::DBConnector.connect_to_db unless ENV['DONT_CONNECT']
39
+
32
40
 
33
41
  The DB settings can be accessed via:
34
42
 
@@ -51,7 +59,7 @@ add a new entry to your `database.yml` config file:
51
59
  adapter: mysql2
52
60
  encoding: utf8
53
61
  reconnect: true
54
- database: app_development
62
+ database: secondary_development
55
63
  pool: 5
56
64
  username: root
57
65
  password:
@@ -69,9 +77,21 @@ Then in your `app.rb` after requiring this gem:
69
77
  Then whichever `ActiveRecord` that needs to connect to the secondary DB
70
78
  can inherit from `SecondaryConnection` instead of `ActiveRecord::Base`.
71
79
 
80
+ ## Rake tasks
81
+
82
+ A Rake task file is also provided so you can load ActiveRecord specific
83
+ tasks. To do that, create a new rake file in your lib/tasks folder, load
84
+ `WDSinatra` and the rake task file:
85
+
86
+ ```
87
+ $ echo "require 'wd_sinatra_active_record'
88
+ load WdSinatraActiveRecord.task_path" > lib/tasks/db.rake
89
+ ```
90
+
91
+ The tasks are very basic and mainly copied from Rails, feel free to send
92
+ patches and improvements.
72
93
 
73
- A rake file with some tasks is also available but I won't support that
74
- feature for now.
94
+ (Note: WDSinatra version 1.0.4 or newer required)
75
95
 
76
96
  ## Contributing
77
97
 
@@ -9,7 +9,9 @@ module WdSinatraActiveRecord
9
9
 
10
10
  # Path to the rake task file so it can be loaded as such:
11
11
  # load WdSinatraActiveRecord.task_path
12
- #
12
+ # (Note that the app loaded should have been started using something like:
13
+ # WDSinatra::AppLoader.console(RAKE_APP_ROOT)
14
+ # before loading this rake task.)
13
15
  def self.task_path
14
16
  File.join(File.expand_path(File.dirname(__FILE__), ".."), "wd_sinatra_active_record", "db.rake")
15
17
  end
@@ -70,7 +72,4 @@ module WdSinatraActiveRecord
70
72
 
71
73
  end
72
74
 
73
- DBConnector.set_db_connection
74
- DBConnector.connect_to_db unless ENV['DONT_CONNECT']
75
-
76
75
  end
@@ -1,3 +1,3 @@
1
1
  module WdSinatraActiveRecord
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wd_sinatra_active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: