clinth3o-acdc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +76 -0
- data/Rakefile +178 -0
- metadata +85 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008-2009 Clint Hill - h3o(software)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
= AC/DC - h3o(software)
|
2
|
+
|
3
|
+
== For Those About To Rock
|
4
|
+
|
5
|
+
This is a little XML-to-object-to-XML library that gets Dirty Deeds Done Dirt Cheap.
|
6
|
+
|
7
|
+
== Features
|
8
|
+
|
9
|
+
* Take XML string objects and convert them to real Ruby objects from your library
|
10
|
+
* Take real Ruby objects and convert them to XML strings
|
11
|
+
* Declare XML elements/attributes easily and with type enforcement
|
12
|
+
* Coerce objects to XML strings automatically (see JAIL_BREAK)
|
13
|
+
|
14
|
+
== Usage
|
15
|
+
|
16
|
+
=== Element
|
17
|
+
|
18
|
+
A basic XML element is created with the use of the following constructor
|
19
|
+
|
20
|
+
require 'acdc'
|
21
|
+
elem = Element("Hells Bells")
|
22
|
+
puts elem.acdc
|
23
|
+
=> "<Element>Hells Bells</Element>"
|
24
|
+
elem = Element("Hells Bells", {}, "BackInBlack")
|
25
|
+
puts elem.acdc
|
26
|
+
=> "<BackInBlack>Hells Bells</BackInBlack>"
|
27
|
+
|
28
|
+
=== It's A Long Way To The Top, If You Want To Rock n Roll
|
29
|
+
|
30
|
+
AcDc::Body assists you with declaring XML objects with ease. And #acdc makes
|
31
|
+
marshaling those objects from XML a breeze.
|
32
|
+
|
33
|
+
require 'acdc'
|
34
|
+
class TheJack < AcDc::Body
|
35
|
+
attribute :shes_got, "the jack"
|
36
|
+
element :big_balls
|
37
|
+
end
|
38
|
+
rosie = TheJack.new(:big_balls => "I've got big balls")
|
39
|
+
puts rosie.big_balls
|
40
|
+
=> "I've got big balls"
|
41
|
+
puts rosie.acdc
|
42
|
+
=> "<TheJack shes_got="the jack"><BigBalls>I've got big balls</BigBalls></TheJack>"
|
43
|
+
who_made_who = acdc("<TheJack><BigBalls>Biggest Balls of them all</BigBalls></TheJack>")
|
44
|
+
puts who_made_who.class
|
45
|
+
=> TheJack
|
46
|
+
puts who_made_who.big_balls
|
47
|
+
=> "Biggest Balls of them all"
|
48
|
+
|
49
|
+
=== JAIL_BREAK
|
50
|
+
|
51
|
+
JAIL_BREAK will determine whether or not you need to explicitly coerce your
|
52
|
+
objects to XML using Element#acdc or Body#acdc. It's may not be the smartest
|
53
|
+
feature in the world, but we're gonna Ride On.
|
54
|
+
|
55
|
+
==== Without JAIL_BREAK
|
56
|
+
|
57
|
+
require 'acdc'
|
58
|
+
XML_element = Element("TNT")
|
59
|
+
puts XML_element
|
60
|
+
=> #<AcDc::Element:>
|
61
|
+
puts XML_element.acdc
|
62
|
+
=> "<Element>TNT</Element>"
|
63
|
+
|
64
|
+
==== With JAIL_BREAK
|
65
|
+
|
66
|
+
JAIL_BREAK = true
|
67
|
+
require 'acdc'
|
68
|
+
XML_element = Element("TNT")
|
69
|
+
puts XML_element
|
70
|
+
=> "<Element>TNT</Element>"
|
71
|
+
|
72
|
+
== Contact
|
73
|
+
|
74
|
+
- Author:: Clint Hill clint.hill@h3osoftware.com
|
75
|
+
- Home Page:: http://h3osoftware.com/acdc
|
76
|
+
- GitHub:: git://github.com/clinth3o/acdc.git
|
data/Rakefile
ADDED
@@ -0,0 +1,178 @@
|
|
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
|
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 = %w( LICENSE README Rakefile ) + Dir["{spec,lib,doc}/**/*"]
|
25
|
+
s.add_dependency "activesupport"
|
26
|
+
s.add_dependency "builder"
|
27
|
+
s.add_dependency "hpricot"
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::GemPackageTask.new(spec) do |package|
|
31
|
+
package.gem_spec = spec
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
##############################################################################
|
37
|
+
# rSpec
|
38
|
+
##############################################################################
|
39
|
+
desc 'Run all specs and rcov'
|
40
|
+
task :spec => ["spec:default"]
|
41
|
+
namespace :spec do
|
42
|
+
Spec::Rake::SpecTask.new('default') do |t|
|
43
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
44
|
+
t.spec_files = Dir['spec/**/*_spec.rb'].sort
|
45
|
+
t.libs = ['lib','lib/acdc']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
##############################################################################
|
50
|
+
# Documentation
|
51
|
+
##############################################################################
|
52
|
+
task :doc => ["doc:yardoc"]
|
53
|
+
namespace :doc do
|
54
|
+
YARD::Rake::YardocTask.new do |t|
|
55
|
+
t.options = ['-odoc/yardoc', '-rREADME', '-mtextile'] # optional
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#############################################################################
|
60
|
+
# Stats
|
61
|
+
#############################################################################
|
62
|
+
STATS_DIRECTORIES = [
|
63
|
+
%w(AcDc lib/acdc),
|
64
|
+
%w(Specs spec)
|
65
|
+
].collect { |name, dir| [ name, "#{Dir.pwd}/#{dir}" ] }.select { |name, dir| File.directory?(dir) }
|
66
|
+
|
67
|
+
desc "Report code statistics (KLOCs, etc) from the application"
|
68
|
+
task :stats do
|
69
|
+
CodeStatistics.new(*STATS_DIRECTORIES).to_s
|
70
|
+
end
|
71
|
+
|
72
|
+
class CodeStatistics #:nodoc:
|
73
|
+
|
74
|
+
TEST_TYPES = %w(Specs)
|
75
|
+
|
76
|
+
def initialize(*pairs)
|
77
|
+
@pairs = pairs
|
78
|
+
@statistics = calculate_statistics
|
79
|
+
@total = calculate_total if pairs.length > 1
|
80
|
+
end
|
81
|
+
|
82
|
+
def to_s
|
83
|
+
print_header
|
84
|
+
@pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
|
85
|
+
print_splitter
|
86
|
+
|
87
|
+
if @total
|
88
|
+
print_line("Total", @total)
|
89
|
+
print_splitter
|
90
|
+
end
|
91
|
+
|
92
|
+
print_code_test_stats
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
def calculate_statistics
|
97
|
+
@pairs.inject({}) { |stats, pair| stats[pair.first] = calculate_directory_statistics(pair.last); stats }
|
98
|
+
end
|
99
|
+
|
100
|
+
def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
|
101
|
+
stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
|
102
|
+
|
103
|
+
Dir.foreach(directory) do |file_name|
|
104
|
+
if File.stat(directory + "/" + file_name).directory? and (/^\./ !~ file_name)
|
105
|
+
newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
|
106
|
+
stats.each { |k, v| stats[k] += newstats[k] }
|
107
|
+
end
|
108
|
+
|
109
|
+
next unless file_name =~ pattern
|
110
|
+
|
111
|
+
f = File.open(directory + "/" + file_name)
|
112
|
+
|
113
|
+
while line = f.gets
|
114
|
+
stats["lines"] += 1
|
115
|
+
stats["classes"] += 1 if line =~ /class [A-Z]/
|
116
|
+
stats["methods"] += 1 if line =~ /def [a-z]/
|
117
|
+
stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
stats
|
122
|
+
end
|
123
|
+
|
124
|
+
def calculate_total
|
125
|
+
total = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
|
126
|
+
@statistics.each_value { |pair| pair.each { |k, v| total[k] += v } }
|
127
|
+
total
|
128
|
+
end
|
129
|
+
|
130
|
+
def calculate_code
|
131
|
+
code_loc = 0
|
132
|
+
@statistics.each { |k, v| code_loc += v['codelines'] unless TEST_TYPES.include? k }
|
133
|
+
code_loc
|
134
|
+
end
|
135
|
+
|
136
|
+
def calculate_tests
|
137
|
+
test_loc = 0
|
138
|
+
@statistics.each { |k, v| test_loc += v['codelines'] if TEST_TYPES.include? k }
|
139
|
+
test_loc
|
140
|
+
end
|
141
|
+
|
142
|
+
def print_header
|
143
|
+
print_splitter
|
144
|
+
puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |"
|
145
|
+
print_splitter
|
146
|
+
end
|
147
|
+
|
148
|
+
def print_splitter
|
149
|
+
puts "+----------------------+-------+-------+---------+---------+-----+-------+"
|
150
|
+
end
|
151
|
+
|
152
|
+
def print_line(name, statistics)
|
153
|
+
m_over_c = (statistics["methods"] / statistics["classes"]) rescue m_over_c = 0
|
154
|
+
loc_over_m = (statistics["codelines"] / statistics["methods"]) - 2 rescue loc_over_m = 0
|
155
|
+
|
156
|
+
start = if TEST_TYPES.include? name
|
157
|
+
"| #{name.ljust(20)} "
|
158
|
+
else
|
159
|
+
"| #{name.ljust(20)} "
|
160
|
+
end
|
161
|
+
|
162
|
+
puts start +
|
163
|
+
"| #{statistics["lines"].to_s.rjust(5)} " +
|
164
|
+
"| #{statistics["codelines"].to_s.rjust(5)} " +
|
165
|
+
"| #{statistics["classes"].to_s.rjust(7)} " +
|
166
|
+
"| #{statistics["methods"].to_s.rjust(7)} " +
|
167
|
+
"| #{m_over_c.to_s.rjust(3)} " +
|
168
|
+
"| #{loc_over_m.to_s.rjust(5)} |"
|
169
|
+
end
|
170
|
+
|
171
|
+
def print_code_test_stats
|
172
|
+
code = calculate_code
|
173
|
+
tests = calculate_tests
|
174
|
+
|
175
|
+
puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}"
|
176
|
+
puts ""
|
177
|
+
end
|
178
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clinth3o-acdc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Clint Hill
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: builder
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: hpricot
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: This is a little xml-to-object-to-xml library that gets Dirty Deeds Done Dirt Cheap.
|
46
|
+
email: clint.hill@h3osoftware.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files: []
|
52
|
+
|
53
|
+
files:
|
54
|
+
- LICENSE
|
55
|
+
- README
|
56
|
+
- Rakefile
|
57
|
+
has_rdoc: false
|
58
|
+
homepage: http://h3osoftware.com/acdc
|
59
|
+
licenses:
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project: acdc
|
80
|
+
rubygems_version: 1.3.5
|
81
|
+
signing_key:
|
82
|
+
specification_version: 2
|
83
|
+
summary: AC/DC by h3o(software)
|
84
|
+
test_files: []
|
85
|
+
|