Class: AmsLayout::DelegateWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/ams_layout/delegate_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#class_nameObject

Name of this class



33
34
35
# File 'lib/ams_layout/delegate_writer.rb', line 33

def class_name
  @class_name ||= AmsLayout.configuration.delegate_class_name
end

#delegated_class_nameObject

Name of class we will delegate to



41
42
43
# File 'lib/ams_layout/delegate_writer.rb', line 41

def delegated_class_name
  @delegated_class_name ||= AmsLayout.configuration.layout_class_name
end

#source_file_nameObject

Name of this class’ source file



25
26
27
# File 'lib/ams_layout/delegate_writer.rb', line 25

def source_file_name
  class_name.ams_layout_snakecase + '.rb'
end

Instance Method Details

#aliasesObject

List of aliases for specified fields



49
50
51
# File 'lib/ams_layout/delegate_writer.rb', line 49

def aliases
  @aliases ||= {}
end

#aliases=(data) ⇒ Object



53
54
55
# File 'lib/ams_layout/delegate_writer.rb', line 53

def aliases=(data)
  @aliases = Hash(data)
end

#write(stream, layout) ⇒ Object

Write a class file, based on the the layout.yml, to the provided stream



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ams_layout/delegate_writer.rb', line 61

def write stream, layout
  stream << header

  layout.each do |, fields|
    stream << section()

    fields.each do |fld|
      stream << field(fld[:label], fld[:id], fld[:type])
      write_aliases stream, fld[:label], fld[:id], fld[:type]
    end # fields
  end # layout

  stream << footer
end