rails_agnostic_models 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.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The purpose of this project is to ease the pain of upgrading Rails versions by abstracting away differences between the Rails 2.3 and 3.2 API.
4
4
 
5
- ## Wait, if I'm gonna update my code, why don't I just update to Rails 3 instead of this crap?
5
+ ### Wait, if I'm gonna update my code, why don't I just update to Rails 3 or 4 instead of this crap?
6
6
 
7
7
  If your codebase is small enough to do that in one go, please, by all means.
8
8
 
@@ -26,8 +26,15 @@ Or install it yourself as:
26
26
 
27
27
  ```ruby
28
28
  class MyModel < ActiveRecord::Base
29
- version_agnostic_scope :active, { where active: true } # proxys to named_scope in Rails 2, scope in Rails 3
30
- version_agnostic_inheritance_column "type_inheritance" # set_inheritance_column in RAils 2, self.inheritance_column= in Rails 3
29
+ # Manage flat_out incompatible code with Rails Edition Specific Blocks
30
+ rails_2 { acts_as_audited }
31
+ rails_3 { audited }
32
+
33
+ # scoping, named_scope in Rails 2, scope in Rails 3+
34
+ version_agnostic_scope :active, { where active: true } # relies on fake_arel in Rails 2 to provide 3+ Query Interface
35
+
36
+ # single table inheritance, set_inheritance_column in rails 2, self.inheritance_column= in Rails 3+
37
+ version_agnostic_inheritance_column "type_inheritance"
31
38
  end
32
39
  ```
33
40
 
@@ -1,34 +1,8 @@
1
1
  module RailsAgnosticModels
2
+ include RailsVersionHelpers
2
3
  module ActiveRecordExtensions
3
4
  module ClassMethods
4
- def rails_2?
5
- (defined? Rails) && (Rails::VERSION::MAJOR == 2)
6
- end
7
-
8
- def rails_3?
9
- (defined? Rails) && (Rails::VERSION::MAJOR == 3)
10
- end
11
-
12
- def rails_4?
13
- (defined? Rails) && (Rails::VERSION::MAJOR == 4)
14
- end
15
-
16
- # Takes a block that will only be executed in a Rails 2 Project
17
- def rails_2(&block)
18
- return nil unless rails_2?
19
- yield
20
- end
21
-
22
- def rails_3(&block)
23
- return nil unless rails_3?
24
- yield
25
- end
26
-
27
- def rails_4(&block)
28
- return nil unless rails_4?
29
- yield
30
- end
31
-
5
+
32
6
  def version_agnostic_scope(*args)
33
7
  if rails_2?
34
8
  named_scope(*args)
@@ -45,6 +19,7 @@ module RailsAgnosticModels
45
19
  end
46
20
  end
47
21
  end
22
+
48
23
  def self.included(klass)
49
24
  klass.extend(ClassMethods)
50
25
  end
@@ -0,0 +1,36 @@
1
+ module RailsAgnosticModels
2
+ module RailsVersionHelpers
3
+ def self.included(klass)
4
+ klass.extend(ClassMethods)
5
+ end
6
+ module ClassMethods
7
+ def rails_2?
8
+ (defined? Rails) && (Rails::VERSION::MAJOR == 2)
9
+ end
10
+
11
+ def rails_3?
12
+ (defined? Rails) && (Rails::VERSION::MAJOR == 3)
13
+ end
14
+
15
+ def rails_4?
16
+ (defined? Rails) && (Rails::VERSION::MAJOR == 4)
17
+ end
18
+
19
+ # Takes a block that will only be executed in a Rails 2 Project
20
+ def rails_2(&block)
21
+ return nil unless rails_2?
22
+ yield
23
+ end
24
+
25
+ def rails_3(&block)
26
+ return nil unless rails_3?
27
+ yield
28
+ end
29
+
30
+ def rails_4(&block)
31
+ return nil unless rails_4?
32
+ yield
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsAgnosticModels
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,3 +1,4 @@
1
1
  require "rails_agnostic_models/version"
2
2
  require "active_record"
3
+ require 'rails_agnostic_models/rails_version_helpers'
3
4
  require "rails_agnostic_models/active_record_extensions"
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = RailsAgnosticModels::VERSION
9
9
  spec.authors = ["DVG"]
10
10
  spec.email = ["devryguy@gmail.com"]
11
- spec.description = %q{The purpose of this project is to ease the pain of upgrading Rails versions by abstracting away differences between the Rails 2.3 and 3.2 API.n}
11
+ spec.description = %q{The purpose of this project is to ease the pain of upgrading Rails versions by abstracting away differences between the Rails 2.3 and 3.2 API.}
12
12
  spec.summary = %q{Extends activerecord to provide rails-agnostic versions of common model code to east the pain of upgrading}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_agnostic_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -60,7 +60,7 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  description: The purpose of this project is to ease the pain of upgrading Rails versions
63
- by abstracting away differences between the Rails 2.3 and 3.2 API.n
63
+ by abstracting away differences between the Rails 2.3 and 3.2 API.
64
64
  email:
65
65
  - devryguy@gmail.com
66
66
  executables: []
@@ -74,6 +74,7 @@ files:
74
74
  - Rakefile
75
75
  - lib/rails_agnostic_models.rb
76
76
  - lib/rails_agnostic_models/active_record_extensions.rb
77
+ - lib/rails_agnostic_models/rails_version_helpers.rb
77
78
  - lib/rails_agnostic_models/version.rb
78
79
  - rails_agnostic_models.gemspec
79
80
  homepage: ''
@@ -91,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
92
  version: '0'
92
93
  segments:
93
94
  - 0
94
- hash: -1780518797676429086
95
+ hash: 3379864087474982938
95
96
  required_rubygems_version: !ruby/object:Gem::Requirement
96
97
  none: false
97
98
  requirements:
@@ -100,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  version: '0'
101
102
  segments:
102
103
  - 0
103
- hash: -1780518797676429086
104
+ hash: 3379864087474982938
104
105
  requirements: []
105
106
  rubyforge_project:
106
107
  rubygems_version: 1.8.24