Sha256: de003d2958653ecbdf75d793ed152a4f3c8b34354d266fcf5395c6fd0543fe0a

Contents?: true

Size: 798 Bytes

Versions: 5

Compression:

Stored size: 798 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"
require_relative "builder"
require_relative "schema_enhancer"

module Esquema
  # The Esquema module provides functionality for building JSON schemas.
  module Model
    extend ActiveSupport::Concern

    included do
      # Returns the JSON schema for the model.
      def self.json_schema
        Esquema::Builder.new(self).build_schema.to_json
      end

      # Enhances the schema using the provided block.
      def self.enhance_schema(&block)
        schema_enhancements
        enhancer = SchemaEnhancer.new(self, @schema_enhancements)
        enhancer.instance_eval(&block)
      end

      # Returns the schema enhancements.
      def self.schema_enhancements
        @schema_enhancements ||= {}
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
model-to-schema-0.1.2 lib/esquema/model.rb
model-to-schema-0.1.1 lib/esquema/model.rb
model-to-schema-0.1.0 lib/esquema/model.rb
model-to-squema-0.1.0 lib/esquema/model.rb
esquema-0.1.2 lib/esquema/model.rb