orange 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +154 -0
- data/lib/orange.rb +7 -0
- data/lib/orange/application.rb +125 -0
- data/lib/orange/carton.rb +114 -0
- data/lib/orange/cartons/site_carton.rb +9 -0
- data/lib/orange/core.rb +197 -0
- data/lib/orange/magick.rb +91 -0
- data/lib/orange/middleware/access_control.rb +100 -0
- data/lib/orange/middleware/base.rb +41 -0
- data/lib/orange/middleware/database.rb +22 -0
- data/lib/orange/middleware/globals.rb +18 -0
- data/lib/orange/middleware/recapture.rb +19 -0
- data/lib/orange/middleware/rerouter.rb +13 -0
- data/lib/orange/middleware/restful_router.rb +59 -0
- data/lib/orange/middleware/route_context.rb +39 -0
- data/lib/orange/middleware/route_site.rb +51 -0
- data/lib/orange/middleware/show_exceptions.rb +78 -0
- data/lib/orange/middleware/site_load.rb +33 -0
- data/lib/orange/middleware/static.rb +81 -0
- data/lib/orange/middleware/static_file.rb +32 -0
- data/lib/orange/middleware/template.rb +61 -0
- data/lib/orange/model_resource.rb +170 -0
- data/lib/orange/packet.rb +88 -0
- data/lib/orange/resource.rb +37 -0
- data/lib/orange/resources/flex_router.rb +13 -0
- data/lib/orange/resources/mapper.rb +55 -0
- data/lib/orange/resources/page_parts.rb +54 -0
- data/lib/orange/resources/parser.rb +60 -0
- data/lib/orange/routable_resource.rb +16 -0
- data/lib/orange/stack.rb +201 -0
- data/spec/application_spec.rb +146 -0
- data/spec/carton_spec.rb +5 -0
- data/spec/core_spec.rb +231 -0
- data/spec/magick_spec.rb +89 -0
- data/spec/mock/mock_app.rb +17 -0
- data/spec/mock/mock_core.rb +2 -0
- data/spec/mock/mock_middleware.rb +13 -0
- data/spec/mock/mock_mixins.rb +19 -0
- data/spec/mock/mock_pulp.rb +24 -0
- data/spec/mock/mock_resource.rb +5 -0
- data/spec/mock/mock_router.rb +10 -0
- data/spec/model_resource_spec.rb +5 -0
- data/spec/orange_spec.rb +19 -0
- data/spec/packet_spec.rb +134 -0
- data/spec/resource_spec.rb +5 -0
- data/spec/resources/flex_router_spec.rb +5 -0
- data/spec/resources/mapper_spec.rb +5 -0
- data/spec/resources/parser_spec.rb +5 -0
- data/spec/routable_resource_spec.rb +5 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/stack_spec.rb +202 -0
- data/spec/stats.rb +182 -0
- metadata +194 -0
data/spec/stats.rb
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
class CodeStatistics #:nodoc:
|
4
|
+
|
5
|
+
TEST_TYPES = %w(Units Functionals Unit\ tests Functional\ tests Integration\ tests)
|
6
|
+
|
7
|
+
def initialize(*pairs)
|
8
|
+
@pairs = pairs
|
9
|
+
@statistics = calculate_statistics
|
10
|
+
@total = calculate_total if pairs.length > 1
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
print_header
|
15
|
+
@pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
|
16
|
+
print_splitter
|
17
|
+
|
18
|
+
if @total
|
19
|
+
print_line("Total", @total)
|
20
|
+
print_splitter
|
21
|
+
end
|
22
|
+
|
23
|
+
print_code_test_stats
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def calculate_statistics
|
28
|
+
@pairs.inject({}) { |stats, pair| stats[pair.first] = calculate_directory_statistics(pair.last); stats }
|
29
|
+
end
|
30
|
+
|
31
|
+
def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
|
32
|
+
stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
|
33
|
+
|
34
|
+
Dir.foreach(directory) do |file_name|
|
35
|
+
if File.stat(directory + "/" + file_name).directory? and (/^\./ !~ file_name)
|
36
|
+
newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
|
37
|
+
stats.each { |k, v| stats[k] += newstats[k] }
|
38
|
+
end
|
39
|
+
|
40
|
+
next unless file_name =~ pattern
|
41
|
+
|
42
|
+
f = File.open(directory + "/" + file_name)
|
43
|
+
|
44
|
+
while line = f.gets
|
45
|
+
stats["lines"] += 1
|
46
|
+
stats["classes"] += 1 if line =~ /class [A-Z]/
|
47
|
+
stats["methods"] += 1 if line =~ /def [a-z]/
|
48
|
+
stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
stats
|
53
|
+
end
|
54
|
+
|
55
|
+
def calculate_total
|
56
|
+
total = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
|
57
|
+
@statistics.each_value { |pair| pair.each { |k, v| total[k] += v } }
|
58
|
+
total
|
59
|
+
end
|
60
|
+
|
61
|
+
def calculate_code
|
62
|
+
code_loc = 0
|
63
|
+
@statistics.each { |k, v| code_loc += v['codelines'] unless TEST_TYPES.include? k }
|
64
|
+
code_loc
|
65
|
+
end
|
66
|
+
|
67
|
+
def calculate_tests
|
68
|
+
test_loc = 0
|
69
|
+
@statistics.each { |k, v| test_loc += v['codelines'] if TEST_TYPES.include? k }
|
70
|
+
test_loc
|
71
|
+
end
|
72
|
+
|
73
|
+
def print_header
|
74
|
+
print_splitter
|
75
|
+
puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |"
|
76
|
+
print_splitter
|
77
|
+
end
|
78
|
+
|
79
|
+
def print_splitter
|
80
|
+
puts "+----------------------+-------+-------+---------+---------+-----+-------+"
|
81
|
+
end
|
82
|
+
|
83
|
+
def print_line(name, statistics)
|
84
|
+
m_over_c = (statistics["methods"] / statistics["classes"]) rescue m_over_c = 0
|
85
|
+
loc_over_m = (statistics["codelines"] / statistics["methods"]) - 2 rescue loc_over_m = 0
|
86
|
+
|
87
|
+
start = if TEST_TYPES.include? name
|
88
|
+
"| #{name.ljust(20)} "
|
89
|
+
else
|
90
|
+
"| #{name.ljust(20)} "
|
91
|
+
end
|
92
|
+
|
93
|
+
puts start +
|
94
|
+
"| #{statistics["lines"].to_s.rjust(5)} " +
|
95
|
+
"| #{statistics["codelines"].to_s.rjust(5)} " +
|
96
|
+
"| #{statistics["classes"].to_s.rjust(7)} " +
|
97
|
+
"| #{statistics["methods"].to_s.rjust(7)} " +
|
98
|
+
"| #{m_over_c.to_s.rjust(3)} " +
|
99
|
+
"| #{loc_over_m.to_s.rjust(5)} |"
|
100
|
+
end
|
101
|
+
|
102
|
+
def print_code_test_stats
|
103
|
+
code = calculate_code
|
104
|
+
tests = calculate_tests
|
105
|
+
|
106
|
+
puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}"
|
107
|
+
puts ""
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class SpecStatistics < CodeStatistics
|
112
|
+
|
113
|
+
TEST_TYPES << "Specs"
|
114
|
+
|
115
|
+
private
|
116
|
+
def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
|
117
|
+
stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0, "specs" => 0, "behaviors" => 0 }
|
118
|
+
|
119
|
+
|
120
|
+
Dir.foreach(directory) do |file_name|
|
121
|
+
if File.stat(directory + "/" + file_name).directory? and (/^\./ !~ file_name)
|
122
|
+
newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
|
123
|
+
stats.each { |k, v| stats[k] += newstats[k] }
|
124
|
+
end
|
125
|
+
|
126
|
+
next unless file_name =~ pattern
|
127
|
+
|
128
|
+
f = File.open(directory + "/" + file_name)
|
129
|
+
|
130
|
+
while line = f.gets
|
131
|
+
stats["lines"] += 1
|
132
|
+
stats["classes"] += 1 if line =~ /class [A-Z]/
|
133
|
+
stats["methods"] += 1 if line =~ /def [a-z]/
|
134
|
+
stats["specs"] += 1 if line.strip =~ /^it.*(do|\{)$/
|
135
|
+
stats["behaviors"] += 1 if line =~ /describe.*(do|\{)$/
|
136
|
+
stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
stats
|
141
|
+
end
|
142
|
+
|
143
|
+
def calculate_total
|
144
|
+
total = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0, "specs" => 0, "behaviors" => 0 }
|
145
|
+
@statistics.each_value { |pair| pair.each { |k, v| total[k] += v } }
|
146
|
+
total
|
147
|
+
end
|
148
|
+
|
149
|
+
def print_header
|
150
|
+
print_splitter
|
151
|
+
puts "| Name | Lines | LOC | Classes | Methods | Behaviors | Specifications | M/C | LOC/M | S/B |"
|
152
|
+
print_splitter
|
153
|
+
end
|
154
|
+
|
155
|
+
def print_splitter
|
156
|
+
puts "+----------------------+-------+-------+---------+---------+-----------+----------------+-----+-------+-----+"
|
157
|
+
end
|
158
|
+
|
159
|
+
def print_line(name, statistics)
|
160
|
+
m_over_c = (statistics["methods"] / statistics["classes"]) rescue m_over_c = 0
|
161
|
+
loc_over_m = (statistics["codelines"] / statistics["methods"]) - 2 rescue loc_over_m = 0
|
162
|
+
|
163
|
+
s_over_b = (statistics["specs"] / statistics["behaviors"]) rescue 0
|
164
|
+
|
165
|
+
start = if TEST_TYPES.include? name
|
166
|
+
"| #{name.ljust(20)} "
|
167
|
+
else
|
168
|
+
"| #{name.ljust(20)} "
|
169
|
+
end
|
170
|
+
|
171
|
+
puts start +
|
172
|
+
"| #{statistics["lines"].to_s.rjust(5)} " +
|
173
|
+
"| #{statistics["codelines"].to_s.rjust(5)} " +
|
174
|
+
"| #{statistics["classes"].to_s.rjust(7)} " +
|
175
|
+
"| #{statistics["methods"].to_s.rjust(7)} " +
|
176
|
+
"| #{statistics["behaviors"].to_s.rjust(10)}" +
|
177
|
+
"| #{statistics["specs"].to_s.rjust(15)}" +
|
178
|
+
"| #{m_over_c.to_s.rjust(3)} " +
|
179
|
+
"| #{loc_over_m.to_s.rjust(6)}" +
|
180
|
+
"| #{s_over_b.to_s.rjust(3)} |"
|
181
|
+
end
|
182
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: orange
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Haslem
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-17 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dm-core
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.10.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: dm-more
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.10.2
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rack
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.1
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: haml
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.2.13
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mynyml-rack-abstract-format
|
57
|
+
type: :runtime
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.9.7
|
64
|
+
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rack-openid
|
67
|
+
type: :runtime
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.2.0
|
74
|
+
version:
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: meekish-openid_dm_store
|
77
|
+
type: :runtime
|
78
|
+
version_requirement:
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.1.2
|
84
|
+
version:
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rspec
|
87
|
+
type: :development
|
88
|
+
version_requirement:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rack-test
|
97
|
+
type: :development
|
98
|
+
version_requirement:
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: "0"
|
104
|
+
version:
|
105
|
+
description: Orange is a Ruby framework for building managed websites with code as simple as Sinatra
|
106
|
+
email: therabidbanana@gmail.com
|
107
|
+
executables: []
|
108
|
+
|
109
|
+
extensions: []
|
110
|
+
|
111
|
+
extra_rdoc_files:
|
112
|
+
- README.markdown
|
113
|
+
files:
|
114
|
+
- lib/orange.rb
|
115
|
+
- lib/orange/application.rb
|
116
|
+
- lib/orange/carton.rb
|
117
|
+
- lib/orange/cartons/site_carton.rb
|
118
|
+
- lib/orange/core.rb
|
119
|
+
- lib/orange/magick.rb
|
120
|
+
- lib/orange/middleware/access_control.rb
|
121
|
+
- lib/orange/middleware/base.rb
|
122
|
+
- lib/orange/middleware/database.rb
|
123
|
+
- lib/orange/middleware/globals.rb
|
124
|
+
- lib/orange/middleware/recapture.rb
|
125
|
+
- lib/orange/middleware/rerouter.rb
|
126
|
+
- lib/orange/middleware/restful_router.rb
|
127
|
+
- lib/orange/middleware/route_context.rb
|
128
|
+
- lib/orange/middleware/route_site.rb
|
129
|
+
- lib/orange/middleware/show_exceptions.rb
|
130
|
+
- lib/orange/middleware/site_load.rb
|
131
|
+
- lib/orange/middleware/static.rb
|
132
|
+
- lib/orange/middleware/static_file.rb
|
133
|
+
- lib/orange/middleware/template.rb
|
134
|
+
- lib/orange/model_resource.rb
|
135
|
+
- lib/orange/packet.rb
|
136
|
+
- lib/orange/resource.rb
|
137
|
+
- lib/orange/resources/flex_router.rb
|
138
|
+
- lib/orange/resources/mapper.rb
|
139
|
+
- lib/orange/resources/page_parts.rb
|
140
|
+
- lib/orange/resources/parser.rb
|
141
|
+
- lib/orange/routable_resource.rb
|
142
|
+
- lib/orange/stack.rb
|
143
|
+
- README.markdown
|
144
|
+
has_rdoc: true
|
145
|
+
homepage: http://github.com/therabidbanana/orange
|
146
|
+
licenses: []
|
147
|
+
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options:
|
150
|
+
- --charset=UTF-8
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: "0"
|
158
|
+
version:
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: "0"
|
164
|
+
version:
|
165
|
+
requirements: []
|
166
|
+
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 1.3.5
|
169
|
+
signing_key:
|
170
|
+
specification_version: 3
|
171
|
+
summary: Middle ground between Sinatra and Rails
|
172
|
+
test_files:
|
173
|
+
- spec/application_spec.rb
|
174
|
+
- spec/carton_spec.rb
|
175
|
+
- spec/core_spec.rb
|
176
|
+
- spec/magick_spec.rb
|
177
|
+
- spec/mock/mock_app.rb
|
178
|
+
- spec/mock/mock_core.rb
|
179
|
+
- spec/mock/mock_middleware.rb
|
180
|
+
- spec/mock/mock_mixins.rb
|
181
|
+
- spec/mock/mock_pulp.rb
|
182
|
+
- spec/mock/mock_resource.rb
|
183
|
+
- spec/mock/mock_router.rb
|
184
|
+
- spec/model_resource_spec.rb
|
185
|
+
- spec/orange_spec.rb
|
186
|
+
- spec/packet_spec.rb
|
187
|
+
- spec/resource_spec.rb
|
188
|
+
- spec/resources/flex_router_spec.rb
|
189
|
+
- spec/resources/mapper_spec.rb
|
190
|
+
- spec/resources/parser_spec.rb
|
191
|
+
- spec/routable_resource_spec.rb
|
192
|
+
- spec/spec_helper.rb
|
193
|
+
- spec/stack_spec.rb
|
194
|
+
- spec/stats.rb
|