class Guard::Annotate

Public Class Methods

new(options={}) click to toggle source
Calls superclass method
# File lib/guard/annotate.rb, line 10
def initialize(options={})
  super

  options[:notify] = true if options[:notify].nil?
  options[:position] = 'before' if options[:position].nil?
  options[:tests] = false if options[:tests].nil?
  options[:factories] = true if options[:factories].nil?
  options[:serializers] = true if options[:serializers].nil?
  options[:sort] = false if options[:sort].nil?
  options[:routes] = false if options[:routes].nil?
  options[:run_at_start] = true if options[:run_at_start].nil?
  options[:show_indexes] = false if options[:show_indexes].nil?
  options[:simple_indexes] = false if options[:simple_indexes].nil?
  options[:show_foreign_keys] = false if options[:show_foreign_keys].nil?
  options[:show_migration] = false if options[:show_migration].nil?
  options[:format] = nil if options[:format].nil? or not [:bare, :markdown, :rdoc].include? options[:format].to_sym
end

Public Instance Methods

reload() click to toggle source
# File lib/guard/annotate.rb, line 36
def reload
  run_annotate if options[:run_at_start]
end
run_all() click to toggle source
# File lib/guard/annotate.rb, line 40
def run_all
  true
end
run_on_change(paths=[])
Alias for: run_on_changes
run_on_changes(paths=[]) click to toggle source
# File lib/guard/annotate.rb, line 44
def run_on_changes(paths=[])
  run_annotate
end
Also aliased as: run_on_change
start() click to toggle source
# File lib/guard/annotate.rb, line 28
def start
  run_annotate if options[:run_at_start]
end
stop() click to toggle source
# File lib/guard/annotate.rb, line 32
def stop
  true
end

Private Instance Methods

annotate_excludes() click to toggle source
# File lib/guard/annotate.rb, line 63
def annotate_excludes
  excludes = []
  excludes << 'tests' << 'fixtures' unless options[:tests]
  excludes << 'factories' unless options[:factories]
  excludes << 'serializers' unless options[:serializers]

  excludes.empty? ? '' : "--exclude #{excludes.join(',')}"
end
annotate_format() click to toggle source
# File lib/guard/annotate.rb, line 80
def annotate_format
  options[:format]
end
annotate_format?() click to toggle source
# File lib/guard/annotate.rb, line 84
def annotate_format?
  not options[:format].nil?
end
annotate_routes?() click to toggle source
# File lib/guard/annotate.rb, line 59
def annotate_routes?
  options[:routes]
end
annotate_sort_columns?() click to toggle source
# File lib/guard/annotate.rb, line 72
def annotate_sort_columns?
  options[:sort]
end
annotation_position() click to toggle source
# File lib/guard/annotate.rb, line 55
def annotation_position
  options[:position]
end
notify?() click to toggle source
# File lib/guard/annotate.rb, line 51
def notify?
  !!options[:notify]
end
run_annotate() click to toggle source
# File lib/guard/annotate.rb, line 100
def run_annotate
  Compat::UI.info 'Running annotate', :reset => true
  started_at = Time.now
  annotate_models_options, annotate_options = '', ''

  annotate_models_command = "bundle exec annotate #{annotate_excludes} -p #{annotation_position}"
  annotate_models_options += ' --sort' if annotate_sort_columns?
  annotate_models_options += ' --show-indexes' if show_indexes?
  annotate_models_options += ' --simple-indexes' if simple_indexes?
  annotate_models_options += ' --show-migration' if show_migration?
  annotate_models_options += ' --show-foreign-keys' if show_foreign_keys?
  annotate_options += " --format=#{annotate_format}" if annotate_format?

  annotate_models_command += annotate_models_options + annotate_options
  @result = system(annotate_models_command)
  Notifier::notify(@result, Time.now - started_at) if notify?

  if annotate_routes?
    started_at = Time.now
    position = if %w[after before].include? options[:routes].to_s
      options[:routes]
    else
      annotation_position
    end
    annotate_routes_command = "bundle exec annotate -r -p #{position}"

    annotate_routes_command += annotate_options
    @result = system(annotate_routes_command)
    Notifier::notify(@result, Time.now - started_at) if notify?
  end

  @result
end
show_foreign_keys?() click to toggle source
# File lib/guard/annotate.rb, line 96
def show_foreign_keys?
  options[:show_foreign_keys]
end
show_indexes?() click to toggle source
# File lib/guard/annotate.rb, line 76
def show_indexes?
  options[:show_indexes]
end
show_migration?() click to toggle source
# File lib/guard/annotate.rb, line 92
def show_migration?
  options[:show_migration]
end
simple_indexes?() click to toggle source
# File lib/guard/annotate.rb, line 88
def simple_indexes?
  options[:simple_indexes]
end