Class: PgVerify::Cli::ShowCommand

Inherits:
Thor
  • Object
show all
Defined in:
lib/pg-verify/cli/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.select_components(only_arg, hide_arg, model) ⇒ Object



111
112
113
114
115
116
117
118
# File 'lib/pg-verify/cli/cli.rb', line 111

def self.select_components(only_arg, hide_arg, model)
    only = (only_arg || []).flatten.map(&:to_s).map(&:downcase)
    hide = (hide_arg || []).flatten.map(&:to_s).map(&:downcase)
    components = model.components.map(&:name)
    components = components.select { |c| only.include?(c.to_s.downcase) } unless only.empty?
    components = components.reject { |c| hide.include?(c.to_s.downcase) } unless hide.empty?
    return components
end

Instance Method Details

#jsonObject



89
90
91
92
93
94
95
96
# File 'lib/pg-verify/cli/cli.rb', line 89

def json()
    models = CliUtils.load_models(options)

    models.each { |model| 
        hash = Transform::HashTransformation.new.transform_graph(model)
        puts JSON.pretty_generate(hash)
    }
end

#nusmvObject



102
103
104
105
106
107
108
109
# File 'lib/pg-verify/cli/cli.rb', line 102

def nusmv()
    models = CliUtils.load_models(options)

    models.each { |model|
        nusmv = Transform::NuSmvTransformation.new.transform_graph(model)
        puts nusmv
    }
end

#pngObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pg-verify/cli/cli.rb', line 50

def png()
    render_options = {
        render_labels: !options[:"hide-labels"],
        render_precons: !options[:"hide-precons"],
        render_guards: !options[:"hide-guards"],
        render_actions: !options[:"hide-actions"]
    }

    models = CliUtils.load_models(options)

    models.each { |model|
        components = self.class.select_components(options[:only], options[:hide], model)
        puml = Transform::PumlTransformation.new(render_options).transform_graph(model, only: components)
        png = PlantumlBuilder::Formats::PNG.new(puml).load
        out_name = model.name.to_s.gsub(/\W+/, '_').downcase + ".png"
        out_path = File.expand_path(out_name, Settings.outdir)
        FileUtils.mkdir_p(Settings.outdir)
        File.binwrite(out_path, png)
        puts "Wrote #{out_path.c_file}"
    }
end

#pumlObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pg-verify/cli/cli.rb', line 24

def puml()
    render_options = {
        render_labels: !options[:"hide-labels"],
        render_precons: !options[:"hide-precons"],
        render_guards: !options[:"hide-guards"],
        render_actions: !options[:"hide-actions"]
    }
    models = CliUtils.load_models(options)
    models.each { |model|
        components = self.class.select_components(options[:only], options[:hide], model)
        puml = Transform::PumlTransformation.new(render_options).transform_graph(model, only: components)
        puts puml
    }
end

#yamlObject



76
77
78
79
80
81
82
83
# File 'lib/pg-verify/cli/cli.rb', line 76

def yaml()
    models = CliUtils.load_models(options)

    models.each { |model| 
        hash = Transform::HashTransformation.new.transform_graph(model)
        puts hash.to_yaml
    }
end