acdc 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/lib/acdc.rb +16 -11
- data/lib/acdc/body.rb +3 -2
- data/lib/acdc/item.rb +0 -2
- data/lib/acdc/mapping.rb +2 -1
- data/lib/acdc/parse.rb +17 -49
- metadata +2 -2
data/README
CHANGED
@@ -25,7 +25,7 @@ marshaling those objects from XML a breeze.
|
|
25
25
|
|
26
26
|
jack = acdc("<thejack shes_got='big-balls'><big_balls>I've got big balls</big_balls></thejack>")
|
27
27
|
puts jack.shes_got
|
28
|
-
=> "
|
28
|
+
=> "big-balls"
|
29
29
|
puts jack.big_balls
|
30
30
|
=> "I've got big balls"
|
31
31
|
puts jack.acdc
|
data/lib/acdc.rb
CHANGED
@@ -10,19 +10,24 @@ class Boolean; end
|
|
10
10
|
|
11
11
|
module AcDc
|
12
12
|
|
13
|
-
DEFAULT_NAMESPACE = "acdc"
|
14
|
-
VERSION = [0,
|
13
|
+
DEFAULT_NAMESPACE = "acdc"
|
14
|
+
VERSION = [0,7,0]
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
def self.parseable_constants
|
17
|
+
@parseables ||= []
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
require File.join(
|
24
|
-
require File.join(
|
25
|
-
require File.join(
|
26
|
-
require File.join(
|
27
|
-
require File.join(
|
28
|
-
require File.join(
|
22
|
+
dir = File.dirname(__FILE__)
|
23
|
+
require File.join(dir, 'acdc/mapping')
|
24
|
+
require File.join(dir, 'acdc/build')
|
25
|
+
require File.join(dir, 'acdc/parse')
|
26
|
+
require File.join(dir, 'acdc/item')
|
27
|
+
require File.join(dir, 'acdc/attribute')
|
28
|
+
require File.join(dir, 'acdc/element')
|
29
|
+
require File.join(dir, 'acdc/body')
|
30
|
+
|
31
|
+
class Object
|
32
|
+
include AcDc::Parsing
|
33
|
+
end
|
data/lib/acdc/body.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module AcDc
|
2
2
|
class Body
|
3
3
|
|
4
|
-
include
|
5
|
-
include
|
4
|
+
include Mapping
|
5
|
+
include Building
|
6
6
|
|
7
7
|
def self.inherited(child)
|
8
8
|
attrs = @attributes.nil? ? {} : @attributes.dup
|
@@ -11,6 +11,7 @@ module AcDc
|
|
11
11
|
child.instance_variable_set("@elements", elems)
|
12
12
|
@inheritance_chain ||= []
|
13
13
|
@inheritance_chain << child
|
14
|
+
AcDc.parseable_constants << child
|
14
15
|
end
|
15
16
|
|
16
17
|
end
|
data/lib/acdc/item.rb
CHANGED
@@ -68,10 +68,8 @@ module AcDc
|
|
68
68
|
if options[:namespace] == false
|
69
69
|
namespace = nil
|
70
70
|
elsif options[:namespace]
|
71
|
-
# from an element definition
|
72
71
|
namespace = "#{DEFAULT_NAMESPACE}:#{options[:namespace]}"
|
73
72
|
elsif self.namespace
|
74
|
-
# this node has a custom namespace (that is present in the doc)
|
75
73
|
namespace = "#{DEFAULT_NAMESPACE}:#{self.namespace}"
|
76
74
|
end
|
77
75
|
|
data/lib/acdc/mapping.rb
CHANGED
data/lib/acdc/parse.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module AcDc
|
2
2
|
module Parsing
|
3
|
-
|
3
|
+
|
4
4
|
def acdc(xml, options={})
|
5
|
-
|
6
5
|
if xml.is_a?(XML::Node)
|
7
6
|
node = xml
|
8
7
|
else
|
@@ -12,20 +11,20 @@ module AcDc
|
|
12
11
|
node = XML::Parser.string(xml).parse.root
|
13
12
|
end
|
14
13
|
end
|
15
|
-
|
14
|
+
# This constantize is a global scope constantize.
|
15
|
+
# It will use AcDc#parseable_constants to detect which class
|
16
|
+
# is being parsed.
|
16
17
|
klass = constantize(node.name)
|
17
|
-
|
18
|
+
if klass.nil?
|
19
|
+
raise Exception.new("Uh Oh ... Live Wire! Couldn't parse #{node.name}.")
|
20
|
+
end
|
18
21
|
root = node.name.downcase == klass.tag_name
|
19
|
-
|
20
22
|
namespace = node.namespaces.default
|
21
23
|
namespace = "#{DEFAULT_NAMESPACE}:#{namespace}" if namespace
|
22
|
-
|
23
24
|
xpath = root ? '/' : './/'
|
24
25
|
xpath += "#{DEFAULT_NAMESPACE}:" if namespace
|
25
26
|
xpath += node.name
|
26
|
-
|
27
27
|
nodes = node.find(xpath, Array(namespace))
|
28
|
-
|
29
28
|
collection = nodes.collect do |n|
|
30
29
|
obj = klass.new
|
31
30
|
klass.attributes.each do |attr|
|
@@ -36,9 +35,7 @@ module AcDc
|
|
36
35
|
end
|
37
36
|
obj
|
38
37
|
end
|
39
|
-
|
40
38
|
nodes = nil
|
41
|
-
|
42
39
|
if options[:single] || root
|
43
40
|
collection.first
|
44
41
|
else
|
@@ -46,45 +43,16 @@ module AcDc
|
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
constant
|
60
|
-
else
|
61
|
-
type
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class Module
|
69
|
-
|
70
|
-
def hierarchy
|
71
|
-
name.split('::').inject([Object]) {|hierarchy,name|
|
72
|
-
hierarchy << hierarchy.last.const_get(name)
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
def all_class_names
|
77
|
-
class_names = []
|
78
|
-
constants.each do |const|
|
79
|
-
constant = const_get(const)
|
80
|
-
case constant
|
81
|
-
when Class
|
82
|
-
class_names << constant.to_s.split('::',2)[1]
|
83
|
-
when Module
|
84
|
-
class_names += constant.all_class_names
|
85
|
-
end
|
46
|
+
private
|
47
|
+
def constantize(type)
|
48
|
+
# I'm using a separate store for constants because of the fact at
|
49
|
+
# runtime during parsing we will simply get a tag name to start with.
|
50
|
+
# It won't be in a form we could use to detect a constant normally.
|
51
|
+
# Also - this way provides a cleaner check for the tag_name feature.
|
52
|
+
AcDc.parseable_constants.detect{ |const|
|
53
|
+
const.name.downcase =~ /#{type.downcase}/ || const.tag_name == type
|
54
|
+
}
|
86
55
|
end
|
87
|
-
|
56
|
+
|
88
57
|
end
|
89
|
-
|
90
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acdc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clint Hill
|
@@ -78,6 +78,6 @@ rubyforge_project:
|
|
78
78
|
rubygems_version: 1.3.5
|
79
79
|
signing_key:
|
80
80
|
specification_version: 3
|
81
|
-
summary: acdc 0.
|
81
|
+
summary: acdc 0.7.0
|
82
82
|
test_files: []
|
83
83
|
|