Class: SandiMeter::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/sandi_meter/cli.rb

Class Method Summary collapse

Class Method Details

.executeObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/sandi_meter/cli.rb', line 77

def execute
  cli = CommandParser.new
  cli.parse_options

  if cli.config[:graph]
    log_dir_path = File.join(cli.config[:path], 'sandi_meter')
    FileUtils.mkdir(log_dir_path) unless Dir.exists?(log_dir_path)

    create_config_file(cli.config[:path], 'sandi_meter/.sandi_meter', %w(db vendor).join("\n"))
    create_config_file(cli.config[:path], 'sandi_meter/config.yml', YAML.dump({ threshold: 90 }))
  end

  if cli.config[:version]
    puts version_info
    exit 0
  end

  if cli.config[:rules]
    show_sandi_rules
    exit 0
  end

  scanner = SandiMeter::FileScanner.new(cli.config[:log])
  data = scanner.scan(cli.config[:path], cli.config[:details] || cli.config[:graph])

  if cli.config[:json]
    formatter = SandiMeter::JsonFormatter.new
  else
    formatter = SandiMeter::Formatter.new
  end

  formatter.print_data(data)

  if cli.config[:graph]
    if File.directory?(cli.config[:path])
      logger = SandiMeter::Logger.new(data)
      logger.log!(cli.config[:path])

      html_generator = SandiMeter::HtmlGenerator.new
      html_generator.copy_assets!(cli.config[:path])
      html_generator.generate_data!(cli.config[:path])
      html_generator.generate_details!(cli.config[:path], data)

      index_html_path = File.join(cli.config[:path], 'sandi_meter/index.html')
      unless cli.config[:quiet]
        open_in_browser(index_html_path)
      end
    else
      puts "WARNING!!! HTML mode works only if you scan folder."
    end
  end

  config_file_path = File.join(cli.config[:path], 'sandi_meter', 'config.yml')
  config =  if File.exists?(config_file_path)
              YAML.load(File.read(config_file_path))
            else
              { threshold: 90 }
            end

  if RulesChecker.new(data, config).ok?
    exit 0
  else
    exit 1
  end
end

.show_sandi_rulesObject



143
144
145
146
147
148
149
150
# File 'lib/sandi_meter/cli.rb', line 143

def show_sandi_rules
  puts %(
    1. 100 lines per class
    2. 5 lines per method
    3. 4 params per method call (and don't even try cheating with hash params)
    4. 1 instance variables per controller' action
  )
end