strokedb 0.0.2.1 → 0.0.2.2

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.
Files changed (192) hide show
  1. data/README +18 -20
  2. data/bench.html +4001 -0
  3. data/bin/strokedb +14 -0
  4. data/examples/movies.rb +105 -0
  5. data/examples/movies2.rb +97 -0
  6. data/examples/strokewiki/README +28 -0
  7. data/examples/strokewiki/view/edit.xhtml +27 -0
  8. data/examples/strokewiki/view/new.xhtml +26 -0
  9. data/examples/strokewiki/view/pages.xhtml +27 -0
  10. data/examples/strokewiki/view/show.xhtml +40 -0
  11. data/examples/strokewiki/view/versions.xhtml +25 -0
  12. data/examples/strokewiki/wiki.rb +106 -0
  13. data/examples/todo.rb +92 -0
  14. data/lib/strokedb.rb +85 -0
  15. data/lib/{config → strokedb}/config.rb +14 -9
  16. data/lib/strokedb/console.rb +87 -0
  17. data/lib/strokedb/core_ext.rb +10 -0
  18. data/lib/{util/ext → strokedb/core_ext}/blank.rb +1 -1
  19. data/lib/{util/ext → strokedb/core_ext}/enumerable.rb +0 -0
  20. data/lib/{util/ext → strokedb/core_ext}/fixnum.rb +0 -0
  21. data/lib/strokedb/core_ext/float.rb +4 -0
  22. data/lib/{util/ext → strokedb/core_ext}/hash.rb +0 -0
  23. data/lib/strokedb/core_ext/infinity.rb +33 -0
  24. data/lib/strokedb/core_ext/kernel.rb +41 -0
  25. data/lib/strokedb/core_ext/object.rb +16 -0
  26. data/lib/{util/ext → strokedb/core_ext}/string.rb +28 -1
  27. data/lib/strokedb/core_ext/symbol.rb +13 -0
  28. data/lib/strokedb/data_structures.rb +5 -0
  29. data/lib/strokedb/data_structures/chunked_skiplist.rb +123 -0
  30. data/lib/{data_structures → strokedb/data_structures}/inverted_list.rb +0 -0
  31. data/lib/{data_structures → strokedb/data_structures}/point_query.rb +0 -0
  32. data/lib/strokedb/data_structures/simple_skiplist.rb +350 -0
  33. data/lib/{data_structures → strokedb/data_structures}/skiplist.rb +1 -1
  34. data/lib/{document → strokedb}/document.rb +180 -71
  35. data/lib/{document → strokedb/document}/callback.rb +0 -0
  36. data/lib/{document → strokedb/document}/delete.rb +2 -2
  37. data/lib/strokedb/document/dsl.rb +4 -0
  38. data/lib/{document → strokedb/document/dsl}/associations.rb +0 -0
  39. data/lib/{document → strokedb/document/dsl}/coercions.rb +0 -0
  40. data/lib/strokedb/document/dsl/meta_dsl.rb +7 -0
  41. data/lib/{document → strokedb/document/dsl}/validations.rb +26 -21
  42. data/lib/{document → strokedb/document/dsl}/virtualize.rb +0 -0
  43. data/lib/{document → strokedb/document}/meta.rb +92 -29
  44. data/lib/{document → strokedb/document}/slot.rb +17 -5
  45. data/lib/{document → strokedb/document}/util.rb +0 -0
  46. data/lib/{document → strokedb/document}/versions.rb +2 -2
  47. data/lib/strokedb/index.rb +2 -0
  48. data/lib/strokedb/nsurl.rb +24 -0
  49. data/lib/strokedb/store.rb +149 -0
  50. data/lib/strokedb/stores.rb +6 -0
  51. data/lib/{stores → strokedb/stores}/chainable_storage.rb +20 -14
  52. data/lib/strokedb/stores/file_storage.rb +118 -0
  53. data/lib/{stores/inverted_list_index → strokedb/stores}/inverted_list_file_storage.rb +50 -0
  54. data/lib/strokedb/stores/memory_storage.rb +80 -0
  55. data/lib/{stores → strokedb/stores}/remote_store.rb +10 -4
  56. data/lib/strokedb/sync.rb +4 -0
  57. data/lib/{sync → strokedb/sync}/chain_sync.rb +0 -0
  58. data/lib/{sync → strokedb/sync}/diff.rb +12 -1
  59. data/lib/{sync/stroke_diff → strokedb/sync/diff}/array.rb +1 -1
  60. data/lib/{sync/stroke_diff → strokedb/sync/diff}/default.rb +0 -0
  61. data/lib/{sync/stroke_diff → strokedb/sync/diff}/hash.rb +1 -1
  62. data/lib/{sync/stroke_diff → strokedb/sync/diff}/string.rb +1 -1
  63. data/lib/{sync → strokedb/sync}/lamport_timestamp.rb +0 -0
  64. data/lib/{sync → strokedb/sync}/store_sync.rb +15 -7
  65. data/lib/strokedb/transaction.rb +78 -0
  66. data/lib/{util → strokedb}/util.rb +14 -7
  67. data/lib/strokedb/util/attach_dsl.rb +29 -0
  68. data/lib/{util → strokedb/util}/blankslate.rb +0 -0
  69. data/lib/strokedb/util/class_optimization.rb +93 -0
  70. data/lib/{util → strokedb/util}/inflect.rb +0 -0
  71. data/lib/strokedb/util/java_util.rb +13 -0
  72. data/lib/{util → strokedb/util}/lazy_array.rb +0 -0
  73. data/lib/{util → strokedb/util}/lazy_mapping_array.rb +4 -0
  74. data/lib/{util → strokedb/util}/lazy_mapping_hash.rb +0 -0
  75. data/lib/{util → strokedb/util}/serialization.rb +21 -0
  76. data/lib/strokedb/util/uuid.rb +159 -0
  77. data/lib/{util → strokedb/util}/xml.rb +0 -0
  78. data/lib/{view → strokedb}/view.rb +2 -2
  79. data/lib/strokedb/volumes.rb +5 -0
  80. data/lib/strokedb/volumes/archive_volume.rb +165 -0
  81. data/lib/strokedb/volumes/block_volume.rb +169 -0
  82. data/lib/strokedb/volumes/distributed_pointer.rb +43 -0
  83. data/lib/strokedb/volumes/fixed_length_skiplist_volume.rb +109 -0
  84. data/lib/strokedb/volumes/map_volume.rb +268 -0
  85. data/meta/MANIFEST +175 -0
  86. data/script/console +2 -70
  87. data/spec/integration/remote_store_spec.rb +70 -0
  88. data/spec/integration/search_spec.rb +76 -0
  89. data/spec/integration/spec_helper.rb +1 -0
  90. data/spec/lib/spec_helper.rb +1 -0
  91. data/spec/lib/strokedb/config_spec.rb +250 -0
  92. data/spec/lib/strokedb/core_ext/blank_spec.rb +20 -0
  93. data/spec/lib/strokedb/core_ext/extract_spec.rb +42 -0
  94. data/spec/lib/strokedb/core_ext/float_spec.rb +62 -0
  95. data/spec/lib/strokedb/core_ext/infinity_spec.rb +40 -0
  96. data/spec/lib/strokedb/core_ext/spec_helper.rb +1 -0
  97. data/spec/lib/strokedb/core_ext/string_spec.rb +25 -0
  98. data/spec/lib/strokedb/core_ext/symbol_spec.rb +8 -0
  99. data/spec/lib/strokedb/data_structures/chunked_skiplist_spec.rb +144 -0
  100. data/spec/lib/strokedb/data_structures/inverted_list_spec.rb +172 -0
  101. data/spec/lib/strokedb/data_structures/simple_skiplist_spec.rb +200 -0
  102. data/spec/lib/strokedb/data_structures/skiplist_spec.rb +253 -0
  103. data/spec/lib/strokedb/data_structures/spec_helper.rb +1 -0
  104. data/spec/lib/strokedb/document/associations_spec.rb +319 -0
  105. data/spec/lib/strokedb/document/callbacks_spec.rb +134 -0
  106. data/spec/lib/strokedb/document/coercions_spec.rb +110 -0
  107. data/spec/lib/strokedb/document/document_spec.rb +1063 -0
  108. data/spec/lib/strokedb/document/meta_meta_spec.rb +30 -0
  109. data/spec/lib/strokedb/document/meta_spec.rb +435 -0
  110. data/spec/lib/strokedb/document/metaslot_spec.rb +43 -0
  111. data/spec/lib/strokedb/document/slot_spec.rb +130 -0
  112. data/spec/lib/strokedb/document/spec_helper.rb +1 -0
  113. data/spec/lib/strokedb/document/validations_spec.rb +1081 -0
  114. data/spec/lib/strokedb/document/virtualize_spec.rb +80 -0
  115. data/spec/lib/strokedb/nsurl_spec.rb +73 -0
  116. data/spec/lib/strokedb/spec_helper.rb +1 -0
  117. data/spec/lib/strokedb/stores/chained_storages_spec.rb +116 -0
  118. data/spec/lib/strokedb/stores/spec_helper.rb +1 -0
  119. data/spec/lib/strokedb/stores/store_spec.rb +201 -0
  120. data/spec/lib/strokedb/stores/transaction_spec.rb +107 -0
  121. data/spec/lib/strokedb/sync/chain_sync_spec.rb +43 -0
  122. data/spec/lib/strokedb/sync/diff_spec.rb +111 -0
  123. data/spec/lib/strokedb/sync/lamport_timestamp_spec.rb +174 -0
  124. data/spec/lib/strokedb/sync/slot_diff_spec.rb +164 -0
  125. data/spec/lib/strokedb/sync/spec_helper.rb +1 -0
  126. data/spec/lib/strokedb/sync/store_sync_spec.rb +181 -0
  127. data/spec/lib/strokedb/sync/stroke_diff/array_spec.rb +97 -0
  128. data/spec/lib/strokedb/sync/stroke_diff/complex_spec.rb +58 -0
  129. data/spec/lib/strokedb/sync/stroke_diff/hash_spec.rb +144 -0
  130. data/spec/lib/strokedb/sync/stroke_diff/scalar_spec.rb +23 -0
  131. data/spec/lib/strokedb/sync/stroke_diff/spec_helper.rb +25 -0
  132. data/spec/lib/strokedb/sync/stroke_diff/string_spec.rb +61 -0
  133. data/spec/lib/strokedb/util/attach_dsl_spec.rb +45 -0
  134. data/spec/lib/strokedb/util/inflect_spec.rb +14 -0
  135. data/spec/lib/strokedb/util/lazy_array_spec.rb +157 -0
  136. data/spec/lib/strokedb/util/lazy_mapping_array_spec.rb +174 -0
  137. data/spec/lib/strokedb/util/lazy_mapping_hash_spec.rb +92 -0
  138. data/spec/lib/strokedb/util/spec_helper.rb +1 -0
  139. data/spec/lib/strokedb/util/uuid_spec.rb +46 -0
  140. data/spec/lib/strokedb/view_spec.rb +228 -0
  141. data/spec/lib/strokedb/volumes/archive_volume_spec.rb +105 -0
  142. data/spec/lib/strokedb/volumes/block_volume_spec.rb +100 -0
  143. data/spec/lib/strokedb/volumes/distributed_pointer_spec.rb +14 -0
  144. data/spec/lib/strokedb/volumes/fixed_length_skiplist_volume_spec.rb +177 -0
  145. data/spec/lib/strokedb/volumes/map_volume_spec.rb +172 -0
  146. data/spec/lib/strokedb/volumes/spec_helper.rb +1 -0
  147. data/spec/regression/docref_spec.rb +94 -0
  148. data/spec/regression/meta_spec.rb +23 -0
  149. data/spec/regression/spec_helper.rb +1 -0
  150. data/spec/regression/sync_spec.rb +36 -0
  151. data/spec/spec.opts +7 -0
  152. data/spec/spec_helper.rb +37 -0
  153. data/spec/temp/storages/TIMESTAMP +1 -0
  154. data/spec/temp/storages/UUID +1 -0
  155. data/spec/temp/storages/database-sync/TIMESTAMP +1 -0
  156. data/spec/temp/storages/database-sync/UUID +1 -0
  157. data/spec/temp/storages/database-sync/config +1 -0
  158. data/spec/temp/storages/database-sync/file/LAST +1 -0
  159. data/spec/temp/storages/database-sync/file/bd/f6/bdf675e5-8a7b-494e-97f2-f74a14ccd95d.av +0 -0
  160. data/spec/temp/storages/database-sync/file/uindex.wal +0 -0
  161. data/spec/temp/storages/database-sync/inverted_list_file/INVERTED_INDEX +1 -0
  162. data/spec/temp/storages/inverted_list_storage/INVERTED_INDEX +0 -0
  163. data/strokedb.gemspec +120 -0
  164. data/task/benchmark.task +9 -0
  165. data/task/ditz.task +30 -0
  166. data/task/echoe.rb +17 -0
  167. data/task/rcov.task +50 -0
  168. data/task/rdoc.task +10 -0
  169. data/task/rspec.task +0 -0
  170. data/vendor/java_inline.rb +106 -0
  171. data/vendor/rbmodexcl/mrimodexcl.rb +82 -0
  172. data/vendor/rbmodexcl/rbmodexcl.rb +5 -0
  173. data/vendor/rbmodexcl/rbxmodexcl.rb +48 -0
  174. data/vendor/rbmodexcl/spec/unextend_spec.rb +50 -0
  175. data/vendor/rbmodexcl/spec/uninclude_spec.rb +26 -0
  176. metadata +271 -79
  177. data/CONTRIBUTORS +0 -7
  178. data/CREDITS +0 -13
  179. data/bin/sdbc +0 -2
  180. data/lib/init.rb +0 -57
  181. data/lib/stores/inverted_list_index/inverted_list_index.rb +0 -49
  182. data/lib/stores/skiplist_store/chunk.rb +0 -119
  183. data/lib/stores/skiplist_store/chunk_storage.rb +0 -21
  184. data/lib/stores/skiplist_store/file_chunk_storage.rb +0 -44
  185. data/lib/stores/skiplist_store/memory_chunk_storage.rb +0 -37
  186. data/lib/stores/skiplist_store/skiplist_store.rb +0 -217
  187. data/lib/stores/store.rb +0 -5
  188. data/lib/sync/stroke_diff/stroke_diff.rb +0 -9
  189. data/lib/util/ext/object.rb +0 -8
  190. data/lib/util/java_util.rb +0 -9
  191. data/lib/util/trigger_partition.rb +0 -136
  192. data/strokedb.rb +0 -75
@@ -0,0 +1,92 @@
1
+ #! /usr/bin/env ruby
2
+ $:.unshift File.dirname(__FILE__) + "/../lib"
3
+ require "strokedb"
4
+
5
+ StrokeDB::Config.build :default => true, :base_path => '.todo.strokedb'
6
+
7
+
8
+ TodoItem = StrokeDB::Meta.new do
9
+ def done!
10
+ self.done = true
11
+ save!
12
+ end
13
+ def to_s
14
+ status = done ? "X" : " "
15
+ "[#{status}] #{description}"
16
+ end
17
+ end
18
+
19
+ TodoList = StrokeDB::Meta.new do
20
+ has_many :items, :through => :todo_items
21
+
22
+ def to_s
23
+ s = "#{name}:\n"
24
+ items.each do |item|
25
+ s << " #{item}\n"
26
+ end
27
+ s
28
+ end
29
+ end
30
+
31
+
32
+ def add_issue(prefix,description)
33
+ todo_list = TodoList.find_or_create(:name => prefix)
34
+ todo_item = TodoItem.find_or_create(:description => description, :done => false, :todo_list => todo_list)
35
+ list_issues
36
+ end
37
+
38
+ def complete_issue(prefix,description)
39
+ todo_list = TodoList.find_or_create(:name => prefix)
40
+ return unless todo_list
41
+ if item = todo_list.items.first(:description => description)
42
+ item.done!
43
+ list_issues
44
+ else
45
+ puts "No such item found"
46
+ end
47
+ end
48
+
49
+ def list_issues
50
+ todo_lists = TodoList.find
51
+ return [] if todo_lists.empty?
52
+ todo_lists.each { |list| puts list }
53
+ end
54
+
55
+ def extract_prefix_item(str)
56
+ _, prefix, _, item = str.match(/(^\[(.*)\])?(.+)/).to_a
57
+ prefix ||= "[Main]"
58
+ prefix.gsub!(/(^\[|\]$)/,'')
59
+ item.lstrip!
60
+ [prefix,item]
61
+ end
62
+
63
+ if ARGV.empty?
64
+ if list_issues.empty?
65
+ puts "Type --help for program help"
66
+ end
67
+ exit
68
+ end
69
+
70
+ if ARGV.first.downcase == "--help"
71
+ puts %{
72
+ Usage: todo Do this Add item to 'Main' list
73
+ todo [project] Do that Add item to 'project' list
74
+ todo -d Do this Complete item in 'Main' list
75
+ todo -d [project] Do that Complete item in 'project' lis
76
+ todo List all items
77
+ todo --help This help message
78
+ }
79
+ exit
80
+ end
81
+
82
+ unless ARGV.first.downcase == "-d"
83
+ prefix,item = extract_prefix_item(ARGV.join(' '))
84
+ add_issue(prefix,item)
85
+ else
86
+ args = ARGV
87
+ args.shift
88
+ prefix,item = extract_prefix_item(args.join(' '))
89
+ complete_issue(prefix,item)
90
+ end
91
+
92
+
@@ -0,0 +1,85 @@
1
+ require 'rubygems'
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
3
+ $LOAD_PATH.unshift( File.expand_path(File.join(File.dirname(__FILE__), 'strokedb')) ).uniq!
4
+ require 'strokedb/core_ext'
5
+ require File.join(File.dirname(__FILE__), '/../vendor/rbmodexcl/rbmodexcl')
6
+ require_one_of 'json', 'json_pure'
7
+
8
+ require 'set'
9
+ require 'fileutils'
10
+
11
+ module StrokeDB
12
+ # Version:
13
+ MAIN = 0
14
+ MAJOR = 0
15
+ MINOR = 2
16
+ PATCHLEVEL = 2
17
+
18
+ VERSION = [MAIN.to_s, MAJOR.to_s, MINOR.to_s, PATCHLEVEL.to_s].join('.')
19
+ VERSION_STRING = VERSION + (RUBY_PLATFORM =~ /java/ ? '-java' : '')
20
+
21
+ # Coverage threshold - bump this float anytime your changes increase the spec coverage
22
+ # DO NOT LOWER THIS NUMBER. EVER.
23
+ COVERAGE = 92
24
+
25
+ # UUID regexp (like 1e3d02cc-0769-4bd8-9113-e033b246b013)
26
+ UUID_RE = /([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/
27
+
28
+ # document version regexp
29
+ VERSION_RE = UUID_RE
30
+
31
+ # XML Schema time format
32
+ # Time.now.xmlschema(6)
33
+ # #=> "2008-04-27T23:39:09.920288+04:00"
34
+ # Time.xmlschema("2008-04-27T23:39:09.920288+04:00")
35
+ # #=> Sun Apr 27 19:39:09 UTC 2008
36
+ XMLSCHEMA_TIME_RE = /\A\s*(-?\d+)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(\.\d*)?(Z|[+-]\d\d:\d\d)?\s*\z/i
37
+
38
+ # STROKEDB NSURL
39
+ STROKEDB_NSURL = "http://strokedb.com/"
40
+
41
+ # so called Nil UUID
42
+ NIL_UUID = "00000000-0000-0000-0000-000000000000"
43
+ RAW_NIL_UUID = "\x00" * 16
44
+
45
+ RAW_FULL_UUID = "\xff" * 16
46
+
47
+
48
+ class <<self
49
+ def default_store
50
+ StrokeDB.default_config.stores[:default] rescue nil
51
+ end
52
+ def default_store=(store)
53
+ cfg = Config.new
54
+ cfg.stores[:default] = store
55
+ StrokeDB.default_config = cfg
56
+ end
57
+ end
58
+
59
+ if ENV['DEBUG'] || $DEBUG
60
+ def DEBUG
61
+ yield
62
+ end
63
+ else
64
+ def DEBUG
65
+ end
66
+ end
67
+
68
+ OPTIMIZATIONS = []
69
+ OPTIMIZATIONS << :C unless RUBY_PLATFORM =~ /java/
70
+ OPTIMIZATIONS << :Java if RUBY_PLATFORM =~ /java/
71
+
72
+ class NoDefaultStoreError < Exception ; end
73
+ end
74
+
75
+ require 'strokedb/nsurl'
76
+ require 'strokedb/util'
77
+ require 'strokedb/document'
78
+ require 'strokedb/config'
79
+ require 'strokedb/data_structures'
80
+ require 'strokedb/volumes'
81
+ require 'strokedb/sync'
82
+ require 'strokedb/index'
83
+ require 'strokedb/view'
84
+ require 'strokedb/transaction'
85
+ require 'strokedb/stores'
@@ -33,7 +33,7 @@ module StrokeDB
33
33
  opts = opts.stringify_keys
34
34
 
35
35
  config = new(opts['default'])
36
- storages = opts['storages'] || [:memory_chunk, :file_chunk]
36
+ storages = opts['storages'] || [:memory, :file]
37
37
 
38
38
  base_path = opts['base_path'] || './'
39
39
 
@@ -58,8 +58,8 @@ module StrokeDB
58
58
 
59
59
  config.add_index(:default, opts['index'] || :inverted_list, index_storages.first)
60
60
 
61
- config.add_store(:default, opts['store'] || :skiplist,
62
- { :storage => storages.first }.merge(opts['store_options'] || {}))
61
+ config.add_store(:default, opts['store'], # FIXME: nil here is a Bad Thing (tm)
62
+ { :storage => storages.first, :path => base_path }.merge(opts['store_options'] || {}))
63
63
 
64
64
  ### save config ###
65
65
 
@@ -106,13 +106,14 @@ module StrokeDB
106
106
  end
107
107
 
108
108
  def add_store(key, type, options = {})
109
+
109
110
  options[:storage] = @storages[options[:storage] || :default]
110
111
  raise "Missing storage for store #{key}" unless options[:storage]
111
-
112
+
112
113
  options[:index] ||= @indexes[options[:index] || :default]
113
-
114
+
114
115
  store_instance = constantize(:store, type).new(options)
115
-
116
+
116
117
  if options[:index]
117
118
  options[:index].document_store = store_instance
118
119
  end
@@ -120,6 +121,10 @@ module StrokeDB
120
121
  @stores[key] = store_instance
121
122
  end
122
123
 
124
+ def inspect
125
+ "#<StrokeDB::Config:0x#{object_id.to_s(16)}>"
126
+ end
127
+
123
128
  private
124
129
 
125
130
  def constantize(name,type)
@@ -134,9 +139,9 @@ module StrokeDB
134
139
  end
135
140
  end
136
141
 
137
- class <<self
142
+ class << self
138
143
  def use_perthread_default_config!
139
- class <<self
144
+ class << self
140
145
  def default_config
141
146
  Thread.current['StrokeDB.default_config']
142
147
  end
@@ -146,7 +151,7 @@ module StrokeDB
146
151
  end
147
152
  end
148
153
  def use_global_default_config!
149
- class <<self
154
+ class << self
150
155
  def default_config
151
156
  $strokedb_default_config
152
157
  end
@@ -0,0 +1,87 @@
1
+ require 'irb'
2
+ require 'core_ext/string'
3
+
4
+
5
+ module StrokeDB
6
+
7
+ module Console
8
+ RAM_BASE_PATH = '.console-ram.strokedb'
9
+
10
+ def self.included(klass)
11
+ klass.module_eval do
12
+
13
+ def setup
14
+ if ARGV.last.is_a? String
15
+ if (@@loc = ARGV.pop) == 'RAM'
16
+ puts 'Using in-memory storage.'
17
+ FileUtils.rm_rf RAM_BASE_PATH
18
+ ::StrokeDB::Config.build :default => true, :storages => [:memory], :base_path => RAM_BASE_PATH
19
+ else
20
+ puts "Using #{@@loc} storage."
21
+ ::StrokeDB::Config.build :default => true, :base_path => @@loc
22
+ end
23
+ else
24
+ @@loc = '.console.strokedb'
25
+ ::StrokeDB::Config.build :default => true, :base_path => @@loc
26
+ end
27
+ @@store = ::StrokeDB::default_store
28
+ @@saved = false
29
+ end
30
+
31
+ def save!
32
+ @@store.storage.sync_chained_storages!
33
+ @@saved = true
34
+ @@store
35
+ end
36
+ def saved?
37
+ @@saved
38
+ end
39
+
40
+ def clear!
41
+ if @@loc == 'RAM'
42
+ FileUtils.rm_rf RAM_BASE_PATH
43
+ else
44
+ FileUtils.rm_rf @@loc
45
+ end
46
+ setup
47
+ "Database has been wiped out."
48
+ end
49
+
50
+ def find(*args)
51
+ @@store.find(*args)
52
+ end
53
+
54
+ def store
55
+ @@store
56
+ end
57
+
58
+ def sandbox?
59
+ @@sandbox
60
+ end
61
+
62
+ def reload!
63
+ silence_warnings do
64
+ load "strokedb.rb"
65
+ end
66
+ StrokeDB
67
+ end
68
+
69
+ def help!
70
+ puts ("
71
+ - save! Save the console's store (by default, a file in your current directory named console.strokedb)
72
+ - clear! Drop the console's store (destructive, and launches you out of the session)
73
+ - find <uuid> Find document by UUID in the console's store (example: find 'a4430ff1-6cb4-4428-a292-7ab8b77de467')
74
+ - Doc Alias for Document
75
+ - store Alias for the console's store's object
76
+ ".unindent!)
77
+ end
78
+
79
+ end
80
+ klass.send(:include, StrokeDB)
81
+ klass.send(:setup)
82
+
83
+ puts "StrokeDB #{::StrokeDB::VERSION} (help! for more info)"
84
+ end # self.included
85
+ end # Console
86
+ Doc = Document
87
+ end # StrokeDB
@@ -0,0 +1,10 @@
1
+ require 'core_ext/kernel'
2
+ require 'core_ext/object'
3
+ require 'core_ext/string'
4
+ require 'core_ext/symbol'
5
+ require 'core_ext/enumerable'
6
+ require 'core_ext/hash'
7
+ require 'core_ext/fixnum'
8
+ require 'core_ext/float'
9
+ require 'core_ext/infinity'
10
+ require 'core_ext/blank'
@@ -7,7 +7,7 @@ class Object
7
7
  # to
8
8
  # if !address.blank?
9
9
  def blank?
10
- respond_to?(:empty?) ? empty? : !self
10
+ respond_to?(:empty?) ? empty? : !truthy?
11
11
  end
12
12
  end
13
13
 
@@ -0,0 +1,4 @@
1
+ class Float
2
+ ::Infinity = 1.0 / 0.0 unless defined? ::Infinity
3
+ ::NaN = 0.0 / 0.0 unless defined? ::NaN
4
+ end
@@ -0,0 +1,33 @@
1
+ # These are for use in Range arguments for View#find.
2
+ # We don't provide correct spaceship operator <=>
3
+ # to preserve performance.
4
+ #
5
+ class Object
6
+ def infinite?
7
+ false
8
+ end
9
+ end
10
+
11
+ class Numeric
12
+ def infinite?
13
+ self.abs == Infinity
14
+ end
15
+ end
16
+
17
+ InfiniteString = Class.new(String) do
18
+ def infinite?
19
+ true
20
+ end
21
+ end.new.freeze
22
+
23
+ InfiniteTime = Class.new(Time) do
24
+ def infinite?
25
+ true
26
+ end
27
+ end.new.freeze
28
+
29
+ # Syntactic sugar: sweet aliases for daily use.
30
+ # For use like (SmallestString.."a") in View#find()
31
+ #
32
+ LargestString = SmallestString = StringInfinity = InfiniteString
33
+ LargestTime = SmallestTime = TimeInfinity = InfiniteTime
@@ -0,0 +1,41 @@
1
+ module Kernel
2
+ def require_one_of(*args)
3
+ if args.first.class == Array
4
+ args = args.first
5
+ original_args = args[1]
6
+ end
7
+ original_args ||= args
8
+
9
+ begin
10
+ require args.shift
11
+ rescue LoadError
12
+ raise LoadError, "You need one of these gems: #{original_args.join(', ')}" if
13
+ args.empty?
14
+ require_one_of(args, original_args)
15
+ end
16
+
17
+ end
18
+
19
+ # Helps to extract arguments for an overloaded methods:
20
+ # def some_method(*args)
21
+ # store, name, options = extract(Store, String, Hash, args)
22
+ # end
23
+ #
24
+ # This method tries to extract arguments according to their type.
25
+ # If the correct type is missing, var is set to nil.
26
+ # If some of the input arguments are not matched, ArgumentError is raised.
27
+ #
28
+ def extract(*template_and_args)
29
+ args = template_and_args.pop
30
+ result = []
31
+
32
+ args.each do |a|
33
+ unless while t = template_and_args.shift
34
+ t === a and result.push a and break 1 or result.push nil
35
+ end
36
+ raise ArgumentError, "Unexpected argument #{a.inspect} is passed!"
37
+ end
38
+ end
39
+ result + template_and_args.map{ nil }
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ require 'inline'
2
+
3
+ # partially extracted from ActiveRecord (http://rubyforge.org/projects/activesupport/)
4
+
5
+ class Object
6
+ unless respond_to?(:send!)
7
+ # Anticipating Ruby 1.9 neutering send
8
+ alias send! send
9
+ end
10
+
11
+ # Tricky, tricky! (-:
12
+ def truthy?
13
+ !!self
14
+ end
15
+
16
+ end