class Ar2gostruct::Builder::Association

Attributes

klass[R]
max_col_size[R]
max_type_size[R]

Public Class Methods

new(klass, max_col_size, max_type_size) click to toggle source
  # File lib/ar2gostruct/builder/association.rb
4 def initialize(klass, max_col_size, max_type_size)
5   @klass = klass
6   @max_col_size = max_col_size
7   @max_type_size = max_type_size
8 end

Public Instance Methods

get_schema_info() click to toggle source
   # File lib/ar2gostruct/builder/association.rb
11 def get_schema_info
12   info = ""
13   self.klass.reflect_on_all_associations.each do |assoc|
14     tags = ["json:\"#{assoc.name.to_s}\""]
15     case assoc.macro
16     when :has_many
17       col_name = assoc.name.to_s.camelize
18       type_name = "[]#{assoc.name.to_s.singularize.camelize}"
19     when :has_one, :belongs_to
20       col_name = assoc.name.to_s.camelize
21       type_name = col_name
22     end
23     if col_name && type_name
24       info << sprintf("\t%-#{self.max_col_size}.#{self.max_col_size+2}s%-#{self.max_type_size}.#{self.max_type_size}s`%s`\n", col_name, type_name, tags.join(" "))
25     end
26   end
27   info
28 end