Class: Ebay::Schema::ApiSchemaImporter

Inherits:
Object
  • Object
show all
Includes:
Inflections, RubyClassGeneratorHelper
Defined in:
lib/ebay/schema/mapper/ebay_schema_importer.rb

Constant Summary collapse

Ignores =
[ 'RecipientRelationCodeType' ]

Constants included from Inflections

Inflections::DOWNCASE_TOKENS, Inflections::NAME_MAPPINGS, Inflections::UPCASE_TOKENS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inflections

#downcase_first_character, #ebay_camelize, #ebay_underscore, #underscore, #upcase_first_character

Constructor Details

#initialize(schema, data) ⇒ ApiSchemaImporter

Returns a new instance of ApiSchemaImporter.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ebay/schema/mapper/ebay_schema_importer.rb', line 13

def initialize(schema, data)
  @xml = XML::Parser.string(data).parse.root
  
  @elements = schema.collect_elements
  @attributes = schema.collect_attributes
  
  # Only want the simple types that have an enumeration (codes)
  @simple_types = schema.collect_simpletypes
  
  @code_types = @simple_types.reject{ |e| e.restriction.enumeration.empty? || Ignores.include?(e.name.name) }

  @complex_types = schema.collect_complextypes
  
  @fault_types = nil
  if schema.respond_to?(:collect_faulttypes)
    @fault_types = schema.collect_faulttypes
  end

  @unused_files = []
end

Instance Attribute Details

#complex_typesObject (readonly)

Returns the value of attribute complex_types.



9
10
11
# File 'lib/ebay/schema/mapper/ebay_schema_importer.rb', line 9

def complex_types
  @complex_types
end

#simple_typesObject (readonly)

Returns the value of attribute simple_types.



9
10
11
# File 'lib/ebay/schema/mapper/ebay_schema_importer.rb', line 9

def simple_types
  @simple_types
end

Instance Method Details

#export_classes(base_dir) ⇒ Object



34
35
36
37
# File 'lib/ebay/schema/mapper/ebay_schema_importer.rb', line 34

def export_classes(base_dir)
  @base_dir = base_dir
  write_classes
end

#write_classesObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ebay/schema/mapper/ebay_schema_importer.rb', line 39

def write_classes
  
  complex_classes = @complex_types.collect do |type|
    puts "Generating class for #{type.name.name}"
    RubyClassGenerator.new(type, @simple_types, @complex_types, @xml)
  end
  
  simple_classes = @code_types.collect do |type|
    puts "Generating simple type class for #{type.name.name}"
    RubyClassGenerator.new(type, @simple_types, @complex_types, @xml)
  end
 
  
  write_requires_files(complex_classes)
  write_class_files(complex_classes) 

  write_class_files(simple_classes) 
  write_requires_file('types', simple_classes)

  remove_unused_files
end