acdc 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -30,7 +30,8 @@ spec = Gem::Specification.new do |s|
30
30
  "lib/acdc/body.rb",
31
31
  "lib/acdc/element.rb",
32
32
  "lib/acdc/item.rb",
33
- "lib/acdc/parse.rb"
33
+ "lib/acdc/parse.rb",
34
+ "lib/acdc/build.rb"
34
35
  ]
35
36
  if s.respond_to? :specification_version then
36
37
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -10,8 +10,8 @@ class Boolean; end
10
10
 
11
11
  module AcDc
12
12
 
13
- DEFAULT_NAMESPACE = "example" unless defined?(AcDc::DEFAULT_NAMESPACE)
14
- VERSION = [0,5,0] unless defined?(AcDc::VERSION)
13
+ DEFAULT_NAMESPACE = "acdc" unless defined?(AcDc::DEFAULT_NAMESPACE)
14
+ VERSION = [0,5,1] unless defined?(AcDc::VERSION)
15
15
 
16
16
  if defined?(JAIL_BREAK)
17
17
  puts "AcDc is live -- Dirty Deeds!"
@@ -25,7 +25,6 @@ module AcDc
25
25
  end
26
26
 
27
27
  module ClassMethods
28
-
29
28
  def attributes
30
29
  @attributes[to_s] || []
31
30
  end
@@ -1,10 +1,62 @@
1
1
  module AcDc
2
2
  class Body
3
+
3
4
  def self.inherited(child)
4
- child.instance_variable_set("@attributes", {})
5
- child.instance_variable_set("@elements",{})
6
- end
7
- extend(ClassMethods)
5
+ attrs = @attributes.nil? ? [] : @attributes.dup
6
+ child.instance_variable_set("@attributes", attrs)
7
+ elems = @elements.nil? ? [] : @elements.dup
8
+ child.instance_variable_set("@elements", elems)
9
+ @inheritance_chain ||= []
10
+ @inheritance_chain << child
11
+ end
12
+
13
+ include(Build::ClassMethods)
14
+
8
15
  extend(Parsing)
16
+
17
+ module BodyClassMethods
18
+
19
+ def attributes
20
+ @attributes || []
21
+ end
22
+
23
+ def elements
24
+ @elements || []
25
+ end
26
+
27
+ def attribute(name, type, options={})
28
+ attribute = Attribute.new(name,type,options)
29
+ @attributes ||= []
30
+ @attributes << attribute
31
+ unless @inheritance_chain.nil?
32
+ @inheritance_chain.each { |child| child.attributes << attribute }
33
+ end
34
+ attr_accessor attribute.method_name.intern
35
+ end
36
+
37
+ def element(name, type, options={})
38
+ element = Element.new(name,type,options)
39
+ @elements ||= []
40
+ @elements << element
41
+ unless @inheritance_chain.nil?
42
+ @inheritance_chain.each { |child| child.elements << element }
43
+ end
44
+ attr_accessor element.method_name.intern
45
+ end
46
+
47
+ def tag_name(name = nil)
48
+ @tag_name = name.to_s if name
49
+ @tag_name ||= to_s.split('::')[-1].downcase
50
+ end
51
+
52
+ def namespace(namespace = nil)
53
+ @namespace = namespace if namespace
54
+ @namespace
55
+ end
56
+
57
+ end
58
+
59
+ extend(BodyClassMethods)
60
+
9
61
  end
10
62
  end
@@ -0,0 +1,35 @@
1
+ module AcDc
2
+ module Build
3
+ module ClassMethods
4
+
5
+ # Converts object to XML
6
+ # Very poor support for multiple namespaces
7
+ def acdc(root = true)
8
+ xml = Builder::XmlMarkup.new
9
+ attrs = self.class.attributes.inject({}){ |acc,attr|
10
+ acc.update(attr.method_name => send(attr.method_name.to_sym))
11
+ }
12
+ attrs.update(:xmlns => self.class.namespace) if self.class.namespace
13
+ xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" if root
14
+ xml.tag!(self.class.tag_name,attrs){ |body|
15
+ self.class.elements.each do |elem|
16
+ value = send(elem.method_name.to_sym)
17
+ if value
18
+ if elem.primitive?
19
+ body.tag! elem.method_name, value
20
+ else
21
+ body << value.acdc(false)
22
+ end
23
+ else
24
+ body.tag! elem.method_name
25
+ end
26
+ end
27
+ }
28
+ xml.target!
29
+ end
30
+ end
31
+ end
32
+
33
+ include Build::ClassMethods
34
+
35
+ 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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clint Hill
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-18 00:00:00 -07:00
12
+ date: 2009-11-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,7 @@ files:
50
50
  - lib/acdc/element.rb
51
51
  - lib/acdc/item.rb
52
52
  - lib/acdc/parse.rb
53
+ - lib/acdc/build.rb
53
54
  has_rdoc: true
54
55
  homepage: http://h3osoftware.com/acdc
55
56
  licenses: []