Sha256: 059f76b6c6d3f525db61c955168f8ecab988ed7c8349aac14937872c17ffbc09
Contents?: true
Size: 813 Bytes
Versions: 2
Compression:
Stored size: 813 Bytes
Contents
require 'fluent/json/schema/terms' class Fluent::Json::Schema::Terms::Field attr_reader :version, :name, :required, :enum, :default, :constraints def initialize(name, options={}) @name = name @required = options[:required] @constraints = [] self.set(options) end def mandate @required = true return self end def optionalise @required = false return self end def set(options={}) @enum = options[:enum] @default = options[:default] end def as_json(options={}) return options.merge(self.as_json_fragment(:default, :enum)) end protected def as_json_fragment(*names) result = {} names.each do |name| value = self.send(name) result[name] = value if value.present? end return result end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fluent-json-schema-0.1.2 | lib/fluent/json/schema/terms/field.rb |
fluent-json-schema-0.1.1 | lib/fluent/json/schema/terms/field.rb |