require 'optparse' class String def camelize self.split('_').map {|w| w.capitalize}.join end end options = {} OptionParser.new do |opts| opts.banner = "Usage: #{__FILE__} [options]" opts.on("-m", "--model-name NAME", "Model Name") { |v| options[:model] = v } opts.on("-c", "--collection-name NAME", "Collection Name") { |v| options[:collection] = v } opts.on("-M", "--methods a:href,b:href,c:href", Array, "List of methods to be defined and href to the method") { |v| options[:methods] = v.map { |a| a.split(':') } } opts.on("-a", "--attributes name:alias,other_name:other_alias", Array, "List of attributes to be defined") { |v| options[:attributes] = v.map { |a| a.split(':') } } end.parse! if options[:methods] methods = options[:methods].map do |m| m = < service, :href => "#{m[1]}") end METHOD end.join("\n ") end if options[:attributes] attributes = options[:attributes].map do |a| a = "attribute :#{a[0]}, :aliases => :#{a[1] || a[0].camelize}" end.join("\n ") end collection_file = "#{File.expand_path(File.dirname(__FILE__))}/models/compute/#{options[:collection]}.rb" model_file = "#{File.expand_path(File.dirname(__FILE__))}/models/compute/#{options[:model]}.rb" collection_request_file = "#{File.expand_path(File.dirname(__FILE__))}/requests/compute/get_#{options[:collection]}.rb" model_request_file = "#{File.expand_path(File.dirname(__FILE__))}/requests/compute/get_#{options[:model]}.rb" collection = <