Module: Leafy::Mixin::Schema

Defined in:
lib/leafy/mixin/schema.rb

Class Method Summary collapse

Class Method Details

.[](orm) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/leafy/mixin/schema.rb', line 9

def self.[](orm)
  Module.new do
    @orm = orm

    def self.included(base)

      base.extend DataAccessor::ClassMethods
      base.include DataAccessor::InstanceMethods

      case @orm
      when :poro

        require_relative "./poro/schema"

        base.extend Poro::Schema::ClassMethods
        base.include Poro::Schema::InstanceMethods

      when :active_record

        require_relative "./active_record/shared"
        require_relative "./active_record/schema"

        base.extend ActiveRecord::Schema::ClassMethods
        base.include ActiveRecord::Shared::InstanceMethods
        base.include ActiveRecord::Schema::InstanceMethods

      else

        raise(RuntimeError, "Leafy: unsupported schema storage: #{orm}")

      end
    end

  end
end