aqua 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/.document +5 -0
  2. data/.gitignore +7 -0
  3. data/Aqua.gemspec +121 -0
  4. data/LICENCE_COUCHREST +176 -0
  5. data/LICENSE +20 -0
  6. data/README.rdoc +105 -0
  7. data/Rakefile +83 -0
  8. data/VERSION +1 -0
  9. data/lib/aqua.rb +101 -0
  10. data/lib/aqua/object/config.rb +43 -0
  11. data/lib/aqua/object/extensions/ar_convert.rb +0 -0
  12. data/lib/aqua/object/extensions/ar_style.rb +0 -0
  13. data/lib/aqua/object/extensions/property.rb +0 -0
  14. data/lib/aqua/object/extensions/validation.rb +0 -0
  15. data/lib/aqua/object/pack.rb +306 -0
  16. data/lib/aqua/object/query.rb +18 -0
  17. data/lib/aqua/object/stub.rb +122 -0
  18. data/lib/aqua/object/tank.rb +54 -0
  19. data/lib/aqua/object/unpack.rb +253 -0
  20. data/lib/aqua/store/couch_db/attachments.rb +183 -0
  21. data/lib/aqua/store/couch_db/couch_db.rb +151 -0
  22. data/lib/aqua/store/couch_db/database.rb +186 -0
  23. data/lib/aqua/store/couch_db/design_document.rb +57 -0
  24. data/lib/aqua/store/couch_db/http_client/adapter/rest_client.rb +53 -0
  25. data/lib/aqua/store/couch_db/http_client/rest_api.rb +62 -0
  26. data/lib/aqua/store/couch_db/server.rb +103 -0
  27. data/lib/aqua/store/couch_db/storage_methods.rb +405 -0
  28. data/lib/aqua/store/storage.rb +59 -0
  29. data/lib/aqua/support/initializers.rb +216 -0
  30. data/lib/aqua/support/mash.rb +144 -0
  31. data/lib/aqua/support/set.rb +23 -0
  32. data/lib/aqua/support/string_extensions.rb +121 -0
  33. data/spec/aqua_spec.rb +19 -0
  34. data/spec/object/config_spec.rb +58 -0
  35. data/spec/object/object_fixtures/array_udder.rb +5 -0
  36. data/spec/object/object_fixtures/canned_hash.rb +5 -0
  37. data/spec/object/object_fixtures/gerbilmiester.rb +18 -0
  38. data/spec/object/object_fixtures/grounded.rb +13 -0
  39. data/spec/object/object_fixtures/log.rb +19 -0
  40. data/spec/object/object_fixtures/persistent.rb +12 -0
  41. data/spec/object/object_fixtures/sugar.rb +4 -0
  42. data/spec/object/object_fixtures/user.rb +38 -0
  43. data/spec/object/pack_spec.rb +607 -0
  44. data/spec/object/query_spec.rb +27 -0
  45. data/spec/object/stub_spec.rb +51 -0
  46. data/spec/object/tank_spec.rb +61 -0
  47. data/spec/object/unpack_spec.rb +361 -0
  48. data/spec/spec.opts +3 -0
  49. data/spec/spec_helper.rb +16 -0
  50. data/spec/store/couchdb/attachments_spec.rb +164 -0
  51. data/spec/store/couchdb/couch_db_spec.rb +104 -0
  52. data/spec/store/couchdb/database_spec.rb +161 -0
  53. data/spec/store/couchdb/design_document_spec.rb +43 -0
  54. data/spec/store/couchdb/fixtures_and_data/document_fixture.rb +3 -0
  55. data/spec/store/couchdb/fixtures_and_data/image_attach.png +0 -0
  56. data/spec/store/couchdb/server_spec.rb +96 -0
  57. data/spec/store/couchdb/storage_methods_spec.rb +408 -0
  58. data/utils/code_statistics.rb +134 -0
  59. data/utils/console +11 -0
  60. metadata +136 -0
@@ -0,0 +1,134 @@
1
+ # This was taken from Merb, who took it from Rails
2
+ # It has been adopted to run from the command line
3
+ # and analyze lib based projects like gems.
4
+ # =================================================
5
+
6
+ # Copyright (c) 2004-2008 David Heinemeier Hansson
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to
13
+ # permit persons to whom the Software is furnished to do so, subject to
14
+ # the following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be
17
+ # included in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+
27
+ class CodeStatistics
28
+
29
+ def initialize(*pairs)
30
+ @pairs = pairs
31
+ @statistics = calculate_statistics
32
+ @total = calculate_total if pairs.length > 1
33
+ end
34
+
35
+ def to_s
36
+ print_header
37
+ @pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
38
+ print_splitter
39
+
40
+ if @total
41
+ print_line("Total", @total)
42
+ print_splitter
43
+ end
44
+
45
+ print_code_test_stats
46
+ end
47
+
48
+ private
49
+
50
+ def calculate_statistics
51
+ @pairs.inject({}) { |stats, pair| stats[pair.first] = calculate_directory_statistics(pair.last); stats }
52
+ end
53
+
54
+ def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
55
+ stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
56
+
57
+ Dir.foreach(directory) do |file_name|
58
+ if File.stat(directory + "/" + file_name).directory? and (/^\./ !~ file_name)
59
+ newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
60
+ stats.each { |k, v| stats[k] += newstats[k] }
61
+ end
62
+
63
+ next unless file_name =~ pattern
64
+
65
+ f = File.open(directory + "/" + file_name)
66
+
67
+ while line = f.gets
68
+ stats["lines"] += 1
69
+ stats["classes"] += 1 if line =~ /class [A-Z]/
70
+
71
+ stats["methods"] += 1 if line =~ /def [a-z]/
72
+ stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
73
+ end
74
+ end
75
+
76
+ stats
77
+ end
78
+
79
+ def calculate_total
80
+ total = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
81
+ @statistics.each_value { |pair| pair.each { |k, v| total[k] += v } }
82
+ total
83
+ end
84
+
85
+ def calculate_code
86
+ code_loc = 0
87
+ @statistics.each { |k, v| code_loc += v['codelines'] unless k.match('Spec') }
88
+ code_loc
89
+ end
90
+
91
+ def calculate_tests
92
+ test_loc = 0
93
+ @statistics.each { |k, v| test_loc += v['codelines'] if k.match('Spec') }
94
+ test_loc
95
+ end
96
+
97
+ def print_header
98
+ print_splitter
99
+ puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |"
100
+ print_splitter
101
+ end
102
+
103
+ def print_splitter
104
+ puts "+----------------------+-------+-------+---------+---------+-----+-------+"
105
+ end
106
+
107
+ def print_line(name, statistics)
108
+ m_over_c = (statistics["methods"] / statistics["classes"]) rescue m_over_c = 0
109
+ loc_over_m = (statistics["codelines"] / statistics["methods"]) - 2 rescue loc_over_m = 0
110
+
111
+ start = if name.match(/Spec/)
112
+ "| #{name.ljust(20)} "
113
+ else
114
+ "| #{name.ljust(20)} "
115
+ end
116
+
117
+ puts start +
118
+ "| #{statistics["lines"].to_s.rjust(5)} " +
119
+ "| #{statistics["codelines"].to_s.rjust(5)} " +
120
+ "| #{statistics["classes"].to_s.rjust(7)} " +
121
+ "| #{statistics["methods"].to_s.rjust(7)} " +
122
+ "| #{m_over_c.to_s.rjust(3)} " +
123
+ "| #{loc_over_m.to_s.rjust(5)} |"
124
+ end
125
+
126
+ def print_code_test_stats
127
+ code = calculate_code
128
+ tests = calculate_tests
129
+
130
+ puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}"
131
+ puts ""
132
+ end
133
+
134
+ end
data/utils/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'irb'
5
+ require 'ruby-debug'
6
+ require File.dirname(__FILE__) + "/../lib/aqua"
7
+ Dir[ File.dirname(__FILE__) + "/../spec/object/object_fixtures/**/*.rb" ].each do |file|
8
+ require file
9
+ end
10
+
11
+ IRB.start if __FILE__ == $0
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aqua
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Kane Baccigalupi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "Even with ORMs like ActiveRecord, DataMapper which ease the pain of relational data storage, considerable developer effort goes into wrangling Ruby objects into their databases. Document-oriented databases have made it possible to store nested data structures that easily map to Ruby objects. Aqua (http://github.com/baccigalupi/aqua) is a new Ruby library that aims to painlessly persists objects, allowing developers to focus more on object oriented code and less on storage. Currently Aqua is in pre-alpha testing, with the following big things left to implement: A data query DSL and implementation; Support of all objects in the Standard Library; Class and code storage to allow the sharing and persistence of classes with their data."
17
+ email: baccigalupi@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - Aqua.gemspec
29
+ - LICENCE_COUCHREST
30
+ - LICENSE
31
+ - README.rdoc
32
+ - Rakefile
33
+ - VERSION
34
+ - lib/aqua.rb
35
+ - lib/aqua/object/config.rb
36
+ - lib/aqua/object/extensions/ar_convert.rb
37
+ - lib/aqua/object/extensions/ar_style.rb
38
+ - lib/aqua/object/extensions/property.rb
39
+ - lib/aqua/object/extensions/validation.rb
40
+ - lib/aqua/object/pack.rb
41
+ - lib/aqua/object/query.rb
42
+ - lib/aqua/object/stub.rb
43
+ - lib/aqua/object/tank.rb
44
+ - lib/aqua/object/unpack.rb
45
+ - lib/aqua/store/couch_db/attachments.rb
46
+ - lib/aqua/store/couch_db/couch_db.rb
47
+ - lib/aqua/store/couch_db/database.rb
48
+ - lib/aqua/store/couch_db/design_document.rb
49
+ - lib/aqua/store/couch_db/http_client/adapter/rest_client.rb
50
+ - lib/aqua/store/couch_db/http_client/rest_api.rb
51
+ - lib/aqua/store/couch_db/server.rb
52
+ - lib/aqua/store/couch_db/storage_methods.rb
53
+ - lib/aqua/store/storage.rb
54
+ - lib/aqua/support/initializers.rb
55
+ - lib/aqua/support/mash.rb
56
+ - lib/aqua/support/set.rb
57
+ - lib/aqua/support/string_extensions.rb
58
+ - spec/aqua_spec.rb
59
+ - spec/object/config_spec.rb
60
+ - spec/object/object_fixtures/array_udder.rb
61
+ - spec/object/object_fixtures/canned_hash.rb
62
+ - spec/object/object_fixtures/gerbilmiester.rb
63
+ - spec/object/object_fixtures/grounded.rb
64
+ - spec/object/object_fixtures/log.rb
65
+ - spec/object/object_fixtures/persistent.rb
66
+ - spec/object/object_fixtures/sugar.rb
67
+ - spec/object/object_fixtures/user.rb
68
+ - spec/object/pack_spec.rb
69
+ - spec/object/query_spec.rb
70
+ - spec/object/stub_spec.rb
71
+ - spec/object/tank_spec.rb
72
+ - spec/object/unpack_spec.rb
73
+ - spec/spec.opts
74
+ - spec/spec_helper.rb
75
+ - spec/store/couchdb/attachments_spec.rb
76
+ - spec/store/couchdb/couch_db_spec.rb
77
+ - spec/store/couchdb/database_spec.rb
78
+ - spec/store/couchdb/design_document_spec.rb
79
+ - spec/store/couchdb/fixtures_and_data/document_fixture.rb
80
+ - spec/store/couchdb/fixtures_and_data/image_attach.png
81
+ - spec/store/couchdb/server_spec.rb
82
+ - spec/store/couchdb/storage_methods_spec.rb
83
+ - utils/code_statistics.rb
84
+ - utils/console
85
+ has_rdoc: true
86
+ homepage: http://github.com/baccigalupi/aqua
87
+ licenses: []
88
+
89
+ post_install_message:
90
+ rdoc_options:
91
+ - --charset=UTF-8
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ version:
106
+ requirements: []
107
+
108
+ rubyforge_project:
109
+ rubygems_version: 1.3.5
110
+ signing_key:
111
+ specification_version: 2
112
+ summary: "Aqua: A Ruby Object Database ... just add water (and CouchDB)"
113
+ test_files:
114
+ - spec/aqua_spec.rb
115
+ - spec/object/config_spec.rb
116
+ - spec/object/object_fixtures/array_udder.rb
117
+ - spec/object/object_fixtures/canned_hash.rb
118
+ - spec/object/object_fixtures/gerbilmiester.rb
119
+ - spec/object/object_fixtures/grounded.rb
120
+ - spec/object/object_fixtures/log.rb
121
+ - spec/object/object_fixtures/persistent.rb
122
+ - spec/object/object_fixtures/sugar.rb
123
+ - spec/object/object_fixtures/user.rb
124
+ - spec/object/pack_spec.rb
125
+ - spec/object/query_spec.rb
126
+ - spec/object/stub_spec.rb
127
+ - spec/object/tank_spec.rb
128
+ - spec/object/unpack_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/store/couchdb/attachments_spec.rb
131
+ - spec/store/couchdb/couch_db_spec.rb
132
+ - spec/store/couchdb/database_spec.rb
133
+ - spec/store/couchdb/design_document_spec.rb
134
+ - spec/store/couchdb/fixtures_and_data/document_fixture.rb
135
+ - spec/store/couchdb/server_spec.rb
136
+ - spec/store/couchdb/storage_methods_spec.rb