Class: GoonModelGen::Source::Field
- Inherits:
-
Object
- Object
- GoonModelGen::Source::Field
- Includes:
- Contextual
- Defined in:
- lib/goon_model_gen/source/field.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#tags ⇒ Object
readonly
Hash<string,Array> ex.
-
#type_name ⇒ Object
readonly
Returns the value of attribute type_name.
-
#unique ⇒ Object
readonly
Returns the value of attribute unique.
Attributes included from Contextual
Instance Method Summary collapse
- #build_tags ⇒ Object
-
#initialize(name, attrs) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(name, attrs) ⇒ Field
Returns a new instance of Field.
17 18 19 20 21 22 23 |
# File 'lib/goon_model_gen/source/field.rb', line 17 def initialize(name, attrs) @name = name @type_name = attrs['type'] @required = attrs['required'] @unique = attrs['unique'] @tags = attrs['tags'] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/goon_model_gen/source/field.rb', line 10 def name @name end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
11 12 13 |
# File 'lib/goon_model_gen/source/field.rb', line 11 def required @required end |
#tags ⇒ Object (readonly)
Hash<string,Array> ex. for datastore, validate, json, etc…
13 14 15 |
# File 'lib/goon_model_gen/source/field.rb', line 13 def @tags end |
#type_name ⇒ Object (readonly)
Returns the value of attribute type_name.
10 11 12 |
# File 'lib/goon_model_gen/source/field.rb', line 10 def type_name @type_name end |
#unique ⇒ Object (readonly)
Returns the value of attribute unique.
12 13 14 |
# File 'lib/goon_model_gen/source/field.rb', line 12 def unique @unique end |
Instance Method Details
#build_tags ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/goon_model_gen/source/field.rb', line 25 def r = {} ( || {}).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 |