Sha256: ad3b2c8d97d784f6f5ad00285ba9dcab549865006164b4e40f880b56082b58fa

Contents?: true

Size: 837 Bytes

Versions: 2

Compression:

Stored size: 837 Bytes

Contents

module Artisanal::Model
  require_relative 'initializer'
  require_relative 'model'

  module DSL
    def self.extended(base)
      base.prepend Initializer
      base.include InstanceMethods
    end

    def inherited(subclass)
      subclass.include Artisanal::Model(**artisanal_model.config.options)
      super(subclass)
    end

    def artisanal_model
      @artisanal_model ||= Model.new(self)
    end

    def schema
      artisanal_model.schema
    end

    def attribute(*args, **kwargs)
      artisanal_model.attribute(*args, **kwargs)
    end

    module InstanceMethods
      def artisanal_model
        self.class.artisanal_model
      end

      def attributes(*args)
        artisanal_model.attributes(self, *args)
      end

      def to_h(**args)
        artisanal_model.to_h(self, **args)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
artisanal-model-0.2.1 lib/artisanal/model/dsl.rb
artisanal-model-0.2.0 lib/artisanal/model/dsl.rb