acdc 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,55 +11,15 @@ class Boolean; end
11
11
  module AcDc
12
12
 
13
13
  DEFAULT_NAMESPACE = "acdc" unless defined?(AcDc::DEFAULT_NAMESPACE)
14
- VERSION = [0,5,1] unless defined?(AcDc::VERSION)
14
+ VERSION = [0,6,0] unless defined?(AcDc::VERSION)
15
15
 
16
16
  if defined?(JAIL_BREAK)
17
17
  puts "AcDc is live -- Dirty Deeds!"
18
18
  end
19
-
20
- def self.included(base)
21
- base.instance_variable_set("@attributes",{})
22
- base.instance_variable_set("@elements",{})
23
- base.extend(ClassMethods)
24
- base.extend(Parsing)
25
- end
26
-
27
- module ClassMethods
28
- def attributes
29
- @attributes[to_s] || []
30
- end
31
-
32
- def elements
33
- @elements[to_s] || []
34
- end
35
-
36
- def attribute(name, type, options={})
37
- attribute = Attribute.new(name,type,options)
38
- @attributes[to_s] ||= []
39
- @attributes[to_s] << attribute
40
- attr_accessor attribute.method_name.intern
41
- end
42
-
43
- def element(name, type, options={})
44
- element = Element.new(name,type,options)
45
- @elements[to_s] ||= []
46
- @elements[to_s] << element
47
- attr_accessor element.method_name.intern
48
- end
49
-
50
- def tag_name(name = nil)
51
- @tag_name = name.to_s if name
52
- @tag_name ||= to_s.split('::')[-1].downcase
53
- end
54
-
55
- def namespace(namespace = nil)
56
- @namespace = namespace if namespace
57
- @namespace
58
- end
59
-
60
- end
61
19
 
62
20
  end
21
+
22
+ require File.join(File.dirname(__FILE__), 'acdc/mapping')
63
23
  require File.join(File.dirname(__FILE__), 'acdc/build')
64
24
  require File.join(File.dirname(__FILE__), 'acdc/parse')
65
25
  require File.join(File.dirname(__FILE__), 'acdc/item')
@@ -1,62 +1,17 @@
1
1
  module AcDc
2
2
  class Body
3
3
 
4
+ include(Mapping)
5
+ include(Building)
6
+
4
7
  def self.inherited(child)
5
- attrs = @attributes.nil? ? [] : @attributes.dup
8
+ attrs = @attributes.nil? ? {} : @attributes.dup
6
9
  child.instance_variable_set("@attributes", attrs)
7
- elems = @elements.nil? ? [] : @elements.dup
10
+ elems = @elements.nil? ? {} : @elements.dup
8
11
  child.instance_variable_set("@elements", elems)
9
12
  @inheritance_chain ||= []
10
13
  @inheritance_chain << child
11
14
  end
12
-
13
- include(Build::ClassMethods)
14
-
15
- extend(Parsing)
16
-
17
- module BodyClassMethods
18
15
 
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
-
61
16
  end
62
17
  end
@@ -1,35 +1,31 @@
1
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
2
+ module Building
3
+
4
+ # Converts object to XML
5
+ # Very poor support for multiple namespaces
6
+ def acdc(root = true)
7
+ xml = Builder::XmlMarkup.new
8
+ attrs = self.class.attributes.inject({}){ |acc,attr|
9
+ acc.update(attr.method_name => send(attr.method_name.to_sym))
10
+ }
11
+ attrs.update(:xmlns => self.class.namespace) if self.class.namespace
12
+ xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" if root
13
+ xml.tag!(self.class.tag_name,attrs){ |body|
14
+ self.class.elements.each do |elem|
15
+ value = send(elem.method_name.to_sym)
16
+ if value
17
+ if elem.primitive?
18
+ body.tag! elem.method_name, value
23
19
  else
24
- body.tag! elem.method_name
20
+ body << value.acdc(false)
25
21
  end
22
+ else
23
+ body.tag! elem.method_name
26
24
  end
27
- }
28
- xml.target!
29
- end
25
+ end
26
+ }
27
+ xml.target!
30
28
  end
31
- end
32
-
33
- include Build::ClassMethods
34
-
29
+
30
+ end
35
31
  end
@@ -0,0 +1,62 @@
1
+ module AcDc
2
+ module Mapping
3
+
4
+ def self.included(base)
5
+ base.instance_variable_set("@attributes",{})
6
+ base.instance_variable_set("@elements",{})
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def attributes
12
+ @attributes[to_s] || []
13
+ end
14
+
15
+ def elements
16
+ @elements[to_s] || []
17
+ end
18
+
19
+ def attribute(name, type, options={})
20
+ attribute = Attribute.new(name,type,options)
21
+ @attributes[to_s] ||= []
22
+ @attributes[to_s] << attribute
23
+ unless @inheritance_chain.nil?
24
+ @inheritance_chain.each { |child| child.attribute(name,type,options) }
25
+ end
26
+ make_accessor(attribute)
27
+ end
28
+
29
+ def element(name, type, options={})
30
+ element = Element.new(name,type,options)
31
+ @elements[to_s] ||= []
32
+ @elements[to_s] << element
33
+ unless @inheritance_chain.nil?
34
+ @inheritance_chain.each { |child| child.element(name,type,options) }
35
+ end
36
+ make_accessor(element)
37
+ end
38
+
39
+ def tag_name(name = nil)
40
+ @tag_name = name.to_s if name
41
+ @tag_name ||= to_s.split('::')[-1].downcase
42
+ end
43
+
44
+ def namespace(namespace = nil)
45
+ @namespace = namespace if namespace
46
+ @namespace
47
+ end
48
+
49
+ private
50
+ def make_accessor(item)
51
+ safe_name = item.name.tr('-','_')
52
+ if instance_methods.include?(safe_name)
53
+ name = "#{item.element? ? "element_" : "attribute_"}#{safe_name}"
54
+ item.name = name
55
+ end
56
+ attr_accessor item.method_name.intern
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
@@ -50,10 +50,11 @@ module AcDc
50
50
 
51
51
  def constantize(type)
52
52
  if type.is_a?(String)
53
- names = type.split('::')
54
53
  constant = Object
55
- names.each do |name|
56
- constant = const_defined?(name) ? const_get(name) : const_missing(name)
54
+ all_class_names.each do |name|
55
+ if name.downcase == type.downcase
56
+ constant = const_get(name)
57
+ end
57
58
  end
58
59
  constant
59
60
  else
@@ -62,4 +63,28 @@ module AcDc
62
63
  end
63
64
 
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
86
+ end
87
+ class_names.uniq
88
+ end
89
+
65
90
  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.1
4
+ version: 0.6.0
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-19 00:00:00 -07:00
12
+ date: 2009-09-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.1.2
34
34
  version:
35
- description: " This is a little xml-to-object-to-xml library that gets Dirty Deeds Done Dirt Cheap. \n"
35
+ description: This is a little xml-to-object-to-xml library that gets Dirty Deeds Done Dirt Cheap.
36
36
  email: clint.hill@h3osoftware.com
37
37
  executables: []
38
38
 
@@ -41,21 +41,21 @@ extensions: []
41
41
  extra_rdoc_files: []
42
42
 
43
43
  files:
44
- - LICENSE
45
- - README
46
- - Rakefile
47
- - lib/acdc.rb
48
44
  - lib/acdc/attribute.rb
49
45
  - lib/acdc/body.rb
46
+ - lib/acdc/build.rb
50
47
  - lib/acdc/element.rb
51
48
  - lib/acdc/item.rb
49
+ - lib/acdc/mapping.rb
52
50
  - lib/acdc/parse.rb
53
- - lib/acdc/build.rb
51
+ - lib/acdc.rb
52
+ - README
53
+ - LICENSE
54
54
  has_rdoc: true
55
- homepage: http://h3osoftware.com/acdc
55
+ homepage: http://github.com/clinth3o/acdc
56
56
  licenses: []
57
57
 
58
- post_install_message:
58
+ post_install_message: For those about to rock ... we salute you!
59
59
  rdoc_options: []
60
60
 
61
61
  require_paths:
@@ -74,10 +74,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version:
75
75
  requirements: []
76
76
 
77
- rubyforge_project: acdc
77
+ rubyforge_project:
78
78
  rubygems_version: 1.3.5
79
79
  signing_key:
80
80
  specification_version: 3
81
- summary: AC/DC by h3o(software)
81
+ summary: acdc 0.6.0
82
82
  test_files: []
83
83
 
data/Rakefile DELETED
@@ -1,201 +0,0 @@
1
- require 'rake'
2
- require 'rake/clean'
3
- require 'rake/gempackagetask'
4
- require 'spec/rake/spectask'
5
- require 'fileutils'
6
- require 'yard'
7
- include FileUtils
8
- require File.join(File.dirname(__FILE__),"lib","acdc")
9
- include AcDc
10
-
11
- spec = Gem::Specification.new do |s|
12
- s.name = "acdc"
13
- s.version = AcDc::VERSION.join(".")
14
- s.platform = Gem::Platform::RUBY
15
- s.author = "Clint Hill"
16
- s.email = "clint.hill@h3osoftware.com"
17
- s.homepage = "http://h3osoftware.com/acdc"
18
- s.summary = "AC/DC by h3o(software)"
19
- s.description = <<-EOF
20
- This is a little xml-to-object-to-xml library that gets Dirty Deeds Done Dirt Cheap.
21
- EOF
22
- s.rubyforge_project = "acdc"
23
- s.require_path = "lib"
24
- s.files = [
25
- "LICENSE",
26
- "README",
27
- "Rakefile",
28
- "lib/acdc.rb",
29
- "lib/acdc/attribute.rb",
30
- "lib/acdc/body.rb",
31
- "lib/acdc/element.rb",
32
- "lib/acdc/item.rb",
33
- "lib/acdc/parse.rb",
34
- "lib/acdc/build.rb"
35
- ]
36
- if s.respond_to? :specification_version then
37
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
- s.specification_version = 3
39
-
40
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
- s.add_runtime_dependency(%q<libxml-ruby>, [">= 1.1.3"])
42
- s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
43
- else
44
- s.add_dependency(%q<libxml-ruby>, [">= 1.1.3"])
45
- s.add_dependency(%q<builder>, [">= 2.1.2"])
46
- end
47
- else
48
- s.add_dependency(%q<libxml-ruby>, [">= 1.1.3"])
49
- s.add_dependency(%q<builder>, [">= 2.1.2"])
50
- end
51
- end
52
-
53
- Rake::GemPackageTask.new(spec) do |package|
54
- package.gem_spec = spec
55
- end
56
-
57
-
58
-
59
- ##############################################################################
60
- # rSpec
61
- ##############################################################################
62
- desc 'Run all specs and rcov'
63
- task :spec => ["spec:default"]
64
- namespace :spec do
65
- Spec::Rake::SpecTask.new('default') do |t|
66
- t.spec_opts = ["--format", "specdoc", "--colour"]
67
- t.spec_files = Dir['spec/**/*_spec.rb'].sort
68
- t.libs = ['lib','lib/acdc']
69
- end
70
- end
71
-
72
- ##############################################################################
73
- # Documentation
74
- ##############################################################################
75
- task :doc => ["doc:yardoc"]
76
- namespace :doc do
77
- YARD::Rake::YardocTask.new do |t|
78
- t.options = ['-odoc/yardoc', '-rREADME', '-mtextile'] # optional
79
- end
80
- end
81
-
82
- #############################################################################
83
- # Stats
84
- #############################################################################
85
- STATS_DIRECTORIES = [
86
- %w(AcDc lib/acdc),
87
- %w(Specs spec)
88
- ].collect { |name, dir| [ name, "#{Dir.pwd}/#{dir}" ] }.select { |name, dir| File.directory?(dir) }
89
-
90
- desc "Report code statistics (KLOCs, etc) from the application"
91
- task :stats do
92
- CodeStatistics.new(*STATS_DIRECTORIES).to_s
93
- end
94
-
95
- class CodeStatistics #:nodoc:
96
-
97
- TEST_TYPES = %w(Specs)
98
-
99
- def initialize(*pairs)
100
- @pairs = pairs
101
- @statistics = calculate_statistics
102
- @total = calculate_total if pairs.length > 1
103
- end
104
-
105
- def to_s
106
- print_header
107
- @pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
108
- print_splitter
109
-
110
- if @total
111
- print_line("Total", @total)
112
- print_splitter
113
- end
114
-
115
- print_code_test_stats
116
- end
117
-
118
- private
119
- def calculate_statistics
120
- @pairs.inject({}) { |stats, pair| stats[pair.first] = calculate_directory_statistics(pair.last); stats }
121
- end
122
-
123
- def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
124
- stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
125
-
126
- Dir.foreach(directory) do |file_name|
127
- if File.stat(directory + "/" + file_name).directory? and (/^\./ !~ file_name)
128
- newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
129
- stats.each { |k, v| stats[k] += newstats[k] }
130
- end
131
-
132
- next unless file_name =~ pattern
133
-
134
- f = File.open(directory + "/" + file_name)
135
-
136
- while line = f.gets
137
- stats["lines"] += 1
138
- stats["classes"] += 1 if line =~ /class [A-Z]/
139
- stats["methods"] += 1 if line =~ /def [a-z]/
140
- stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
141
- end
142
- end
143
-
144
- stats
145
- end
146
-
147
- def calculate_total
148
- total = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
149
- @statistics.each_value { |pair| pair.each { |k, v| total[k] += v } }
150
- total
151
- end
152
-
153
- def calculate_code
154
- code_loc = 0
155
- @statistics.each { |k, v| code_loc += v['codelines'] unless TEST_TYPES.include? k }
156
- code_loc
157
- end
158
-
159
- def calculate_tests
160
- test_loc = 0
161
- @statistics.each { |k, v| test_loc += v['codelines'] if TEST_TYPES.include? k }
162
- test_loc
163
- end
164
-
165
- def print_header
166
- print_splitter
167
- puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |"
168
- print_splitter
169
- end
170
-
171
- def print_splitter
172
- puts "+----------------------+-------+-------+---------+---------+-----+-------+"
173
- end
174
-
175
- def print_line(name, statistics)
176
- m_over_c = (statistics["methods"] / statistics["classes"]) rescue m_over_c = 0
177
- loc_over_m = (statistics["codelines"] / statistics["methods"]) - 2 rescue loc_over_m = 0
178
-
179
- start = if TEST_TYPES.include? name
180
- "| #{name.ljust(20)} "
181
- else
182
- "| #{name.ljust(20)} "
183
- end
184
-
185
- puts start +
186
- "| #{statistics["lines"].to_s.rjust(5)} " +
187
- "| #{statistics["codelines"].to_s.rjust(5)} " +
188
- "| #{statistics["classes"].to_s.rjust(7)} " +
189
- "| #{statistics["methods"].to_s.rjust(7)} " +
190
- "| #{m_over_c.to_s.rjust(3)} " +
191
- "| #{loc_over_m.to_s.rjust(5)} |"
192
- end
193
-
194
- def print_code_test_stats
195
- code = calculate_code
196
- tests = calculate_tests
197
-
198
- puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}"
199
- puts ""
200
- end
201
- end