Class: Guard::Standardrb

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/standardrb.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Standardrb

Returns a new instance of Standardrb.



6
7
8
9
10
11
12
13
14
# File 'lib/guard/standardrb.rb', line 6

def initialize(opts = {})
  super

  @options = {
    fix: false,
    all_on_start: false,
    progress: false
  }.merge(opts)
end

Instance Method Details

#inspect_with_standardrb(paths = []) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/guard/standardrb.rb', line 40

def inspect_with_standardrb(paths = [])
  args = ["bundle", "exec", "standardrb"]
  args << "--fix" if @options[:fix]
  args << ["--format", "progress"] if @options[:progress]

  args.flatten!
  args += paths

  system(*args)
end

#run_allObject



24
25
26
# File 'lib/guard/standardrb.rb', line 24

def run_all
  inspect_with_standardrb
end

#run_on_additions(paths) ⇒ Object



28
29
30
31
# File 'lib/guard/standardrb.rb', line 28

def run_on_additions(paths)
  Guard::UI.info "StandardRb a file was added"
  inspect_with_standardrb(paths)
end

#run_on_modifications(paths) ⇒ Object



33
34
35
36
37
38
# File 'lib/guard/standardrb.rb', line 33

def run_on_modifications(paths)
  Guard::UI.info "StandardRb a file was modified"
  inspect_with_standardrb(paths)

  $stdout.puts paths if paths
end

#startObject



16
17
18
19
20
21
22
# File 'lib/guard/standardrb.rb', line 16

def start
  Guard::UI.info "Inspecting Ruby code style with standardrb"
  Guard::UI.info "fix = #{@options[:fix]}," +
  " all_on_start = #{@options[:all_on_start]}," +
  " progress = #{@options[:progress]}"
  run_all if @options[:all_on_start]
end