Class: AnnotateRb::Parser
- Inherits:
-
Object
- Object
- AnnotateRb::Parser
- Defined in:
- lib/annotate_rb/parser.rb
Overview
Class for handling command line arguments
Constant Summary collapse
- BANNER_STRING =
<<~BANNER.freeze Usage: annotaterb [command] [options] Commands: models [options] routes [options] help version BANNER
- DEFAULT_OPTIONS =
{ target_action: :do_annotations, exit: false }.freeze
- ANNOTATION_POSITIONS =
%w[before top after bottom].freeze
- FILE_TYPE_POSITIONS =
%w[position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer].freeze
- EXCLUSION_LIST =
%w[tests fixtures factories serializers].freeze
- FORMAT_TYPES =
%w[bare rdoc yard markdown].freeze
- COMMAND_MAP =
{ "models" => :models, "routes" => :routes, "version" => :version, "help" => :help }.freeze
Class Method Summary collapse
-
.parse(args, existing_options) ⇒ Object
rubocop:disable Metrics/ClassLength.
Instance Method Summary collapse
-
#initialize(args, existing_options) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #remaining_args ⇒ Object
Constructor Details
#initialize(args, existing_options) ⇒ Parser
Returns a new instance of Parser.
37 38 39 40 41 42 43 |
# File 'lib/annotate_rb/parser.rb', line 37 def initialize(args, ) @args = args.clone = DEFAULT_OPTIONS.dup @options = .merge() @commands = [] @options[:original_args] = args.clone end |
Class Method Details
.parse(args, existing_options) ⇒ Object
rubocop:disable Metrics/ClassLength
6 7 8 |
# File 'lib/annotate_rb/parser.rb', line 6 def self.parse(args, ) new(args, ).parse end |
Instance Method Details
#parse ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/annotate_rb/parser.rb', line 45 def parse parse_command(@args) parser.parse!(@args) act_on_command @options end |
#remaining_args ⇒ Object
55 56 57 58 59 |
# File 'lib/annotate_rb/parser.rb', line 55 def remaining_args # `@args` gets modified throughout the lifecycle of this class. # It starts as a shallow clone of ARGV, then arguments matching commands and options are removed in #parse @args end |