Class: Ebay::Schema::RubyClassGenerator

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

Constant Summary

BuiltInTypes =
['string', 'anyURI', 'int', 'float', 'long', 'dateTime', 'boolean', 'token', 'decimal', 'duration', 'double']

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

- (RubyClassGenerator) initialize(type, simple_types, complex_types, xml)

Returns a new instance of RubyClassGenerator



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 10

def initialize(type, simple_types, complex_types, xml)
  @xml = xml
          
  @indent = 2
  @type = type
  @simple_types, @complex_types = simple_types, complex_types
  @ignored_classes = []
  # node = @xml.find_first("xs:complexType[@name='#{xml_type}']/xs:annotation/xs:documentation")
  # @documentation = (node && node.content) || ''
  find_base
end

Instance Attribute Details

- (Object) documentation (readonly)

Returns the value of attribute documentation



8
9
10
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 8

def documentation
  @documentation
end

- (Object) ignored_classes (readonly)

Returns the value of attribute ignored_classes



8
9
10
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 8

def ignored_classes
  @ignored_classes
end

Instance Method Details

- (Boolean) abstract?

Returns:

  • (Boolean)


87
88
89
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 87

def abstract?
  abstract_request? || abstract_response?
end

- (Boolean) abstract_request?

Returns:

  • (Boolean)


91
92
93
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 91

def abstract_request?
  name == 'AbstractRequest'
end

- (Boolean) abstract_response?

Returns:

  • (Boolean)


95
96
97
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 95

def abstract_response?
  name == 'AbstractResponse'
end

- (Object) base_class



75
76
77
78
79
80
81
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 75

def base_class
  if abstract_request? || abstract_response?
    'Base'
  else
    trim_type(@base.name.name) unless @base.nil?
  end
end

- (Boolean) complex?

Returns:

  • (Boolean)


30
31
32
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 30

def complex?
  @type.is_a?(WSDL::XMLSchema::ComplexType)
end

- (Boolean) derived_request?

Returns:

  • (Boolean)


117
118
119
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 117

def derived_request?
  base_class == 'AbstractRequest'
end

- (Boolean) derived_response?

Returns:

  • (Boolean)


121
122
123
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 121

def derived_response?
  base_class == 'AbstractResponse'
end

- (Object) generate_class



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
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 38

def generate_class
  
  template = simple? ? 'value' : 'base'
  base = ClassTemplate.new(template).load
 
  customization = ClassTemplate.new(ebay_underscore(name))
  customization.load if customization.exists?
 
  if request? || response?
    class_name = ebay_camelize(name).gsub(/(Request|Response)$/, '')
  else
    class_name = ebay_camelize(name)
  end

  element_name = ebay_camelize(name)
  
    
  class_def = ClassDefinition.new(class_name, element_name, module_name, base_class)
  nodes = generate_nodes

  class_def.nodes.concat nodes
  
  class_def.customization = customization.render(class_def) if customization.exists?

  # class_def.documentation = @documentation
  
  base.render(class_def)
end

- (Object) module_name



99
100
101
102
103
104
105
106
107
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 99

def module_name
  if request?
    'Requests'
  elsif response?
    'Responses'
  else
    'Types'
  end
end

- (Object) name



71
72
73
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 71

def name
  @name ||= trim_type(@type.name.name)
end

- (Boolean) request?

Returns:

  • (Boolean)


109
110
111
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 109

def request?
  abstract_request? || derived_request?
end

- (Boolean) response?

Returns:

  • (Boolean)


113
114
115
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 113

def response?
  abstract_response? || derived_response?
end

- (Boolean) simple?

Returns:

  • (Boolean)


26
27
28
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 26

def simple?
  @type.is_a?(WSDL::XMLSchema::SimpleType)
end

- (Boolean) simple_content?

Returns:

  • (Boolean)


22
23
24
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 22

def simple_content?
  @type.simplecontent
end

- (Object) to_s



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

def to_s
  @class_def ||= generate_class
end

- (Boolean) type?

Returns:

  • (Boolean)


83
84
85
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 83

def type?
  !(derived_request? || derived_response?)
end

- (Object) xml_type



67
68
69
# File 'lib/ebay/schema/mapper/ruby_class_generator.rb', line 67

def xml_type
  @type.name.name
end