Class: Guard::Rubybeautify

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rubybeautify

Returns a new instance of Rubybeautify.



8
9
10
11
12
13
14
15
16
# File 'lib/guard/rubybeautify.rb', line 8

def initialize(options = {})
  super
    @last_run = 0
  @options = {
      grace_period: 5,
    count: 1,
    style: :tabs
  }.merge(options)
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



6
7
8
# File 'lib/guard/rubybeautify.rb', line 6

def count
  @count
end

#grace_periodObject

Returns the value of attribute grace_period.



6
7
8
# File 'lib/guard/rubybeautify.rb', line 6

def grace_period
  @grace_period
end

#styleObject

Returns the value of attribute style.



6
7
8
# File 'lib/guard/rubybeautify.rb', line 6

def style
  @style
end

Instance Method Details

#run_on_modifications(paths) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/guard/rubybeautify.rb', line 18

def run_on_modifications(paths)
  if @last_run + options[:grace_period] < Time.now.to_i
    paths.each do |file|
      Compat::UI.info "Ruby beautify executed against: #{Guard::Compat::UI.color file, :green}"
      `ruby-beautify #{file} -c #{options[:count]} --#{options[:style].to_s}`
    end
      # make sure to set a real last run if we did a beautify.
    @last_run = Time.now.to_i
    else
    Compat::UI.debug "Ruby beautify skipped on #{paths.join}"
  end
end