Class: Gemi::Options
- Inherits:
-
Object
- Object
- Gemi::Options
- Defined in:
- lib/gemi/options.rb
Defined Under Namespace
Classes: YamlGivenError
Constant Summary collapse
- TYPES =
{ "-u" => :uninstall, "--uninstall" => :uninstall, "-n" => :update, "--update" => :update, "-c" => :clean, "--clean" => :clean, }
Instance Attribute Summary collapse
-
#confpath ⇒ Object
readonly
Returns the value of attribute confpath.
-
#gem_names ⇒ Object
readonly
Returns the value of attribute gem_names.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#yamls ⇒ Object
readonly
Returns the value of attribute yamls.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(argv) ⇒ Options
constructor
A new instance of Options.
- #parse(argv) ⇒ Object
Constructor Details
#initialize(argv) ⇒ Options
Returns a new instance of Options.
10 11 12 |
# File 'lib/gemi/options.rb', line 10 def initialize(argv) @confpath, @type, @gem_names, @yamls = parse(argv) end |
Instance Attribute Details
#confpath ⇒ Object (readonly)
Returns the value of attribute confpath.
13 14 15 |
# File 'lib/gemi/options.rb', line 13 def confpath @confpath end |
#gem_names ⇒ Object (readonly)
Returns the value of attribute gem_names.
13 14 15 |
# File 'lib/gemi/options.rb', line 13 def gem_names @gem_names end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/gemi/options.rb', line 13 def type @type end |
#yamls ⇒ Object (readonly)
Returns the value of attribute yamls.
13 14 15 |
# File 'lib/gemi/options.rb', line 13 def yamls @yamls end |
Class Method Details
.parse(argv) ⇒ Object
6 7 8 |
# File 'lib/gemi/options.rb', line 6 def self.parse(argv) new(argv) end |
Instance Method Details
#empty? ⇒ Boolean
15 16 17 |
# File 'lib/gemi/options.rb', line 15 def empty? @yamls.empty? and @gem_names.empty? end |
#parse(argv) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gemi/options.rb', line 28 def parse(argv) confpath = GEMIRC if %w(-h --help).any?{|o| argv.include?(o)} return confpath, nil, [], [] end if %w(-r --rc).include?(argv.first) confpath = argv[1] if not File.exist?(confpath) raise ConfNotFound, "config file not found in #{confpath}" exit end argv.shift argv.shift end case when TYPES.key?(argv.first) type = TYPES[argv.first] args = argv[1..-1] when argv.first == "--" type = nil args = argv[1..-1] else # gem names only type = :install args = argv end case type when nil # verbatim(--) yamls = [] gem_names = args else yamls, gem_names = args.partition{|s| s =~ REXP_YAML} if [:update, :clean].include?(type) and not yamls.empty? raise YamlGivenError, "You cannot give yaml files with #{argv.first}" end end return confpath, type, gem_names, yamls end |