picky 2.7.0 → 3.0.0.pre1

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 (213) hide show
  1. data/lib/picky/adapters/rack/base.rb +20 -16
  2. data/lib/picky/adapters/rack/live_parameters.rb +28 -24
  3. data/lib/picky/adapters/rack/search.rb +67 -0
  4. data/lib/picky/adapters/rack.rb +27 -23
  5. data/lib/picky/application.rb +246 -236
  6. data/lib/picky/backend/base.rb +115 -119
  7. data/lib/picky/backend/file/basic.rb +102 -98
  8. data/lib/picky/backend/file/json.rb +27 -23
  9. data/lib/picky/backend/file/marshal.rb +32 -28
  10. data/lib/picky/backend/file/text.rb +45 -41
  11. data/lib/picky/backend/files.rb +19 -15
  12. data/lib/picky/backend/redis/basic.rb +76 -72
  13. data/lib/picky/backend/redis/list_hash.rb +40 -36
  14. data/lib/picky/backend/redis/string_hash.rb +30 -26
  15. data/lib/picky/backend/redis.rb +32 -28
  16. data/lib/picky/bundle.rb +82 -57
  17. data/lib/{bundling.rb → picky/bundling.rb} +0 -0
  18. data/lib/picky/calculations/location.rb +51 -47
  19. data/lib/picky/categories.rb +60 -56
  20. data/lib/picky/categories_indexed.rb +73 -82
  21. data/lib/picky/categories_indexing.rb +12 -8
  22. data/lib/picky/category.rb +109 -120
  23. data/lib/picky/category_indexed.rb +39 -41
  24. data/lib/picky/category_indexing.rb +123 -125
  25. data/lib/picky/character_substituters/west_european.rb +32 -26
  26. data/lib/{constants.rb → picky/constants.rb} +0 -0
  27. data/lib/picky/cores.rb +96 -92
  28. data/lib/{deployment.rb → picky/deployment.rb} +0 -0
  29. data/lib/picky/frontend_adapters/rack.rb +133 -118
  30. data/lib/picky/generators/aliases.rb +5 -3
  31. data/lib/picky/generators/base.rb +11 -7
  32. data/lib/picky/generators/partial/default.rb +7 -3
  33. data/lib/picky/generators/partial/none.rb +24 -20
  34. data/lib/picky/generators/partial/strategy.rb +20 -16
  35. data/lib/picky/generators/partial/substring.rb +94 -90
  36. data/lib/picky/generators/partial_generator.rb +11 -7
  37. data/lib/picky/generators/similarity/default.rb +9 -5
  38. data/lib/picky/generators/similarity/double_metaphone.rb +20 -16
  39. data/lib/picky/generators/similarity/metaphone.rb +20 -16
  40. data/lib/picky/generators/similarity/none.rb +23 -19
  41. data/lib/picky/generators/similarity/phonetic.rb +49 -45
  42. data/lib/picky/generators/similarity/soundex.rb +20 -16
  43. data/lib/picky/generators/similarity/strategy.rb +10 -6
  44. data/lib/picky/generators/similarity_generator.rb +11 -7
  45. data/lib/picky/generators/strategy.rb +14 -10
  46. data/lib/picky/generators/weights/default.rb +9 -5
  47. data/lib/picky/generators/weights/logarithmic.rb +30 -26
  48. data/lib/picky/generators/weights/strategy.rb +10 -6
  49. data/lib/picky/generators/weights_generator.rb +11 -7
  50. data/lib/picky/helpers/measuring.rb +20 -16
  51. data/lib/picky/indexed/bundle/base.rb +39 -37
  52. data/lib/picky/indexed/bundle/memory.rb +68 -64
  53. data/lib/picky/indexed/bundle/redis.rb +73 -69
  54. data/lib/picky/indexed/wrappers/bundle/calculation.rb +26 -22
  55. data/lib/picky/indexed/wrappers/bundle/location.rb +30 -26
  56. data/lib/picky/indexed/wrappers/bundle/wrapper.rb +36 -32
  57. data/lib/picky/indexed/wrappers/category/location.rb +17 -13
  58. data/lib/picky/indexed/wrappers/exact_first.rb +46 -42
  59. data/lib/picky/indexers/base.rb +26 -22
  60. data/lib/picky/indexers/parallel.rb +62 -58
  61. data/lib/picky/indexers/serial.rb +41 -37
  62. data/lib/picky/indexes/index.rb +400 -0
  63. data/lib/picky/indexes/index_indexed.rb +24 -0
  64. data/lib/picky/indexes/index_indexing.rb +138 -0
  65. data/lib/picky/indexes/memory.rb +20 -0
  66. data/lib/picky/indexes/redis.rb +20 -0
  67. data/lib/picky/indexes.rb +68 -61
  68. data/lib/picky/indexes_indexed.rb +16 -12
  69. data/lib/picky/indexes_indexing.rb +41 -37
  70. data/lib/picky/indexing/bundle/base.rb +216 -205
  71. data/lib/picky/indexing/bundle/memory.rb +16 -11
  72. data/lib/picky/indexing/bundle/redis.rb +14 -12
  73. data/lib/picky/indexing/wrappers/category/location.rb +17 -13
  74. data/lib/picky/interfaces/live_parameters.rb +159 -154
  75. data/lib/picky/loader.rb +267 -304
  76. data/lib/picky/loggers/search.rb +20 -13
  77. data/lib/picky/no_source_specified_exception.rb +7 -3
  78. data/lib/picky/performant.rb +6 -2
  79. data/lib/picky/query/allocation.rb +71 -67
  80. data/lib/picky/query/allocations.rb +99 -94
  81. data/lib/picky/query/combination.rb +70 -66
  82. data/lib/picky/query/combinations/base.rb +56 -52
  83. data/lib/picky/query/combinations/memory.rb +36 -32
  84. data/lib/picky/query/combinations/redis.rb +66 -62
  85. data/lib/picky/query/indexes.rb +175 -160
  86. data/lib/picky/query/qualifier_category_mapper.rb +43 -0
  87. data/lib/picky/query/token.rb +165 -172
  88. data/lib/picky/query/tokens.rb +86 -82
  89. data/lib/picky/query/weights.rb +44 -48
  90. data/lib/picky/query.rb +5 -1
  91. data/lib/picky/rack/harakiri.rb +51 -47
  92. data/lib/picky/results.rb +81 -77
  93. data/lib/picky/search.rb +169 -158
  94. data/lib/picky/sinatra.rb +34 -0
  95. data/lib/picky/sources/base.rb +73 -70
  96. data/lib/picky/sources/couch.rb +61 -57
  97. data/lib/picky/sources/csv.rb +68 -64
  98. data/lib/picky/sources/db.rb +139 -135
  99. data/lib/picky/sources/delicious.rb +52 -48
  100. data/lib/picky/sources/mongo.rb +68 -63
  101. data/lib/picky/sources/wrappers/base.rb +20 -16
  102. data/lib/picky/sources/wrappers/location.rb +37 -33
  103. data/lib/picky/statistics.rb +46 -43
  104. data/lib/picky/tasks.rb +3 -0
  105. data/lib/picky/tokenizers/base.rb +192 -187
  106. data/lib/picky/tokenizers/index.rb +25 -21
  107. data/lib/picky/tokenizers/location.rb +33 -29
  108. data/lib/picky/tokenizers/query.rb +49 -43
  109. data/lib/picky.rb +21 -13
  110. data/lib/tasks/application.rake +1 -1
  111. data/lib/tasks/index.rake +3 -3
  112. data/lib/tasks/routes.rake +1 -1
  113. data/lib/tasks/server.rake +1 -1
  114. data/spec/lib/adapters/rack/base_spec.rb +1 -1
  115. data/spec/lib/adapters/rack/live_parameters_spec.rb +1 -1
  116. data/spec/lib/adapters/rack/query_spec.rb +1 -1
  117. data/spec/lib/application_spec.rb +39 -32
  118. data/spec/lib/backend/file/basic_spec.rb +2 -2
  119. data/spec/lib/backend/file/json_spec.rb +2 -2
  120. data/spec/lib/backend/file/marshal_spec.rb +2 -2
  121. data/spec/lib/backend/file/text_spec.rb +1 -1
  122. data/spec/lib/backend/files_spec.rb +14 -24
  123. data/spec/lib/backend/redis/basic_spec.rb +2 -2
  124. data/spec/lib/backend/redis/list_hash_spec.rb +3 -3
  125. data/spec/lib/backend/redis/string_hash_spec.rb +3 -3
  126. data/spec/lib/backend/redis_spec.rb +20 -13
  127. data/spec/lib/calculations/location_spec.rb +1 -1
  128. data/spec/lib/categories_indexed_spec.rb +16 -34
  129. data/spec/lib/category_indexed_spec.rb +9 -27
  130. data/spec/lib/category_indexing_spec.rb +2 -3
  131. data/spec/lib/category_spec.rb +10 -10
  132. data/spec/lib/character_substituters/west_european_spec.rb +6 -5
  133. data/spec/lib/cores_spec.rb +17 -17
  134. data/spec/lib/extensions/symbol_spec.rb +15 -1
  135. data/spec/lib/frontend_adapters/rack_spec.rb +20 -20
  136. data/spec/lib/generators/aliases_spec.rb +3 -3
  137. data/spec/lib/generators/cacher_strategy_spec.rb +1 -1
  138. data/spec/lib/generators/partial/default_spec.rb +3 -3
  139. data/spec/lib/generators/partial/none_spec.rb +2 -2
  140. data/spec/lib/generators/partial/substring_spec.rb +1 -1
  141. data/spec/lib/generators/partial_generator_spec.rb +3 -3
  142. data/spec/lib/generators/similarity/double_metaphone_spec.rb +1 -1
  143. data/spec/lib/generators/similarity/metaphone_spec.rb +1 -1
  144. data/spec/lib/generators/similarity/none_spec.rb +1 -1
  145. data/spec/lib/generators/similarity/phonetic_spec.rb +1 -1
  146. data/spec/lib/generators/similarity/soundex_spec.rb +1 -1
  147. data/spec/lib/generators/similarity_generator_spec.rb +2 -2
  148. data/spec/lib/generators/weights/logarithmic_spec.rb +1 -1
  149. data/spec/lib/generators/weights_generator_spec.rb +1 -1
  150. data/spec/lib/helpers/measuring_spec.rb +2 -2
  151. data/spec/lib/indexed/bundle/memory_spec.rb +6 -6
  152. data/spec/lib/indexed/bundle/redis_spec.rb +4 -4
  153. data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +2 -3
  154. data/spec/lib/indexed/wrappers/bundle/wrapper_spec.rb +2 -2
  155. data/spec/lib/indexed/wrappers/exact_first_spec.rb +5 -5
  156. data/spec/lib/indexers/base_spec.rb +1 -1
  157. data/spec/lib/indexers/parallel_spec.rb +1 -1
  158. data/spec/lib/indexers/serial_spec.rb +1 -1
  159. data/spec/lib/{index/base_indexed_spec.rb → indexes/index_indexed_spec.rb} +3 -3
  160. data/spec/lib/{index/base_indexing_spec.rb → indexes/index_indexing_spec.rb} +19 -2
  161. data/spec/lib/{index/base_spec.rb → indexes/index_spec.rb} +6 -25
  162. data/spec/lib/{index → indexes}/redis_spec.rb +1 -1
  163. data/spec/lib/indexes_class_spec.rb +2 -2
  164. data/spec/lib/indexes_indexed_spec.rb +1 -1
  165. data/spec/lib/indexes_indexing_spec.rb +1 -1
  166. data/spec/lib/indexes_spec.rb +1 -1
  167. data/spec/lib/indexing/bundle/base_spec.rb +7 -5
  168. data/spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb +4 -4
  169. data/spec/lib/indexing/bundle/memory_spec.rb +15 -15
  170. data/spec/lib/indexing/bundle/redis_spec.rb +9 -9
  171. data/spec/lib/interfaces/live_parameters_spec.rb +5 -5
  172. data/spec/lib/loader_spec.rb +17 -19
  173. data/spec/lib/loggers/search_spec.rb +2 -2
  174. data/spec/lib/query/allocation_spec.rb +1 -1
  175. data/spec/lib/query/allocations_spec.rb +1 -1
  176. data/spec/lib/query/combination_spec.rb +4 -4
  177. data/spec/lib/query/combinations/base_spec.rb +1 -1
  178. data/spec/lib/query/combinations/memory_spec.rb +1 -1
  179. data/spec/lib/query/combinations/redis_spec.rb +1 -1
  180. data/spec/lib/query/indexes_spec.rb +7 -2
  181. data/spec/lib/query/qualifier_category_mapper_spec.rb +34 -0
  182. data/spec/lib/query/token_spec.rb +32 -53
  183. data/spec/lib/query/tokens_spec.rb +30 -35
  184. data/spec/lib/query/weights_spec.rb +16 -16
  185. data/spec/lib/rack/harakiri_spec.rb +5 -5
  186. data/spec/lib/results_spec.rb +1 -1
  187. data/spec/lib/search_spec.rb +24 -22
  188. data/spec/lib/sinatra_spec.rb +36 -0
  189. data/spec/lib/sources/base_spec.rb +1 -1
  190. data/spec/lib/sources/couch_spec.rb +9 -9
  191. data/spec/lib/sources/csv_spec.rb +7 -7
  192. data/spec/lib/sources/db_spec.rb +2 -2
  193. data/spec/lib/sources/delicious_spec.rb +5 -5
  194. data/spec/lib/sources/mongo_spec.rb +7 -7
  195. data/spec/lib/sources/wrappers/base_spec.rb +2 -2
  196. data/spec/lib/sources/wrappers/location_spec.rb +1 -1
  197. data/spec/lib/statistics_spec.rb +1 -1
  198. data/spec/lib/tokenizers/base_spec.rb +2 -2
  199. data/spec/lib/tokenizers/index_spec.rb +1 -1
  200. data/spec/lib/tokenizers/query_spec.rb +1 -1
  201. metadata +30 -30
  202. data/lib/picky/adapters/rack/query.rb +0 -65
  203. data/lib/picky/index/base.rb +0 -409
  204. data/lib/picky/index/base_indexed.rb +0 -29
  205. data/lib/picky/index/base_indexing.rb +0 -127
  206. data/lib/picky/index/memory.rb +0 -16
  207. data/lib/picky/index/redis.rb +0 -16
  208. data/lib/picky/query/qualifiers.rb +0 -76
  209. data/lib/picky/query/solr.rb +0 -60
  210. data/lib/picky/signals.rb +0 -8
  211. data/lib/picky-tasks.rb +0 -6
  212. data/lib/tasks/spec.rake +0 -11
  213. data/spec/lib/query/qualifiers_spec.rb +0 -31
@@ -1,123 +1,119 @@
1
- module Backend
2
-
3
- class Base
4
-
5
- attr_reader :bundle_name,
6
- :prepared,
7
- :inverted,
8
- :weights,
9
- :similarity,
10
- :configuration,
11
- :category,
12
- :identifier
13
-
14
- delegate :index_name, :category_name, :to => :@category
15
-
16
- def initialize bundle_name, category
17
- @identifier = "#{category.identifier}:#{bundle_name}"
18
- @bundle_name = bundle_name
19
- @category = category
20
- @prepared = File::Text.new category.prepared_index_path
21
- end
22
-
23
- # Delegators.
24
- #
25
-
26
- # Retrieving data.
27
- #
28
- def retrieve &block
29
- prepared.retrieve &block
30
- end
31
-
32
- # Dumping.
33
- #
34
- def dump_inverted inverted_hash
35
- timed_exclaim %Q{"#{identifier}": => #{inverted}.}
36
- inverted.dump inverted_hash
37
- end
38
- def dump_weights weights_hash
39
- timed_exclaim %Q{"#{identifier}": => #{weights}.}
40
- weights.dump weights_hash
41
- end
42
- def dump_similarity similarity_hash
43
- timed_exclaim %Q{"#{identifier}": => #{similarity}.}
44
- similarity.dump similarity_hash
45
- end
46
- def dump_configuration configuration_hash
47
- timed_exclaim %Q{"#{identifier}": => #{configuration}.}
48
- configuration.dump configuration_hash
49
- end
50
-
51
- # Loading.
52
- #
53
- def load_inverted
54
- inverted.load
55
- end
56
- def load_similarity
57
- similarity.load
58
- end
59
- def load_weights
60
- weights.load
61
- end
62
- def load_configuration
63
- configuration.load
64
- end
65
-
66
- # Cache ok?
67
- #
68
- def inverted_cache_ok?
69
- inverted.cache_ok?
70
- end
71
- def similarity_cache_ok?
72
- similarity.cache_ok?
73
- end
74
- def weights_cache_ok?
75
- weights.cache_ok?
76
- end
77
-
78
- # Cache small?
79
- #
80
- def inverted_cache_small?
81
- inverted.cache_small?
82
- end
83
- def similarity_cache_small?
84
- similarity.cache_small?
85
- end
86
- def weights_cache_small?
87
- weights.cache_small?
88
- end
89
-
90
- # Copies the indexes to the "backup" directory.
91
- #
92
- def backup
93
- inverted.backup
94
- weights.backup
95
- similarity.backup
96
- configuration.backup
97
- end
98
-
99
- # Restores the indexes from the "backup" directory.
100
- #
101
- def restore
102
- inverted.restore
103
- weights.restore
104
- similarity.restore
105
- configuration.restore
106
- end
107
-
108
- # Delete all index files.
109
- #
110
- def delete
111
- inverted.delete
112
- weights.delete
113
- similarity.delete
114
- configuration.delete
115
- end
1
+ module Picky
2
+
3
+ module Backend
4
+
5
+ class Base
6
+
7
+ attr_reader :bundle,
8
+ :inverted,
9
+ :weights,
10
+ :similarity,
11
+ :configuration
12
+
13
+ delegate :identifier,
14
+ :to => :bundle
15
+
16
+ def initialize bundle
17
+ @bundle = bundle
18
+ end
19
+ def identifier
20
+ bundle.identifier
21
+ end
22
+
23
+ # Delegators.
24
+ #
25
+
26
+ # Dumping.
27
+ #
28
+ def dump_inverted inverted_hash
29
+ timed_exclaim %Q{"#{identifier}": => #{inverted}.}
30
+ inverted.dump inverted_hash
31
+ end
32
+ def dump_weights weights_hash
33
+ timed_exclaim %Q{"#{identifier}": => #{weights}.}
34
+ weights.dump weights_hash
35
+ end
36
+ def dump_similarity similarity_hash
37
+ timed_exclaim %Q{"#{identifier}": => #{similarity}.}
38
+ similarity.dump similarity_hash
39
+ end
40
+ def dump_configuration configuration_hash
41
+ timed_exclaim %Q{"#{identifier}": => #{configuration}.}
42
+ configuration.dump configuration_hash
43
+ end
44
+
45
+ # Loading.
46
+ #
47
+ def load_inverted
48
+ inverted.load
49
+ end
50
+ def load_similarity
51
+ similarity.load
52
+ end
53
+ def load_weights
54
+ weights.load
55
+ end
56
+ def load_configuration
57
+ configuration.load
58
+ end
59
+
60
+ # Cache ok?
61
+ #
62
+ def inverted_cache_ok?
63
+ inverted.cache_ok?
64
+ end
65
+ def similarity_cache_ok?
66
+ similarity.cache_ok?
67
+ end
68
+ def weights_cache_ok?
69
+ weights.cache_ok?
70
+ end
71
+
72
+ # Cache small?
73
+ #
74
+ def inverted_cache_small?
75
+ inverted.cache_small?
76
+ end
77
+ def similarity_cache_small?
78
+ similarity.cache_small?
79
+ end
80
+ def weights_cache_small?
81
+ weights.cache_small?
82
+ end
83
+
84
+ # Copies the indexes to the "backup" directory.
85
+ #
86
+ def backup
87
+ inverted.backup
88
+ weights.backup
89
+ similarity.backup
90
+ configuration.backup
91
+ end
92
+
93
+ # Restores the indexes from the "backup" directory.
94
+ #
95
+ def restore
96
+ inverted.restore
97
+ weights.restore
98
+ similarity.restore
99
+ configuration.restore
100
+ end
101
+
102
+ # Delete all index files.
103
+ #
104
+ def delete
105
+ inverted.delete
106
+ weights.delete
107
+ similarity.delete
108
+ configuration.delete
109
+ end
110
+
111
+ #
112
+ #
113
+ def to_s
114
+ "#{self.class}(#{bundle.identifier})"
115
+ end
116
116
 
117
- #
118
- #
119
- def to_s
120
- "#{self.class}(#{prepared}, #{bundle_name}, #{category.identifier})"
121
117
  end
122
118
 
123
119
  end
@@ -1,105 +1,109 @@
1
- module Backend
1
+ module Picky
2
2
 
3
- # Handles all aspects of index files, such as dumping/loading.
4
- #
5
- module File
3
+ module Backend
6
4
 
7
- # Base class for all index files.
5
+ # Handles all aspects of index files, such as dumping/loading.
8
6
  #
9
- # Provides necessary helper methods for its
10
- # subclasses.
11
- # Not directly useable, as it does not provide
12
- # dump/load methods.
13
- #
14
- class Basic
15
-
16
- # This file's location.
17
- #
18
- attr_reader :cache_path
19
-
20
- # An index cache takes a path, without file extension,
21
- # which will be provided by the subclasses.
22
- #
23
- def initialize cache_path
24
- @cache_path = "#{cache_path}.#{extension}"
25
- end
26
-
27
- # The default extension for index files is "index".
28
- #
29
- def extension
30
- :index
31
- end
32
-
33
- # Will copy the index file to a location that
34
- # is in a directory named "backup" right under
35
- # the directory the index file is in.
36
- #
37
- def backup
38
- prepare_backup backup_directory
39
- FileUtils.cp cache_path, target, verbose: true
40
- end
41
-
42
- # The backup directory of this file.
43
- # Equal to the file's dirname plus /backup
44
- #
45
-
46
- def backup_directory
47
- ::File.join ::File.dirname(cache_path), 'backup'
48
- end
49
-
50
- # Prepares the backup directory for the file.
51
- #
52
- def prepare_backup target
53
- FileUtils.mkdir target unless Dir.exists?(target)
54
- end
55
-
56
- # Copies the file from its backup location back
57
- # to the original location.
58
- #
59
- def restore
60
- FileUtils.cp backup_file_path_of(cache_path), cache_path, verbose: true
61
- end
62
-
63
- # The backup filename.
64
- #
65
- def backup_file_path_of path
66
- dir, name = ::File.split path
67
- ::File.join dir, 'backup', name
68
- end
69
-
70
- # Deletes the file.
71
- #
72
- def delete
73
- `rm -Rf #{cache_path}`
74
- end
75
-
76
- # Checks.
77
- #
7
+ module File
8
+
9
+ # Base class for all index files.
10
+ #
11
+ # Provides necessary helper methods for its
12
+ # subclasses.
13
+ # Not directly useable, as it does not provide
14
+ # dump/load methods.
15
+ #
16
+ class Basic
17
+
18
+ # This file's location.
19
+ #
20
+ attr_reader :cache_path
21
+
22
+ # An index cache takes a path, without file extension,
23
+ # which will be provided by the subclasses.
24
+ #
25
+ def initialize cache_path
26
+ @cache_path = "#{cache_path}.#{extension}"
27
+ end
28
+
29
+ # The default extension for index files is "index".
30
+ #
31
+ def extension
32
+ :index
33
+ end
34
+
35
+ # Will copy the index file to a location that
36
+ # is in a directory named "backup" right under
37
+ # the directory the index file is in.
38
+ #
39
+ def backup
40
+ prepare_backup backup_directory
41
+ FileUtils.cp cache_path, target, verbose: true
42
+ end
43
+
44
+ # The backup directory of this file.
45
+ # Equal to the file's dirname plus /backup
46
+ #
47
+
48
+ def backup_directory
49
+ ::File.join ::File.dirname(cache_path), 'backup'
50
+ end
51
+
52
+ # Prepares the backup directory for the file.
53
+ #
54
+ def prepare_backup target
55
+ FileUtils.mkdir target unless Dir.exists?(target)
56
+ end
57
+
58
+ # Copies the file from its backup location back
59
+ # to the original location.
60
+ #
61
+ def restore
62
+ FileUtils.cp backup_file_path_of(cache_path), cache_path, verbose: true
63
+ end
64
+
65
+ # The backup filename.
66
+ #
67
+ def backup_file_path_of path
68
+ dir, name = ::File.split path
69
+ ::File.join dir, 'backup', name
70
+ end
71
+
72
+ # Deletes the file.
73
+ #
74
+ def delete
75
+ `rm -Rf #{cache_path}`
76
+ end
77
+
78
+ # Checks.
79
+ #
80
+
81
+ # Is this cache file suspiciously small?
82
+ # (less than 8 Bytes of size)
83
+ #
84
+ def cache_small?
85
+ size_of(cache_path) < 8
86
+ end
87
+ # Is the cache ok? (existing and larger than
88
+ # zero Bytes in size)
89
+ #
90
+ # A small cache is still ok.
91
+ #
92
+ def cache_ok?
93
+ size_of(cache_path) > 0
94
+ end
95
+ # Extracts the size of the file in Bytes.
96
+ #
97
+ def size_of path
98
+ `ls -l #{path} | awk '{print $5}'`.to_i
99
+ end
100
+
101
+ #
102
+ #
103
+ def to_s
104
+ "#{self.class}(#{cache_path})"
105
+ end
78
106
 
79
- # Is this cache file suspiciously small?
80
- # (less than 8 Bytes of size)
81
- #
82
- def cache_small?
83
- size_of(cache_path) < 8
84
- end
85
- # Is the cache ok? (existing and larger than
86
- # zero Bytes in size)
87
- #
88
- # A small cache is still ok.
89
- #
90
- def cache_ok?
91
- size_of(cache_path) > 0
92
- end
93
- # Extracts the size of the file in Bytes.
94
- #
95
- def size_of path
96
- `ls -l #{path} | awk '{print $5}'`.to_i
97
- end
98
-
99
- #
100
- #
101
- def to_s
102
- "#{self.class}(#{cache_path})"
103
107
  end
104
108
 
105
109
  end
@@ -1,30 +1,34 @@
1
- module Backend
1
+ module Picky
2
2
 
3
- module File
3
+ module Backend
4
4
 
5
- # Index files dumped in the JSON format.
6
- #
7
- class JSON < Basic
5
+ module File
8
6
 
9
- # Uses the extension "json".
7
+ # Index files dumped in the JSON format.
10
8
  #
11
- def extension
12
- :json
13
- end
14
- # Loads the index hash from json format.
15
- #
16
- def load
17
- Yajl::Parser.parse ::File.open(cache_path, 'r'), symbolize_keys: true
18
- end
19
- # Dumps the index hash in json format.
20
- #
21
- def dump hash
22
- hash.dump_json cache_path
23
- end
24
- # A json file does not provide retrieve functionality.
25
- #
26
- def retrieve
27
- raise "Can't retrieve from JSON file. Use text file."
9
+ class JSON < Basic
10
+
11
+ # Uses the extension "json".
12
+ #
13
+ def extension
14
+ :json
15
+ end
16
+ # Loads the index hash from json format.
17
+ #
18
+ def load
19
+ Yajl::Parser.parse ::File.open(cache_path, 'r'), symbolize_keys: true
20
+ end
21
+ # Dumps the index hash in json format.
22
+ #
23
+ def dump hash
24
+ hash.dump_json cache_path
25
+ end
26
+ # A json file does not provide retrieve functionality.
27
+ #
28
+ def retrieve
29
+ raise "Can't retrieve from JSON file. Use text file."
30
+ end
31
+
28
32
  end
29
33
 
30
34
  end
@@ -1,34 +1,38 @@
1
- module Backend
2
-
3
- module File
4
-
5
- # Index data in the Ruby Marshal format.
6
- #
7
- class Marshal < Basic
8
-
9
- # Uses the extension "dump".
10
- #
11
- def extension
12
- :dump
13
- end
14
- # Loads the index hash from marshal format.
15
- #
16
- def load
17
- ::Marshal.load ::File.open(cache_path, 'r:binary')
18
- end
19
- # Dumps the index hash in marshal format.
20
- #
21
- def dump hash
22
- hash.dump_marshalled cache_path
23
- end
24
- # A marshal file does not provide retrieve functionality.
1
+ module Picky
2
+
3
+ module Backend
4
+
5
+ module File
6
+
7
+ # Index data in the Ruby Marshal format.
25
8
  #
26
- def retrieve
27
- raise "Can't retrieve from marshalled file. Use text file."
9
+ class Marshal < Basic
10
+
11
+ # Uses the extension "dump".
12
+ #
13
+ def extension
14
+ :dump
15
+ end
16
+ # Loads the index hash from marshal format.
17
+ #
18
+ def load
19
+ ::Marshal.load ::File.open(cache_path, 'r:binary')
20
+ end
21
+ # Dumps the index hash in marshal format.
22
+ #
23
+ def dump hash
24
+ hash.dump_marshalled cache_path
25
+ end
26
+ # A marshal file does not provide retrieve functionality.
27
+ #
28
+ def retrieve
29
+ raise "Can't retrieve from marshalled file. Use text file."
30
+ end
31
+
28
32
  end
29
-
33
+
30
34
  end
31
-
35
+
32
36
  end
33
37
 
34
38
  end
@@ -1,54 +1,58 @@
1
- module Backend
1
+ module Picky
2
2
 
3
- module File
3
+ module Backend
4
4
 
5
- # Index data dumped in the text format.
6
- #
7
- class Text < Basic
5
+ module File
8
6
 
9
- # Uses the extension "txt".
7
+ # Index data dumped in the text format.
10
8
  #
11
- def extension
12
- :txt
13
- end
14
- # Text files are used exclusively for
15
- # prepared data files.
16
- #
17
- def load
18
- raise "Can't load from text file. Use JSON or Marshal."
19
- end
20
- # Text files are used exclusively for
21
- # prepared data files.
22
- #
23
- def dump hash
24
- raise "Can't dump to text file. Use JSON or Marshal."
25
- end
9
+ class Text < Basic
26
10
 
27
- # Retrieves prepared index data in the form
28
- # * id,data\n
29
- # * id,data\n
30
- # * id,data\n
31
- #
32
- # Yields an id string and a symbol token.
33
- #
34
- def retrieve
35
- id = nil
36
- token = nil
37
- ::File.open(cache_path, 'r:binary') do |file|
38
- file.each_line do |line|
39
- id, token = line.split ?,, 2
40
- yield id, (token.chomp! || token).to_sym
11
+ # Uses the extension "txt".
12
+ #
13
+ def extension
14
+ :txt
15
+ end
16
+ # Text files are used exclusively for
17
+ # prepared data files.
18
+ #
19
+ def load
20
+ raise "Can't load from text file. Use JSON or Marshal."
21
+ end
22
+ # Text files are used exclusively for
23
+ # prepared data files.
24
+ #
25
+ def dump hash
26
+ raise "Can't dump to text file. Use JSON or Marshal."
27
+ end
28
+
29
+ # Retrieves prepared index data in the form
30
+ # * id,data\n
31
+ # * id,data\n
32
+ # * id,data\n
33
+ #
34
+ # Yields an id string and a symbol token.
35
+ #
36
+ def retrieve
37
+ id = nil
38
+ token = nil
39
+ ::File.open(cache_path, 'r:binary') do |file|
40
+ file.each_line do |line|
41
+ id, token = line.split ?,, 2
42
+ yield id, (token.chomp! || token).to_sym
43
+ end
41
44
  end
42
45
  end
43
- end
44
46
 
45
- #
46
- #
47
- def open &block
48
- ::File.open cache_path, 'w:binary', &block
49
- end
47
+ #
48
+ #
49
+ def open &block
50
+ ::File.open cache_path, 'w:binary', &block
51
+ end
50
52
 
51
53
 
54
+ end
55
+
52
56
  end
53
57
 
54
58
  end