Sha256: 70ced0cbca960b3497bcd19bd7ec252a87ca13d9fc3be53cf51fd64ebc5ee0ac

Contents?: true

Size: 827 Bytes

Versions: 11

Compression:

Stored size: 827 Bytes

Contents

# encoding: utf-8

class SimpleTemplater
  module ArgvParsingMixin
    def parse!
      self.inject(Hash.new) do |options, argument|
        case argument
        when /^--no-([^=]+)$/ # --no-git-repository
          options[$1.gsub("-", "_").to_sym] = false
        when /^--([^=]+)$/    # --git-repository
          options[$1.gsub("-", "_").to_sym] = true
        when /^--([^=]+)=([^,]+)$/ # --controller=post
          key, value = $1, $2
          options[key.gsub("-", "_").to_sym] = value.dup
        when /^--([^=]+)=(.+)$/    # --controllers=posts,comments
          key, value = $1, $2
          options[key.gsub("-", "_").to_sym] = value.split(",")
        else
          raise "Parsing failed on: #{argument}"
        end
        options
      end
    end
  end
end

ARGV.extend(SimpleTemplater::ArgvParsingMixin)

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
simple-templater-0.0.1.6 lib/simple-templater/argv_parsing.rb
simple-templater-0.0.1.5 lib/simple-templater/argv_parsing.rb
simple-templater-0.0.1.4 lib/simple-templater/argv_parsing.rb
simple-templater-0.0.1.3 lib/simple-templater/argv_parsing.rb
simple-templater-0.2.pre lib/simple-templater/argv_parsing.rb
simple-templater-0.0.1.2 lib/simple-templater/argv_parsing.rb
simple-templater-0.0.1.1 lib/simple-templater/argv_parsing.rb
rango-0.0.6 vendor/simple-templater/lib/simple-templater/argv_parsing.rb
rango-0.1.pre vendor/simple-templater/lib/simple-templater/argv_parsing.rb
simple-templater-0.1.pre lib/simple-templater/argv_parsing.rb
simple-templater-0.0.1 lib/simple-templater/argv_parsing.rb