Sha256: fa911744c68eda2145e7e3d6c5c9047a99a965224f5e70309601a9696bff3218
Contents?: true
Size: 1.12 KB
Versions: 3
Compression:
Stored size: 1.12 KB
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 set_context_for opts klass.new(name, opts, &block).tap do reinitialize if is_a?(Entity) end end protected def set_context_for(opts) if is_a?(Entity) opts[:parent] ||= self else opts[:root] = self end end 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
json-schema_builder-0.8.2 | lib/json/schema_builder/dsl.rb |
json-schema_builder-0.8.1 | lib/json/schema_builder/dsl.rb |
json-schema_builder-0.8.0 | lib/json/schema_builder/dsl.rb |