Module: Mobility::Backend::OrmDelegator
- Defined in:
- lib/mobility/backend/orm_delegator.rb
Overview
Adds #for method to backend to return ORM-specific backend.
Class Method Summary collapse
Instance Method Summary collapse
-
#for(model_class) ⇒ Class
Class of backend to use for model.
Class Method Details
.included(base) ⇒ Object
28 29 30 |
# File 'lib/mobility/backend/orm_delegator.rb', line 28 def self.included(base) base.extend(self) end |
Instance Method Details
#for(model_class) ⇒ Class
Returns Class of backend to use for model.
18 19 20 21 22 23 24 25 26 |
# File 'lib/mobility/backend/orm_delegator.rb', line 18 def for(model_class) if Loaded::ActiveRecord && model_class < ::ActiveRecord::Base const_get(name.split("::").insert(-2, "ActiveRecord").join("::")) elsif Loaded::Sequel && model_class < ::Sequel::Model const_get(name.split("::").insert(-2, "Sequel").join("::")) else raise ArgumentError, "#{name.split('::').last} backend can only be used by ActiveRecord or Sequel models" end end |