snapshots 0.0.1 → 0.0.2

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.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/snapshots/app.rb +24 -7
  3. data/snapshots.gemspec +1 -1
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/snapshots/app.rb CHANGED
@@ -7,9 +7,14 @@ module Snapshots
7
7
  :banner => 'rails_root',
8
8
  :group => 'Global'
9
9
 
10
+ class_option :environment, :default => (ENV['RAILS_ENV'] || 'development'), :type => :string,
11
+ :desc => 'Rails environment',
12
+ :banner => 'env',
13
+ :group => 'Global'
14
+
10
15
  desc 'list', 'List all snapshots for a rails app.'
11
16
  def list
12
- goto_rails(self.options.app) do
17
+ goto_rails do
13
18
 
14
19
  Snapshots.find.each do |snapshot|
15
20
  snapshot =~ /snapshot_(\d+)\.rb$/
@@ -22,7 +27,7 @@ module Snapshots
22
27
 
23
28
  desc 'dump', 'Make a new snapshot.'
24
29
  def dump
25
- goto_rails(self.options.app) do
30
+ goto_rails do
26
31
  load_environment!
27
32
 
28
33
  begin
@@ -38,7 +43,7 @@ module Snapshots
38
43
 
39
44
  desc 'load VERSION', 'Restore a snapshot.'
40
45
  def load(version)
41
- goto_rails(self.options.app) do
46
+ goto_rails do
42
47
  load_environment!
43
48
 
44
49
  begin
@@ -54,7 +59,7 @@ module Snapshots
54
59
 
55
60
  desc 'install', 'Install rake tasks in rails app.'
56
61
  def install
57
- goto_rails(self.options.app) do
62
+ goto_rails do
58
63
  File.open('lib/tasks/snapshots.rake', 'w+') do |f|
59
64
  f.write <<-EOR
60
65
  begin
@@ -72,11 +77,16 @@ EOR
72
77
  private
73
78
 
74
79
  def load_environment!
80
+ Object.const_set('RAILS_ROOT', rails_root) rescue nil
81
+ ENV['RAILS_ENV'] = environment
75
82
  $rails_rake_task = true
76
83
  require(File.join(RAILS_ROOT, 'config', 'environment'))
77
84
  end
78
85
 
79
- def goto_rails(root_path, &proc)
86
+ def rails_root
87
+ return @rails_root if @rails_root
88
+
89
+ root_path = self.options.app
80
90
  root_path = File.expand_path(root_path)
81
91
 
82
92
  unless File.directory?(root_path) and File.file?(File.join(root_path, 'config', 'environment.rb'))
@@ -84,8 +94,15 @@ EOR
84
94
  exit(1)
85
95
  end
86
96
 
87
- Object.const_set('RAILS_ROOT', root_path)
88
- Dir.chdir(root_path, &proc)
97
+ @rails_root = root_path
98
+ end
99
+
100
+ def environment
101
+ self.options.environment
102
+ end
103
+
104
+ def goto_rails(&proc)
105
+ Dir.chdir(rails_root, &proc)
89
106
  end
90
107
 
91
108
  end
data/snapshots.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{snapshots}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Simon Menke"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapshots
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Menke