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 before_doc].freeze
- AFTER_POSITIONS =
%w[after bottom].freeze
- DOC_AWARE_POSITIONS =
%w[before_doc].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.
39 40 41 42 43 44 45 |
# File 'lib/annotate_rb/parser.rb', line 39 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
47 48 49 50 51 52 53 54 55 |
# File 'lib/annotate_rb/parser.rb', line 47 def parse parse_command(@args) parser.parse!(@args) act_on_command @options end |
#remaining_args ⇒ Object
57 58 59 60 61 |
# File 'lib/annotate_rb/parser.rb', line 57 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 |