class OData::Model::CLI::GeneratorConfiguration

Represents the configuration for the command-line tool responsible for model generation. @api private

Attributes

options[R]
service[R]

Public Class Methods

new(options) click to toggle source
# File lib/odata/model/cli/generator_configuration.rb, line 11
def initialize(options)
  @options = options
  @service = OData::Service.open(service_url, handle_auth_options)
end
validate_service_url(opts) click to toggle source
# File lib/odata/model/cli/generator_configuration.rb, line 21
def self.validate_service_url(opts)
  unless opts[:service_url]
    puts 'You must supply a service_url (-s, --service_url=)'
    exit(1)
  end
end

Public Instance Methods

generate() click to toggle source
# File lib/odata/model/cli/generator_configuration.rb, line 16
def generate
  template = ModelTemplate.new(class_name, service_name, properties)
  template.render
end

Private Instance Methods

class_name() click to toggle source
# File lib/odata/model/cli/generator_configuration.rb, line 30
def class_name
  options[:model_name] || entity_set.type
end
entity_set() click to toggle source
# File lib/odata/model/cli/generator_configuration.rb, line 51
def entity_set
  service[options[:entity_set]]
end
handle_auth_options() click to toggle source
# File lib/odata/model/cli/generator_configuration.rb, line 55
def handle_auth_options
  service_options = {}
  if options[:username] && options[:password]
    service_options[:typhoeus] = {
        username: options[:username],
        password: options[:password]
    }
    if options[:auth_type]
      auth_type = options[:auth_type].to_sym
      service_options[:typhoeus][:httpauth] = auth_type
    end
  end
  service_options
end
properties() click to toggle source
# File lib/odata/model/cli/generator_configuration.rb, line 34
def properties
  if options[:properties]
    Hash[options[:properties].collect {|property_set| property_set.split(':')}]
  else
    properties = service.properties_for(entity_set.type)
    Hash[properties.collect {|k,v| [k, nil]}]
  end
end
service_name() click to toggle source
# File lib/odata/model/cli/generator_configuration.rb, line 43
def service_name
  options[:service_name] || service_url
end
service_url() click to toggle source
# File lib/odata/model/cli/generator_configuration.rb, line 47
def service_url
  options[:service_url]
end