Class: Eaco::Adapters::ActiveRecord::Compatibility
- Inherits:
-
Object
- Object
- Eaco::Adapters::ActiveRecord::Compatibility
- Defined in:
- lib/eaco/adapters/active_record/compatibility.rb,
lib/eaco/adapters/active_record/compatibility/v32.rb,
lib/eaco/adapters/active_record/compatibility/v40.rb,
lib/eaco/adapters/active_record/compatibility/v41.rb,
lib/eaco/adapters/active_record/compatibility/v42.rb,
lib/eaco/adapters/active_record/compatibility/scoped.rb
Overview
Sets up JSONB support for the different AR versions
Defined Under Namespace
Modules: Scoped, V32, V40, V41, V42
Instance Method Summary collapse
-
#active_record_version ⇒ String
private
Example: “42” for 4.2.
-
#check!
Checks whether the target model is compatible.
-
#initialize(model) ⇒ Compatibility
constructor
Memoizes the given
modelfor later #check! calls. -
#support_module ⇒ Module
private
Tries to look up the support module for the #active_record_version in the Compatibility namespace.
-
#support_module_name ⇒ String
private
Example: “V32” for Rails 3.2.
-
#target ⇒ ActiveRecord::Base
private
Associated with the model.
Constructor Details
#initialize(model) ⇒ Compatibility
Memoizes the given model for later #check! calls.
21 22 23 |
# File 'lib/eaco/adapters/active_record/compatibility.rb', line 21 def initialize(model) @model = model end |
Instance Method Details
#active_record_version ⇒ String (private)
Example: “42” for 4.2
52 53 54 55 |
# File 'lib/eaco/adapters/active_record/compatibility.rb', line 52 def active_record_version ver = target.parent.const_get(:VERSION) [ver.const_get(:MAJOR), ver.const_get(:MINOR)].join end |
#check!
This method returns an undefined value.
Checks whether the target model is compatible. Looks up the #support_module and includes it.
33 34 35 36 |
# File 'lib/eaco/adapters/active_record/compatibility.rb', line 33 def check! layer = support_module target.instance_eval { include layer } end |
#support_module ⇒ Module (private)
Tries to look up the support module for the #active_record_version in the Eaco::Adapters::ActiveRecord::Compatibility namespace.
67 68 69 70 71 72 73 74 75 |
# File 'lib/eaco/adapters/active_record/compatibility.rb', line 67 def support_module unless self.class.const_defined?(support_module_name) raise Eaco::Error, <<-EOF Unsupported Active Record version: #{active_record_version} EOF end self.class.const_get support_module_name end |
#support_module_name ⇒ String (private)
Example: “V32” for Rails 3.2.
82 83 84 |
# File 'lib/eaco/adapters/active_record/compatibility.rb', line 82 def support_module_name ['V', active_record_version].join end |
#target ⇒ ActiveRecord::Base (private)
Returns associated with the model.
43 44 45 |
# File 'lib/eaco/adapters/active_record/compatibility.rb', line 43 def target @model.base_class.superclass end |