Sha256: 0a19ca14c2363cbb6dbfb9643b95749cbf021c8eec4bc31cf20a8067c06fc456
Contents?: true
Size: 960 Bytes
Versions: 11
Compression:
Stored size: 960 Bytes
Contents
module Mobility module Backend =begin Adds {#for} method to backend to return ORM-specific backend. @example KeyValue backend for AR model class Post < ActiveRecord::Base # ... end Mobility::Backend::KeyValue.for(Post) #=> Mobility::Backend::ActiveRecord::KeyValue =end module OrmDelegator # @param [Class] model_class Class of model # @return [Class] Class of backend to use for model 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 def self.included(base) base.extend(self) end end end end
Version data entries
11 entries across 11 versions & 1 rubygems