activerecord-table_version 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source :rubygems
2
2
 
3
3
  case ("rails%s" % ENV.fetch("RAILS_VERSION", "3")).to_sym
4
- when :rails3; gem 'activerecord', '~> 3.0.3'
5
- when :rails2; gem 'activerecord', '~> 2.3.10'
4
+ when :rails3; gem 'activerecord', '~> 3.0.5'
5
+ when :rails2; gem 'activerecord', '~> 2.3.11'
6
6
  end
7
7
 
8
8
  group :development do
@@ -1,17 +1,17 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.0.3)
5
- activesupport (= 3.0.3)
4
+ activemodel (3.0.5)
5
+ activesupport (= 3.0.5)
6
6
  builder (~> 2.1.2)
7
7
  i18n (~> 0.4)
8
- activerecord (3.0.3)
9
- activemodel (= 3.0.3)
10
- activesupport (= 3.0.3)
8
+ activerecord (3.0.5)
9
+ activemodel (= 3.0.5)
10
+ activesupport (= 3.0.5)
11
11
  arel (~> 2.0.2)
12
12
  tzinfo (~> 0.3.23)
13
- activesupport (3.0.3)
14
- arel (2.0.7)
13
+ activesupport (3.0.5)
14
+ arel (2.0.9)
15
15
  builder (2.1.2)
16
16
  diff-lcs (1.1.2)
17
17
  i18n (0.5.0)
@@ -30,7 +30,7 @@ PLATFORMS
30
30
  ruby
31
31
 
32
32
  DEPENDENCIES
33
- activerecord (~> 3.0.3)
33
+ activerecord (~> 3.0.5)
34
34
  bundler (~> 1.0.0)
35
35
  rake (~> 0.8.7)
36
36
  rspec (= 2.1.0)
@@ -0,0 +1,57 @@
1
+ h1. ActiveRecord::TableVersion
2
+
3
+ Makes setting table name versions simple.
4
+
5
+ h2. Example
6
+
7
+ <pre><code>
8
+ class Model < ActiveRecord::Base
9
+ set_table_name "foos"
10
+ set_table_version "2011_01_25"
11
+ end
12
+
13
+ Model.table_name #=> "foos_2011_01_25"
14
+ </code></pre>
15
+
16
+ h2. Installation
17
+
18
+ Depends on ActiveRecord. Works with both versions 2.3.10 and 3.0.3.
19
+
20
+ Install the gem with:
21
+ <code>gem install activerecord-table_version</code>
22
+
23
+ Or, in your Gemfile:
24
+ <code>gem "activerecord-table_version", "~> 0.0.1"</code>
25
+
26
+ If you're on an older version of Rails:
27
+ <code>config.gem "activerecord-table_version", :version => "~> 0.0.1"</code>
28
+
29
+ h2. Migrations and Warning
30
+
31
+ In order to apply migrations, you will need to refer to the @table_name@ of the model directly.
32
+
33
+ NOTE: This has not seen extensive production use and this may result in problems in practice. You've been warned.
34
+
35
+ h2. License and Copyright
36
+
37
+ The MIT License
38
+
39
+ Copyright (c) 2011 Matt Todd.
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining a copy
42
+ of this software and associated documentation files (the "Software"), to deal
43
+ in the Software without restriction, including without limitation the rights
44
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45
+ copies of the Software, and to permit persons to whom the Software is
46
+ furnished to do so, subject to the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be included in
49
+ all copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
57
+ THE SOFTWARE.
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{activerecord-table_version}
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Matt Todd"]
7
- s.date = %q{2011-01-25}
7
+ s.date = %q{2011-03-09}
8
8
  s.description = %q{Specify a table name with a version number}
9
9
  s.email = %q{chiology@gmail.com}
10
10
  s.files = [
@@ -1,13 +1,23 @@
1
1
  require 'active_record'
2
+ require 'active_support/core_ext/module/aliasing'
2
3
 
3
- module ActiveRecord
4
- module TableVersion
5
- def set_table_version(version)
6
- self.set_table_name "%s_%s" % [self.table_name, version]
4
+ class ActiveRecord::Base
5
+
6
+ class_attribute :table_version, :instance_writer => false
7
+ self.table_version = nil
8
+
9
+ class << self
10
+ def compute_table_name_with_version
11
+ return compute_table_name_without_version unless table_version.present?
12
+ "%s_%s" % [compute_table_name_without_version, table_version]
13
+ end
14
+ alias_method_chain :compute_table_name, :version
15
+
16
+ def set_table_version(version = nil)
17
+ self.table_version = version
18
+ reset_table_name
19
+ version
7
20
  end
8
21
  end
9
22
 
10
- Base.class_eval do
11
- extend TableVersion
12
- end
13
23
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  class Model < ActiveRecord::Base
4
4
  end
5
5
 
6
- describe ActiveRecord::TableVersion do
6
+ describe ActiveRecord::Base do
7
7
 
8
8
  describe "when not used" do
9
9
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-table_version
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Todd
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-25 00:00:00 -05:00
18
+ date: 2011-03-09 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  requirements: []
116
116
 
117
117
  rubyforge_project:
118
- rubygems_version: 1.3.7
118
+ rubygems_version: 1.4.2
119
119
  signing_key:
120
120
  specification_version: 3
121
121
  summary: Specify a table name with a version number