moargration 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -28,7 +28,7 @@ Worry not, Moargration won't impact your boot time until you actually need it.
28
28
 
29
29
  So it's time to drop some columns.
30
30
 
31
- Knowing that this can bring your app down, and that you normally need to do two deploys to safely dro pcolumns, you can use Moargration to setup the first step for you.
31
+ Knowing that this can bring your app down, and that you normally need to do two deploys to safely drop columns, you can use Moargration to setup the first step for you.
32
32
 
33
33
  Just set an `ENV` var like:
34
34
 
data/lib/moargration.rb CHANGED
@@ -5,8 +5,12 @@ module Moargration
5
5
 
6
6
  def init
7
7
  return unless ignore = ENV["MOARGRATION_IGNORE"]
8
- spec = parse(ignore)
9
- hack_active_record(spec)
8
+ columns_to_ignore = parse(ignore)
9
+ hack_active_record!
10
+ end
11
+
12
+ def columns_to_ignore=(columns)
13
+ @@columns_to_ignore = columns
10
14
  end
11
15
 
12
16
  def columns_to_ignore
@@ -14,20 +18,21 @@ module Moargration
14
18
  end
15
19
 
16
20
  def parse(text)
17
- text.strip.split(" ").inject({}) do |parsed, definition|
21
+ @@columns_to_ignore = text.strip.split(" ").inject({}) do |parsed, definition|
18
22
  table, fields = definition.split(":", 2)
19
23
  parsed[table] = fields.split(",") if fields
20
24
  parsed
21
25
  end
22
26
  end
23
27
 
24
- def hack_active_record(spec)
25
- @@columns_to_ignore = spec
26
-
28
+ def hack_active_record!
27
29
  ActiveRecord::Base.class_eval do
28
- def self.columns
29
- super.reject do |column|
30
- (Moargration.columns_to_ignore[table_name] || []).include?(column.name)
30
+ class << self
31
+ alias :columns_without_moargration :columns
32
+ def columns
33
+ columns_without_moargration.reject do |column|
34
+ (Moargration.columns_to_ignore[table_name] || []).include?(column.name)
35
+ end
31
36
  end
32
37
  end
33
38
  end
data/moargration.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "moargration"
7
- gem.version = "0.0.2"
7
+ gem.version = "0.0.3"
8
8
  gem.authors = ["Pedro Belo"]
9
9
  gem.email = ["pedro@heroku.com"]
10
10
  gem.description = %q{Helping you migrate, MOAR.}
@@ -21,12 +21,12 @@ describe Moargration do
21
21
 
22
22
  describe "hack_active_record" do
23
23
  it "hacks the model to ignore the specified columns" do
24
- Moargration.hack_active_record("samples" => %w( f1 ))
24
+ Moargration.columns_to_ignore = { "samples" => %w( f1 ) }
25
25
  Sample.columns.map(&:name).wont_include("f1")
26
26
  end
27
27
 
28
28
  it "doesn't affect other models" do
29
- Moargration.hack_active_record("samples" => %w( f1 ))
29
+ Moargration.columns_to_ignore = { "samples" => %w( f1 ) }
30
30
  User.columns.map(&:name).must_include("f1")
31
31
  end
32
32
  end
data/test/test_helper.rb CHANGED
@@ -19,4 +19,8 @@ class Sample < ActiveRecord::Base
19
19
  end
20
20
 
21
21
  class User < ActiveRecord::Base
22
- end
22
+ end
23
+
24
+ # enable the hack
25
+ ENV["MOARGRATION_IGNORE"] = ""
26
+ Moargration.hack_active_record!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moargration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: