Module: WellsFargo::Schema

Defined in:
lib/wells_fargo/schema.rb

Constant Summary collapse

Schema =
File.expand_path File.join(File.dirname(__FILE__), '..', 'schema.xml')
ElementDir =
File.expand_path File.join(File.dirname(__FILE__), 'elements')
NameMapFile =
File.expand_path File.join(ElementDir, 'name_map.rb')

Class Method Summary collapse

Class Method Details

.generate_element_filesObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
# File 'lib/wells_fargo/schema.rb', line 15

def generate_element_files
  @name_map = {}
  schema do |definition|
    class_name = definition.attributes['name'].value
    file = File.join(ElementDir, "#{WellsFargo.underscore class_name}.rb")
    puts "Writing #{class_name} => #{File.basename file}"
    File.open(file, 'w') do |f|
      f.write "module WellsFargo\n  class Element\n    class \#{class_name} < WellsFargo::Element\n\#{(definition / 'xsd|attribute').map do |attr|\n\n  name = attr.attributes['name'].value.gsub(/\\s+/, '')\n  @name_map[WellsFargo.underscore name] = name\n  name = WellsFargo.underscore name\n\n  use = attr.attributes['use']\n\n  if use && 'required' == use.value\n    \"      required_attribute :\#{name}\"\n  else\n    \"      attribute :\#{name}\"\n  end\nend.join(\"\\n\")}\n\n\#{(definition / 'xsd|element').map do |element|\n\n  name = (element.attributes['ref'] || element.attributes['name']).value.gsub(/\\s+/, '')\n  @name_map[WellsFargo.underscore name] = name\n  name = WellsFargo.underscore name\n  options = {}\n  limit = ((max = element.attributes['maxOccurs']) && max && max.value).to_i\n  options[:limit] = limit if limit > 0\n  options[:simple] = true if element.attributes['ref'].nil?\n\n  if {} == options\n    \"      child :\#{name}\"\n  else\n    \"      child :\#{name}, :limit => \#{limit}\"\n  end\nend.join(\"\\n\")}\n    end\n  end\nend\n"  
    end
    save_name_map
  end
end

.NameMapObject



9
10
11
12
13
# File 'lib/wells_fargo/schema.rb', line 9

def NameMap
  Marshal.load File.read(NameMapFile)
rescue Errno::ENOENT
  {}
end

.schemaObject



66
67
68
69
70
# File 'lib/wells_fargo/schema.rb', line 66

def schema
  (load_schema / 'xsd|schema > xsd|element').each do |element|
    yield element
  end
end