Class: Eaco::Adapters::ActiveRecord::Compatibility

Inherits:
Object
  • Object
show all
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/v50.rb,
lib/eaco/adapters/active_record/compatibility/v51.rb,
lib/eaco/adapters/active_record/compatibility/scoped.rb,
lib/eaco/adapters/active_record/compatibility/sanitized.rb

Overview

Sets up JSONB support for the different AR versions

Defined Under Namespace

Modules: Sanitized, Scoped, V32, V40, V41, V42, V50, V51

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Compatibility

Memoizes the given model for later #check! calls.

Parameters:

  • model (ActiveRecord::Base)

    the model to check


24
25
26
# File 'lib/eaco/adapters/active_record/compatibility.rb', line 24

def initialize(model)
  @model = model
end

Instance Method Details

#active_record_versionString (private)

Example: “42” for 4.2

Returns:

  • (String)

    the ActiveRecord major and minor version numbers


48
49
50
51
52
53
# File 'lib/eaco/adapters/active_record/compatibility.rb', line 48

def active_record_version
  [
    ::ActiveRecord::VERSION::MAJOR,
    ::ActiveRecord::VERSION::MINOR
  ].join
end

#check!

This method returns an undefined value.

Checks whether ActiveRecord::Base is compatible. Looks up the #support_module and includes it.

See Also:


36
37
38
39
# File 'lib/eaco/adapters/active_record/compatibility.rb', line 36

def check!
  layer = support_module
  ::ActiveRecord::Base.instance_eval { include layer }
end

#support_moduleModule (private)

Tries to look up the support module for the #active_record_version in the Eaco::Adapters::ActiveRecord::Compatibility namespace.

Returns:

  • (Module)

    the support module

Raises:

See Also:


65
66
67
68
69
70
71
72
73
# File 'lib/eaco/adapters/active_record/compatibility.rb', line 65

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_nameString (private)

Example: “V32” for Rails 3.2.

Returns:


80
81
82
# File 'lib/eaco/adapters/active_record/compatibility.rb', line 80

def support_module_name
  ['V', active_record_version].join
end