rails_agnostic_models 0.0.3 → 0.0.4

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
@@ -31,7 +31,8 @@ class MyModel < ActiveRecord::Base
31
31
  rails_3 { audited }
32
32
 
33
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
34
+ # We recommend using FakeArel in Rails 2 projects to get a universal query interface, but it is not required
35
+ version_agnostic_scope :active, { where active: true }
35
36
 
36
37
  # single table inheritance, set_inheritance_column in rails 2, self.inheritance_column= in Rails 3+
37
38
  version_agnostic_inheritance_column "type_inheritance"
@@ -1,16 +1,25 @@
1
1
  module RailsAgnosticModels
2
2
  module ActiveRecordExtensions
3
3
  module ClassMethods
4
+
5
+ # Checks if the host app is a Rails 2 app
4
6
  def rails_2?
5
- (defined? Rails) && (Rails::VERSION::MAJOR == 2)
7
+ rails_loaded && (Rails::VERSION::MAJOR == 2)
6
8
  end
7
9
 
10
+ # Checks if the host app is a Rails 3 app
8
11
  def rails_3?
9
- (defined? Rails) && (Rails::VERSION::MAJOR == 3)
12
+ rails_loaded && (Rails::VERSION::MAJOR == 3)
10
13
  end
11
14
 
15
+ # Checks if the host app is a Rails 4 app
12
16
  def rails_4?
13
- (defined? Rails) && (Rails::VERSION::MAJOR == 4)
17
+ rails_loaded && (Rails::VERSION::MAJOR == 4)
18
+ end
19
+
20
+ # Checks if Rails is loaded
21
+ def rails_loaded
22
+ defined? Rails
14
23
  end
15
24
 
16
25
  # Takes a block that will only be executed in a Rails 2 Project
@@ -19,16 +28,25 @@ module RailsAgnosticModels
19
28
  yield
20
29
  end
21
30
 
31
+ # Code to be executed insode of a Rails 3 app
22
32
  def rails_3(&block)
23
33
  return nil unless rails_3?
24
34
  yield
25
35
  end
26
36
 
37
+ # Code to be executed inside of a Rails 4 app
27
38
  def rails_4(&block)
28
39
  return nil unless rails_4?
29
40
  yield
30
41
  end
31
42
 
43
+ # Code to be executed only inside of a rails app
44
+ def rails(&block)
45
+ return nil unless rails_loaded
46
+ yield
47
+ end
48
+
49
+ # Defines the appropraite scope based on the version of Rails
32
50
  def version_agnostic_scope(*args)
33
51
  if rails_2?
34
52
  named_scope(*args)
@@ -37,6 +55,7 @@ module RailsAgnosticModels
37
55
  end
38
56
  end
39
57
 
58
+ # Sets the inheritance column based on the version of Rails
40
59
  def version_agnostic_inheritance_column(column_name)
41
60
  if rails_2?
42
61
  set_inheritance_column column_name
@@ -50,4 +69,4 @@ module RailsAgnosticModels
50
69
  end
51
70
  end
52
71
  ActiveRecord::Base.send(:include, ActiveRecordExtensions)
53
- end
72
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsAgnosticModels
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-06 00:00:00.000000000 Z
12
+ date: 2014-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -92,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  segments:
94
94
  - 0
95
- hash: 223464881747250287
95
+ hash: 1843333470422886331
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  version: '0'
102
102
  segments:
103
103
  - 0
104
- hash: 223464881747250287
104
+ hash: 1843333470422886331
105
105
  requirements: []
106
106
  rubyforge_project:
107
107
  rubygems_version: 1.8.24