Class: GoonModelGen::Golang::Field
- Inherits:
-
Object
- Object
- GoonModelGen::Golang::Field
- Defined in:
- lib/goon_model_gen/golang/field.rb
Instance Attribute Summary collapse
-
#goon_id ⇒ Object
readonly
true/false.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prepare_method ⇒ Object
Returns the value of attribute prepare_method.
-
#struct ⇒ Object
Returns the value of attribute struct.
-
#tags ⇒ Object
readonly
Hash<string,Array> ex.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#type_name ⇒ Object
readonly
Returns the value of attribute type_name.
-
#unique ⇒ Object
Returns the value of attribute unique.
Instance Method Summary collapse
- #definition_in(pkg) ⇒ string
-
#initialize(name, type_name, tags, goon_id: false) ⇒ Field
constructor
A new instance of Field.
- #ptr? ⇒ Boolean
- #resolve(pkgs) ⇒ Object
- #short_desc(pkg2alias = nil) ⇒ string
- #slice? ⇒ Boolean
- #struct? ⇒ Boolean
- #tags_string ⇒ Object
- #value_ptr? ⇒ Boolean
Constructor Details
#initialize(name, type_name, tags, goon_id: false) ⇒ Field
Returns a new instance of Field.
20 21 22 23 24 |
# File 'lib/goon_model_gen/golang/field.rb', line 20 def initialize(name, type_name, , goon_id: false) @name, @type_name = name, type_name = || {} @goon_id = goon_id end |
Instance Attribute Details
#goon_id ⇒ Object (readonly)
true/false
14 15 16 |
# File 'lib/goon_model_gen/golang/field.rb', line 14 def goon_id @goon_id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/goon_model_gen/golang/field.rb', line 12 def name @name end |
#prepare_method ⇒ Object
Returns the value of attribute prepare_method.
17 18 19 |
# File 'lib/goon_model_gen/golang/field.rb', line 17 def prepare_method @prepare_method end |
#struct ⇒ Object
Returns the value of attribute struct.
16 17 18 |
# File 'lib/goon_model_gen/golang/field.rb', line 16 def struct @struct end |
#tags ⇒ Object (readonly)
Hash<string,Array> ex. for datastore, validate, json, etc…
13 14 15 |
# File 'lib/goon_model_gen/golang/field.rb', line 13 def end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/goon_model_gen/golang/field.rb', line 15 def type @type end |
#type_name ⇒ Object (readonly)
Returns the value of attribute type_name.
12 13 14 |
# File 'lib/goon_model_gen/golang/field.rb', line 12 def type_name @type_name end |
#unique ⇒ Object
Returns the value of attribute unique.
18 19 20 |
# File 'lib/goon_model_gen/golang/field.rb', line 18 def unique @unique end |
Instance Method Details
#definition_in(pkg) ⇒ string
41 42 43 44 45 |
# File 'lib/goon_model_gen/golang/field.rb', line 41 def definition_in(pkg) type_exp = (type.package.path == pkg.path) ? type.name : type.qualified_name "#{ name } #{ type_exp } `#{ tags_string }`" end |
#ptr? ⇒ Boolean
47 48 49 50 51 52 53 |
# File 'lib/goon_model_gen/golang/field.rb', line 47 def ptr? case type when Modifier then (type.prefix == "*") when Type then false else raise "Unsupported type class #{type.inspect}" end end |
#resolve(pkgs) ⇒ Object
27 28 29 |
# File 'lib/goon_model_gen/golang/field.rb', line 27 def resolve(pkgs) @type = pkgs.type_for(type_name) || raise("#{type_name.inspect} not found for #{struct.qualified_name}.#{name}") end |
#short_desc(pkg2alias = nil) ⇒ string
88 89 90 |
# File 'lib/goon_model_gen/golang/field.rb', line 88 def short_desc(pkg2alias = nil) "#{name}: #{type.qualified_name(pkg2alias)}" end |
#slice? ⇒ Boolean
55 56 57 58 59 60 61 62 |
# File 'lib/goon_model_gen/golang/field.rb', line 55 def slice? case type when Modifier then (type.prefix == "[]") when NamedSlice then true when Type then false else raise "Unsupported type class #{type.inspect}" end end |
#struct? ⇒ Boolean
64 65 66 67 68 69 70 71 |
# File 'lib/goon_model_gen/golang/field.rb', line 64 def struct? case type when Modifier then false when Struct then true when Type then false else raise "Unsupported type class #{type.inspect}" end end |
#tags_string ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/goon_model_gen/golang/field.rb', line 31 def .keys.sort.map do |key| val = [key] vals = val.is_a?(Array) ? val.join(',') : val.to_s vals.empty? ? nil : "#{key}:\"#{vals}\"" end.compact.join(' ') end |
#value_ptr? ⇒ Boolean
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/goon_model_gen/golang/field.rb', line 73 def value_ptr? case type when Modifier then return false unless type.prefix == '*' case type.target when Builtin then type.target.name != 'interface' else false end when Type then false else raise "Unsupported type class #{type.inspect}" end end |