Module: GreenHat::ShellHelper::Faststats
- Defined in:
- lib/greenhat/shell/faststats.rb
Overview
Hide from Commands
Class Method Summary collapse
-
.faststats? ⇒ Boolean
Internal Helpers =====================================.
- .files ⇒ Object
-
.invalid_settings ⇒ Object
Default Settings from arg parse that won’t work.
- .parse(raw) ⇒ Object
- .run(thing, cmd = '') ⇒ Object
- .things ⇒ Object
Class Method Details
.faststats? ⇒ Boolean
Internal Helpers
268 269 270 |
# File 'lib/greenhat/shell/faststats.rb', line 268 def self.faststats? TTY::Which.exist?('fast-stats') end |
.files ⇒ Object
250 251 252 253 254 255 256 257 |
# File 'lib/greenhat/shell/faststats.rb', line 250 def self.files %w[ production_json api_json gitaly/current sidekiq/current ] end |
.invalid_settings ⇒ Object
Default Settings from arg parse that won’t work
218 219 220 |
# File 'lib/greenhat/shell/faststats.rb', line 218 def self.invalid_settings %i[page round truncate logic fuzzy_file_match] end |
.parse(raw) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/greenhat/shell/faststats.rb', line 222 def self.parse(raw) file_list, flags, args = Args.parse(raw, invalid_settings) cmd = args.map { |opt| "--#{opt.field}=#{opt.value}" }.join(' ') cmd += flags.map do |flag, value| # Don't Include Raw next if flag == :raw case value when true then "--#{flag}" when Array then "--#{flag}=#{value.join}" else "--#{flag}=#{value}" end end.join(' ') # Prepare Log List / Allow attempting of parsing everything file_list = if file_list == ['*'] Thing.all.map(&:name) else ShellHelper.prepare_list(file_list, ShellHelper::Faststats.things) end # Convert to Things files = ShellHelper.find_things(file_list, fuzzy_file_match: true) [files, flags, cmd] end |
.run(thing, cmd = '') ⇒ Object
272 273 274 275 276 277 |
# File 'lib/greenhat/shell/faststats.rb', line 272 def self.run(thing, cmd = '') # Blank return if cannot possibly run return {} unless thing || !faststats? Oj.load `fast-stats #{cmd} #{thing.file} --format=json` end |
.things ⇒ Object
259 260 261 262 263 |
# File 'lib/greenhat/shell/faststats.rb', line 259 def self.things Thing.all.select do |thing| files.any? { |x| thing.name.include? x } end end |