active_record_tasks 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d2b93b41cf93f54078729e5472c54114e5cc484
4
- data.tar.gz: 8d5f738139366738f90c1f61e8e142d52ae44175
3
+ metadata.gz: 6ac78a2d5bb04d804ca7c9bfaf8b151ccbbe45f2
4
+ data.tar.gz: 4d1e78b507ca0451d47ba19c2a51095165114da0
5
5
  SHA512:
6
- metadata.gz: 3e5257235b7390f4620116263a2c069b976e0312ec46afb1043eaf74b9a9255344657540fb22f1c55b8429183856e420945f747919bd4070d86bbbebc9c1748c
7
- data.tar.gz: 115e91a69a09e22bb1f2840f00618569b633b8d7d3493e1b133375627f203957b73a18f297dd449279b7a99b00e029ce16cef9631005a9ec36116713a0b28e04
6
+ metadata.gz: 4517445375502c934a17d3aeccbec8f873cbae89798e10c5515047f617e1c1e24b6a902e259ee3bc8e54158fedcb5694e938efae9c16d0854135017130e8aa58
7
+ data.tar.gz: a2fc3b58b0e8e578afb79c0c46264423175351b8785edf96c3f16c64068af4d7f3ea4c8721fa21491d9db20b695323c992804760d8717dea68f8a6fcf54bd39d
data/README.md CHANGED
@@ -6,7 +6,7 @@ The easiest way to get started with ActiveRecord 4 in a non-rails project.
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'active_record_tasks', '~> 1.0.2'
9
+ gem 'active_record_tasks', '~> 1.0.3'
10
10
 
11
11
  And then execute:
12
12
 
@@ -16,7 +16,7 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install active_record_tasks
18
18
 
19
- ## Usage
19
+ ## Getting Started
20
20
 
21
21
  Include the following in your `Rakefile`:
22
22
 
@@ -34,7 +34,17 @@ end
34
34
  ActiveRecordTasks.load_tasks
35
35
  ```
36
36
 
37
- Now you have access to all the ActiveRecord db tasks!
37
+ If this is a new project:
38
+
39
+ ```
40
+ $ rake generate:init
41
+ ```
42
+
43
+ will generate your configured db directory (if it doesn't exist).
44
+
45
+ ## Usage
46
+
47
+ ActiveRecordTasks gives you access to all the ActiveRecord db tasks:
38
48
 
39
49
  ```
40
50
  $ rake -T
@@ -55,7 +65,7 @@ rake db:version # Retrieves the current schema version number
55
65
  ...
56
66
  ```
57
67
 
58
- ## Basic Generate Migration
68
+ ### Generating Migrations
59
69
 
60
70
  This gem provides a bonus `generate:migration` task. It's very basic, but it works:
61
71
 
data/Rakefile CHANGED
@@ -6,6 +6,6 @@ require 'bundler/gem_tasks'
6
6
  require 'active_record_tasks'
7
7
 
8
8
  ActiveRecordTasks.configure do |config|
9
- config.db_dir = './fixtures/db1'
9
+ config.db_dir = './fixtures/db3'
10
10
  end
11
11
  ActiveRecordTasks.load_tasks
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "activerecord", ">= 4.0"
22
22
  spec.add_dependency "rake"
23
+ spec.add_dependency "rainbow"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.3"
25
26
  end
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: rspec_test
@@ -30,6 +30,50 @@ end
30
30
 
31
31
  # Simple migration generator
32
32
  namespace :generate do
33
+ require 'rainbow/ext/string'
34
+ def puts_exists(subject)
35
+ print "\texists\t".color(:cyan)
36
+ puts subject
37
+ end
38
+ def puts_create(subject)
39
+ print "\tcreate\t".color(:green)
40
+ puts subject
41
+ end
42
+
43
+ desc "Generates a new db directory"
44
+ task :init do
45
+ # Create (configured) db and db/migrate directory
46
+ if File.directory?(config.db_dir)
47
+ puts_exists config.db_dir
48
+ else
49
+ puts_create config.db_dir
50
+ Dir.mkdir(config.db_dir)
51
+ end
52
+
53
+ migrate_dir = "#{config.db_dir}/migrate"
54
+ if File.directory?(migrate_dir)
55
+ puts_exists migrate_dir
56
+ else
57
+ puts_create migrate_dir
58
+ Dir.mkdir(migrate_dir)
59
+ end
60
+
61
+ # Create basic config.yml file
62
+ db_config_path = config.db_config_path
63
+ if File.exist?(db_config_path)
64
+ puts_exists db_config_path
65
+ else
66
+ puts_create db_config_path
67
+ project_dir = File.basename(Dir.pwd)
68
+ template = File.read File.join(File.dirname(__FILE__), 'templates/config.erb')
69
+ result = ERB.new(template).result(binding)
70
+
71
+ File.write(db_config_path, result)
72
+ end
73
+
74
+ end
75
+
76
+
33
77
  desc "Creates a new migration file with the specified name"
34
78
  task :migration => :environment do |t, args|
35
79
  name = args[:name] || ENV['name']
@@ -48,10 +92,16 @@ namespace :generate do
48
92
  template = File.read File.join(File.dirname(__FILE__), 'templates/migrate.erb')
49
93
  result = ERB.new(template).result(binding)
50
94
 
95
+ # Ensure migrate directory exists
96
+ migrate_dir = "#{config.db_dir}/migrate"
97
+ unless File.directory?(migrate_dir)
98
+ Dir.mkdir(migrate_dir)
99
+ end
100
+
51
101
  timestamp = Time.now.strftime("%Y%m%d%H%M%S")
52
- migration_path = File.join("#{config.db_dir}/migrate/#{timestamp}_#{name.underscore}.rb")
102
+ migration_path = File.join(migrate_dir, "#{timestamp}_#{name.underscore}.rb")
53
103
  File.write(migration_path, result)
54
- puts " create #{migration_path}"
104
+ puts_create migration_path
55
105
  end
56
106
  end
57
107
 
@@ -0,0 +1,11 @@
1
+ development:
2
+ adapter: postgresql
3
+ database: <%= project_dir %>_dev
4
+ pool: 5
5
+ timeout: 5000
6
+
7
+ test:
8
+ adapter: postgresql
9
+ database: <%= project_dir %>_test
10
+ pool: 5
11
+ timeout: 5000
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordTasks
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilbert
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,8 +81,10 @@ files:
67
81
  - active_record_tasks.gemspec
68
82
  - fixtures/db1/config.yml
69
83
  - fixtures/db1/migrate/.gitkeep
84
+ - fixtures/db2/config.yml
70
85
  - lib/active_record_tasks.rb
71
86
  - lib/active_record_tasks/tasks.rb
87
+ - lib/active_record_tasks/templates/config.erb
72
88
  - lib/active_record_tasks/templates/migrate.erb
73
89
  - lib/active_record_tasks/version.rb
74
90
  homepage: https://github.com/makersquare/active_record_tasks