Sha256: 554a01cadf6440a6ac37569d0ad333cb98fd354d3f115c9ab4a7f303b3f3d1f3
Contents?: true
Size: 979 Bytes
Versions: 14
Compression:
Stored size: 979 Bytes
Contents
require "goon_model_gen" require "goon_model_gen/source/contextual" module GoonModelGen module Source class Field include Contextual attr_reader :name, :type_name attr_reader :required attr_reader :unique attr_reader :tags # Hash<string,Array[string]> ex. for datastore, validate, json, etc... # @param name [String] # @param attrs [Hash<string,Object>] def initialize(name, attrs) @name = name @type_name = attrs['type'] @required = attrs['required'] @unique = attrs['unique'] @tags = attrs['tags'] end def build_tags r = {} (tags || {}).each do |key, val| r[key] = val.is_a?(Array) ? val.dup : [val] end r['json'] ||= [name.underscore] if required r['validate'] = ['required'] + (r['validate'] || []) else r['json'] << 'omitempty' end return r end end end end
Version data entries
14 entries across 14 versions & 1 rubygems