Class: CukeTagger::Tagger
- Inherits:
-
Object
- Object
- CukeTagger::Tagger
- Defined in:
- lib/cuketagger/tagger.rb
Constant Summary collapse
- USAGE =
"#{File.basename $0} [-v|--version] [-f|--force] [add|remove|replace]:TAG[:REPLACEMENT] [FILE[:LINE]]+"
Class Method Summary collapse
Instance Method Summary collapse
- #execute(args) ⇒ Object
- #process(feature, element, tag_names) ⇒ Object
- #should_alter?(feature, element) ⇒ Boolean
Class Method Details
.execute(args) ⇒ Object
5 6 7 |
# File 'lib/cuketagger/tagger.rb', line 5 def self.execute(args) new.execute(args) end |
Instance Method Details
#execute(args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cuketagger/tagger.rb', line 9 def execute(args) abort(USAGE) if args.empty? || args.first =~ /^(-h|--help)$/ opts = {:dry_run => true, :source => true} args.each do |arg| case arg when /^-v|--version$/ puts CukeTagger::Version when /^(.+?\.feature)(:\d+)?$/ add_feature($1, $2.to_s) when /^(add|remove):(.+?)$/ alterations << [$1.to_sym, $2] when /^(replace):(.+?):(.+)$/ alterations << [$1.to_sym, [$2, $3]] when /^(-f|--force)$/ opts[:autoformat] = "." opts[:source] = false Term::ANSIColor.coloring = false else abort(USAGE) end end formatter = Cucumber::Formatter::Pretty.new(step_mother, $stdout, opts) formatter.extend(TagFormatter) formatter.tagger = self walker = Cucumber::Ast::TreeWalker.new(step_mother, [formatter], opts) walker.visit_features features end |
#process(feature, element, tag_names) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cuketagger/tagger.rb', line 40 def process(feature, element, tag_names) return unless should_alter?(feature, element) alterations.each do |op, tag_name| case op when :add tag_names.push "@#{tag_name}" when :remove tag_names.delete "@#{tag_name}" when :replace idx = tag_names.index "@#{tag_name.first}" if idx.nil? $stderr.puts "expected #{tag_name.first.inspect} at #{file_and_line_for(feature, element).join(":")}, skipping" else tag_names[idx] = "@#{tag_name.last}" end end end end |
#should_alter?(feature, element) ⇒ Boolean
60 61 62 63 |
# File 'lib/cuketagger/tagger.rb', line 60 def should_alter?(feature, element) fl = file_and_line_for(feature, element) features_to_change.include? fl end |