lincoln 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lincoln.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # Purpose
2
+
3
+ Have you ever needed to ignore a database column in ActiveRecord? For example, when you
4
+ have a table with hundreds of millions of rows and you want to delete or rename a column
5
+ with no down time. In order to pull that off you need to ignore the column on master,
6
+ while you remove it on a slave. Once the column is deleted, you start replication to catch
7
+ up to master before promoting the slave to master. Without a way to ignore a column on
8
+ master you will get error when replicating.
9
+
10
+ ## Example
11
+
12
+ class Person < ActiveRecord::Base
13
+ attr_ignore :last_name, :first_name
14
+ end
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'bundler'
4
+
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ require "rspec/core/rake_task"
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.pattern = 'spec/**/*_spec.rb'
10
+ end
11
+
12
+ task :default => :spec
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec" }
@@ -0,0 +1,40 @@
1
+ module Lincoln
2
+ module AttrIgnore
3
+ def self.included(base) # :nodoc:
4
+ base.send(:extend, ClassMethods)
5
+ base.send(:include, InstanceMethods)
6
+
7
+ class << base
8
+ alias_method :columns_with_attr_ignore, :columns
9
+ alias_method :columns, :columns_without_attr_ignore
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+ # Attributes listed as ignore will be completely hidden from active record. They
15
+ # will not show up in create, update, delete, or queries. Read and write methods
16
+ # will not be generated as well.
17
+ def attr_ignore(*attributes)
18
+ write_inheritable_attribute(:attr_ignore, Set.new(attributes.map { |a| a.to_s }) + (ignore_attributes || []))
19
+ end
20
+
21
+ # Returns an array of all the attributes that have been specified as ignore.
22
+ def ignore_attributes
23
+ read_inheritable_attribute(:attr_ignore) || []
24
+ end
25
+
26
+ # Return the list of columns taking into account the attr_ignore attribute.
27
+ def columns_without_attr_ignore
28
+ unless defined?(@columns) && @columns
29
+ @columns = columns_with_attr_ignore
30
+ @columns.reject! { |column| ignore_attributes.include?(column.name) }
31
+ end
32
+
33
+ @columns
34
+ end
35
+ end
36
+
37
+ module InstanceMethods
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Lincoln
2
+ VERSION = "0.0.1"
3
+ end
data/lib/lincoln.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'active_record'
2
+ require File.dirname(__FILE__) + "/lincoln/attr_ignore"
3
+
4
+ ActiveRecord::Base.send(:include, Lincoln::AttrIgnore)
data/lincoln.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "lincoln/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "lincoln"
7
+ s.version = Lincoln::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ben Curren"]
10
+ s.email = ["ben@outright.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Extensions to ActiveRecord to make it easier to run at scale.}
13
+ s.description = %q{Extensions to ActiveRecord to make it easier to run at scale.}
14
+
15
+ # s.rubyforge_project = "lincoln"
16
+
17
+ s.required_ruby_version = '>= 1.8.7'
18
+ s.required_rubygems_version = ">= 1.3.6"
19
+
20
+ s.add_dependency('activerecord', '~> 3.0')
21
+ s.add_development_dependency "rspec", "~> 2.0"
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
27
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ describe "attr_reader" do
4
+ it "has ignore_attributes" do
5
+ MyModel.ignore_attributes.should == Set.new(["column1", "column2"])
6
+ end
7
+
8
+ it "ignores columns specified in ignore_attr" do
9
+ column_names = MyModel.columns.collect { |column| column.name }
10
+ column_names.should == ["column3"]
11
+ end
12
+ end
13
+
14
+ class MyModel < ActiveRecord::Base
15
+ attr_ignore :column1, :column2
16
+ end
data/spec/spec.opts ADDED
File without changes
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'rspec'
5
+ require 'rspec/autorun'
6
+
7
+ # Need to override ActivreRecord::Base before we require lincoln
8
+ # for testing
9
+ require 'active_record'
10
+ class ActiveRecord::Base
11
+ def self.columns
12
+ [ActiveRecord::ConnectionAdapters::Column.new("column1", nil, "string", false),
13
+ ActiveRecord::ConnectionAdapters::Column.new("column2", nil, "string", false),
14
+ ActiveRecord::ConnectionAdapters::Column.new("column3", nil, "string", false)]
15
+ end
16
+ end
17
+ require 'lincoln'
18
+
19
+ RSpec.configure do |config|
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lincoln
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ben Curren
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-05 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activerecord
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ version: "3.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 2
47
+ - 0
48
+ version: "2.0"
49
+ type: :development
50
+ version_requirements: *id002
51
+ description: Extensions to ActiveRecord to make it easier to run at scale.
52
+ email:
53
+ - ben@outright.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - .gitignore
62
+ - Gemfile
63
+ - README.md
64
+ - Rakefile
65
+ - autotest/discover.rb
66
+ - lib/lincoln.rb
67
+ - lib/lincoln/attr_ignore.rb
68
+ - lib/lincoln/version.rb
69
+ - lincoln.gemspec
70
+ - spec/attr_ignore_spec.rb
71
+ - spec/spec.opts
72
+ - spec/spec_helper.rb
73
+ has_rdoc: true
74
+ homepage: ""
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 57
88
+ segments:
89
+ - 1
90
+ - 8
91
+ - 7
92
+ version: 1.8.7
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 23
99
+ segments:
100
+ - 1
101
+ - 3
102
+ - 6
103
+ version: 1.3.6
104
+ requirements: []
105
+
106
+ rubyforge_project:
107
+ rubygems_version: 1.5.0
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Extensions to ActiveRecord to make it easier to run at scale.
111
+ test_files:
112
+ - spec/attr_ignore_spec.rb
113
+ - spec/spec.opts
114
+ - spec/spec_helper.rb