gemmyrb 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2e8b98d32d322e6d51bed3e6d7fe795e61eb2ea
4
- data.tar.gz: 4cbcb9bc58eb5353d1d92eb2f0e24bbe91a316b4
3
+ metadata.gz: b2d90fcdf579db68f27ca1757ff19a799fcfc922
4
+ data.tar.gz: dec4516b981738b2494a9886227c22ebb1de168d
5
5
  SHA512:
6
- metadata.gz: acfad1fbbea670260ff7facce87015063e43ed46eb5a17dd5bc794e03c624d4d93b8a262c201fb9e8c6d773e730294181d4b5b70e9462d19732f05b3257863b0
7
- data.tar.gz: 78d7cbd03c70f10e9afdb10c174010e840935260e87b18cd792728cb0af5c82a0808a557afefd0c7a3629dd06fe897f57900cb63ea2d4380e7d1ef1d2342c16f
6
+ metadata.gz: 2492d8942963c75d93fac869831113119249a3eb4718c4aaf495acddacb6655a7844072362c36a56043e556f488a38477bd3907f58012c03baee62dbb341703c
7
+ data.tar.gz: 17f0dee57643eaa6f3ce8df6fdad7e271eb8a8232b358316bdfffb2b397ce03ffaed083549e769e8d0971dd2836d572946c4b09b53816e35a624df175af7f73b
@@ -16,7 +16,8 @@ class Gemmy::Components::Cache < Hash
16
16
  def initialize(db_name, hash={})
17
17
  cache_path = self.class.setup_cache_folder
18
18
  @db = hash.persisted "#{cache_path}/#{db_name}.yaml"
19
- @db.set_state hash
19
+ # copy db state into memory
20
+ @db.data.each { |k,v| self[k] = v.deep_dup }
20
21
  end
21
22
 
22
23
  def get_or_set(*keys, &blk)
@@ -40,6 +41,19 @@ class Gemmy::Components::Cache < Hash
40
41
  @db.dig *keys
41
42
  end
42
43
 
44
+ # Delete functions like "dig_delete"
45
+ # I.e. if given a few keys as arguments, it will treat only the last as
46
+ # a delete key and all the rest as dig keys.
47
+ def dig_delete(*keys)
48
+ @db.dig_delete *keys
49
+ key_to_delete = keys.pop
50
+ if keys.empty?
51
+ self.delete key_to_delete
52
+ else
53
+ self.dig(*keys).delete key_to_delete
54
+ end
55
+ end
56
+
43
57
  def set_state(hash)
44
58
  @db.set_state hash
45
59
  each_key &m(:delete)
@@ -17,6 +17,18 @@ module Gemmy::Patches::HashPatch
17
17
 
18
18
  module InstanceMethods
19
19
 
20
+ module Indifferent
21
+ def indifferent
22
+ self.with_indifferent_access
23
+ end
24
+ end
25
+
26
+ module Easy
27
+ def easy
28
+ self.with_indifferent_access
29
+ end
30
+ end
31
+
20
32
  module UpdateKeys
21
33
  # facets
22
34
  # in place
@@ -297,11 +309,13 @@ module Gemmy::Patches::HashPatch
297
309
  #
298
310
 
299
311
  module Persisted
312
+
300
313
  def persisted(path)
301
314
  require 'yaml/store'
302
315
  autovivified = Gemmy.patch("hash/i/autovivified")\
303
316
  .method(:_autovivified)
304
317
  autovivified.call(self).tap do |hash|
318
+ # load data from YAML into memory
305
319
  hash.instance_exec do
306
320
  @store = YAML::Store.new path
307
321
  @store.transaction do
@@ -312,9 +326,11 @@ module Gemmy::Patches::HashPatch
312
326
  hash.extend Gemmy::Patches::HashPatch::PersistedHash
313
327
  end
314
328
  end
329
+
315
330
  def db
316
331
  @store
317
332
  end
333
+
318
334
  end
319
335
 
320
336
  end # end instance methods
@@ -322,9 +338,11 @@ module Gemmy::Patches::HashPatch
322
338
  # Helper methods for the persistence patch
323
339
  #
324
340
  module PersistedHash
341
+
325
342
  def get(*keys, disk: true)
326
343
  disk ? @store.transaction { @store[:data].dig(*keys) } : dig(*keys)
327
344
  end
345
+
328
346
  def set(*keys, val)
329
347
  bury = Gemmy::Patches::HashPatch::InstanceMethods::Bury.method(:bury)
330
348
  bury.call(self, *keys, val)
@@ -333,10 +351,29 @@ module Gemmy::Patches::HashPatch
333
351
  end
334
352
  val
335
353
  end
354
+
336
355
  def data
337
356
  @store.transaction { @store[:data] }
338
357
  end
339
358
 
359
+ # Delete functions like "dig_delete"
360
+ # I.e. if given a few keys as arguments, it will treat only the last as
361
+ # a delete key and all the rest as dig keys.
362
+ def dig_delete(*keys)
363
+ key_to_delete = keys.pop
364
+ if keys.empty?
365
+ delete key_to_delete
366
+ @store.transaction do
367
+ @store[:data].delete key_to_delete
368
+ end
369
+ else
370
+ dig(*keys).delete key_to_delete
371
+ @store.transaction do
372
+ @store[:data].dig(*keys).delete key_to_delete
373
+ end
374
+ end
375
+ end
376
+
340
377
  # This won't autovivify the hash automatically
341
378
  def set_state(hash)
342
379
  @store.transaction { @store[:data] = hash }
@@ -7,6 +7,12 @@ module Gemmy::Patches::StringPatch
7
7
 
8
8
  module InstanceMethods
9
9
 
10
+ module Unchomp
11
+ def unchomp
12
+ self.ends_with?("\n") ? self : "#{self}\n"
13
+ end
14
+ end
15
+
10
16
  module SyllableCount
11
17
  def syllable_count
12
18
  Odyssey.flesch_kincaid_re(self, true)["syllable_count"]
data/lib/gemmy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Gemmy
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemmyrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - max pleaner