Module: Hippo::Command::ClientModelUpdate

Defined in:
lib/hippo/command/client_model_update.rb

Instance Method Summary collapse

Instance Method Details

#replace_props(file, columns) ⇒ Object

Parameters:

  • file (Pathname)

    file to replace the props on


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hippo/command/client_model_update.rb', line 6

def replace_props(file, columns)
    contents = file.read
    match = contents.match(/\n(\s+props\s*:\s*)\n+(\s+)\w/m)
    if !match
        raise Thor::Error.new("Unable to detect existing props section")
    end
    (props,indent) = match.capture3
p match
    maxlen = columns.map{|field| field.name.length }.max

    contents = "#{props}"
    columns.each do | column |
        contents << sprintf("#{indent}%-#{maxlen+1}s",column.name+':') + type_specification(column) + "\n"
    end
puts contents
#                gsub_file file, /\n\s+props\s*:\s*\n.*?\n\n/m, contents

#     props:
# <% len = max_name_length(@columns)
#    @columns.each do | column | -%>
#         <%= sprintf("%-#{len+1}s",column.name+':') -%> <%= type_specification(column) %>
# <% end -%>

# <% if @associations.any? -%>
#     associations:
# <% len = max_name_length(@associations)
#    @associations.each do | assoc | -%>
#         <%= sprintf("%-#{len+2}s",assoc.name.to_s+':') -%> { <%= assoc.collection? ? 'collection' : 'model' -%>: "<%= assoc.class_name.demodulize %>" }
# <% end -%>
# <% end -%>




end