Module: Leafy::Mixin::Fields

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

Class Method Summary collapse

Class Method Details

.[](orm = :poro) ⇒ 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
44
# File 'lib/leafy/mixin/fields.rb', line 9

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

    def self.included(base)

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

      case @orm

      when :poro

        require_relative "./poro/fields"

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

      when :active_record

        require_relative "./active_record/shared"
        require_relative "./active_record/fields"

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

      else

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

      end
    end

  end
end