Sha256: 4cc0a00b00a9618b87be8356f985274bd754e39a79e0babbb6f6606b66ae8e77

Contents?: true

Size: 951 Bytes

Versions: 1

Compression:

Stored size: 951 Bytes

Contents

module JSON
  module SchemaBuilder
    module DSL
      extend ActiveSupport::Concern
      mattr_accessor :types

      def entity(*args, &block)
        opts = args.extract_options!
        klass, name = klass_and_name_from args
        opts[:parent] ||= self if is_a?(Entity)
        klass.new name, opts, &block
      end

      protected

      def klass_and_name_from(args)
        type, name = args
        if DSL.types[type]
          [DSL.types[type], name]
        else
          [Entity, type]
        end
      end

      module ClassMethods
        def register(type)
          self.registered_type = type
          DSL.types ||= { }
          DSL.types[type] = self

          DSL.module_eval do
            define_method type do |*args, &block|
              opts = args.extract_options!
              name = args.first
              entity type, name, opts, &block
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
json-schema_builder-0.0.1 lib/json/schema_builder/dsl.rb