Class: GoaModelGen::Cli
- Inherits:
-
Thor
- Object
- Thor
- GoaModelGen::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/goa_model_gen/cli.rb
Instance Method Summary collapse
- #config(path = './goa_model_gen.yaml') ⇒ Object
- #converter(path) ⇒ Object
- #model(*paths) ⇒ Object
- #show(*paths) ⇒ Object
- #store(*paths) ⇒ Object
- #structs_gen ⇒ Object
- #version ⇒ Object
Instance Method Details
#config(path = './goa_model_gen.yaml') ⇒ Object
27 28 29 30 |
# File 'lib/goa_model_gen/cli.rb', line 27 def config(path = './goa_model_gen.yaml') setup open(path, 'w'){|f| f.puts(Config.new.fulfill.to_yaml) } end |
#converter(path) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/goa_model_gen/cli.rb', line 79 def converter(path) setup new_generator.process({ "templates/converter_base.go.erb" => File.join(cfg.converter_dir, "base.go"), }) structs = JSON.parse(File.read(path)) (structs['model'] || []).each do |mt| m = GoStruct.new(mt) pt = (structs['payload'] || []).detect{|t| t["Name"] == "#{m.name}Payload" } rt = (structs['result'] || []).detect{|t| t["Name"] == m.name } variables = { model: m, payload: pt ? GoStruct.new(pt) : nil, result: rt ? GoStruct.new(rt) : nil } new_generator.run('templates/converter.go.erb', File.join(cfg.converter_dir, m.name.underscore, "conv.go"), variables) end end |
#model(*paths) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/goa_model_gen/cli.rb', line 42 def model(*paths) setup new_generator.process({ 'templates/validator.go.erb' => File.join(cfg.model_dir, 'validator.go'), }) load_types_for(paths) do |source_file| new_generator.tap{|g| g.source_file = source_file }.process({ 'templates/model.go.erb' => File.join(cfg.model_dir, "#{source_file.basename}.go"), 'templates/model_validation.go.erb' => File.join(cfg.model_dir, "#{source_file.basename}_validation.go"), }) end end |
#show(*paths) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/goa_model_gen/cli.rb', line 33 def show(*paths) setup load_types_for(paths) do |source_file| puts "types in #{source_file.yaml_path}" puts YAML.dump(source_file.types) end end |
#store(*paths) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/goa_model_gen/cli.rb', line 56 def store(*paths) setup new_generator.process({ "templates/goon.go.erb" => File.join(cfg.store_dir, "goon_store", "goon.go"), }) load_types_for(paths) do |source_file| new_generator.tap{|g| g.source_file = source_file }.process({ 'templates/store.go.erb' => File.join(cfg.store_dir, source_file.basename, "store.go"), 'templates/store_validation.go.erb' => File.join(cfg.store_dir, source_file.basename, "validation.go"), }) end end |
#structs_gen ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/goa_model_gen/cli.rb', line 70 def structs_gen setup new_generator.process({ "templates/structs_base.go.erb" => File.join(cfg.structs_gen_dir, "structs.go"), "templates/structs_main.go.erb" => File.join(cfg.structs_gen_dir, "main.go"), }) end |
#version ⇒ Object
99 100 101 |
# File 'lib/goa_model_gen/cli.rb', line 99 def version show_version end |