sinatra-activerecord 1.2.5 → 1.3.0

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
  SHA1:
3
- metadata.gz: 7c133323fecd58b8b5cbc3191b786cb37be8908e
4
- data.tar.gz: a9e18e09f160a989811f63a7d9bbd8def3a2a985
3
+ metadata.gz: 7edc0684bddd8d0f9cc24239a89dc19361301dea
4
+ data.tar.gz: c51d1ade72ed09fda8477a1dc375aa33136eaa8c
5
5
  SHA512:
6
- metadata.gz: 72bfb753f3af935b94b743af3ef7c3306bd145f2791750b1be973472515b7ced8bc68c09ce3f524a5fe1fe59485b6762306f86b130ca84749a4f027d8040d7a9
7
- data.tar.gz: 39421549e92c8d5826fb43022da5519c1f9c16aba7b006db251c0c5072e6167a0a76a1b935de4a30abf7c57071a18bb6b2bb01bf614685dbc9b6eee0c88d192c
6
+ metadata.gz: 8d5eef19d30808bb280a1eb32743e63224f678f2a8c646a5c88629d39e2e071821e4c72b3163263ba80c18fc6475a0f6816786d7822869459b4cc9cb3a18fbcf
7
+ data.tar.gz: 006139024a60db57dbb2967045aee49ef8819981b39599b4c281f7457982284268e740d0463034465795fe263b0d13f3e7d7a885c14f62fd845fbcb16e2fede8
data/README.md CHANGED
@@ -125,7 +125,7 @@ This gem was made in 2009 by Blake Mizerany, creator of Sinatra.
125
125
 
126
126
  ## Social
127
127
 
128
- You can follow me on Twitter, I'm [@m_janko](http://twitter.com/m_janko).
128
+ You can follow me on Twitter, I'm [@jankomarohnic](http://twitter.com/jankomarohnic).
129
129
 
130
130
  ## License
131
131
 
@@ -21,7 +21,10 @@ module Sinatra
21
21
  @database ||= begin
22
22
  ActiveRecord::Base.logger = activerecord_logger
23
23
  ActiveRecord::Base.establish_connection(resolve_spec(database_spec))
24
- ActiveRecord::Base.connection
24
+ begin
25
+ ActiveRecord::Base.connection
26
+ rescue Exception => e
27
+ end
25
28
  ActiveRecord::Base
26
29
  end
27
30
  end
@@ -37,7 +40,10 @@ module Sinatra
37
40
  require 'erb'
38
41
 
39
42
  database_hash = YAML.load(ERB.new(File.read(path)).result) || {}
43
+ ActiveRecord::Base.configurations = database_hash
44
+
40
45
  database_hash = database_hash[environment.to_s] if database_hash[environment.to_s]
46
+
41
47
  set :database, database_hash
42
48
  end
43
49
  end
@@ -6,6 +6,32 @@ module Sinatra
6
6
  module ActiveRecordTasks
7
7
  extend self
8
8
 
9
+ def create
10
+ silence_activerecord do
11
+ ActiveRecord::Tasks::DatabaseTasks.create(config)
12
+ end
13
+ end
14
+
15
+ def drop
16
+ silence_activerecord do
17
+ ActiveRecord::Tasks::DatabaseTasks.drop(config)
18
+ end
19
+ end
20
+
21
+ def seed
22
+ silence_activerecord do
23
+ load("db/seeds.rb")
24
+ end
25
+ end
26
+
27
+ def setup
28
+ silence_activerecord do
29
+ create()
30
+ load_schema()
31
+ seed()
32
+ end
33
+ end
34
+
9
35
  def create_migration(migration_name, version = nil)
10
36
  raise "No NAME specified. Example usage: `rake db:create_migration NAME=create_users`" if migration_name.nil?
11
37
 
@@ -58,6 +84,10 @@ module Sinatra
58
84
 
59
85
  private
60
86
 
87
+ def config
88
+ ActiveRecord::Base.configurations[Sinatra::Application.environment.to_s]
89
+ end
90
+
61
91
  def migrations_dir
62
92
  ActiveRecord::Migrator.migrations_path
63
93
  end
@@ -1,6 +1,26 @@
1
1
  require 'rake'
2
2
 
3
3
  namespace :db do
4
+ desc "create the database from config/database.yml from the current Sinatra env"
5
+ task :create do
6
+ Sinatra::ActiveRecordTasks.create()
7
+ end
8
+
9
+ desc "drops the data from config/database.yml from the current Sinatra env"
10
+ task :drop do
11
+ Sinatra::ActiveRecordTasks.drop()
12
+ end
13
+
14
+ desc "load the seed data from db/seeds.rb"
15
+ task :seed do
16
+ Sinatra::ActiveRecordTasks.seed()
17
+ end
18
+
19
+ desc "create the database and load the schema"
20
+ task :setup do
21
+ Sinatra::ActiveRecordTasks.setup()
22
+ end
23
+
4
24
  desc "create an ActiveRecord migration"
5
25
  task :create_migration do
6
26
  Sinatra::ActiveRecordTasks.create_migration(ENV["NAME"], ENV["VERSION"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Mizerany
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-04 00:00:00.000000000 Z
12
+ date: 2014-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra