couchpillow 0.4.9 → 0.4.10

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: 2d7345235a3c65ff275b24df3e7c3a2633445460
4
- data.tar.gz: 0fe1d51ac229b905db59d7c4b6099c813a4412c3
3
+ metadata.gz: a06d6bda2c5d092ce129525276179029fa6f93c0
4
+ data.tar.gz: 45a5414fc84538bcb84bf913d688e0b4fb3de476
5
5
  SHA512:
6
- metadata.gz: af5e607cf055c06484a7ee18f24e91a28de8afcf9d9b5fed6ef44cf210283487153d86b118ce72af27073116f4016e17ffd528a19d09afe0f3ac53ec135f5ba2
7
- data.tar.gz: 5c3633aba46a77245abaaade884b9d83dc9ade01e836cdd8cd5c6c505091ff1a23e101e3777706ec2284d80346fffa3532c145646aed41b7a588231d325745da
6
+ metadata.gz: 44d9569edb47479fd4ba5a149a2a0ebec1277d9572f2b6754c42361fff134c0d6735935a1037f683a4575eda65777af9920a87719c8d4b30bd91096c0469f9dc
7
+ data.tar.gz: 1c7b4713f099a6212ec7db4385cdada55082331c9581f0f9c7c65e0ffd8960d676e2b6d2699ef8985f31b73b6a291e92f83c55900cb2fcbb45cc1d2ca411f5de
@@ -0,0 +1,21 @@
1
+ module CouchPillow
2
+
3
+ module TTLDirective
4
+
5
+ # Sets the TTL
6
+ #
7
+ def ttl value
8
+ @ttl = value
9
+ end
10
+
11
+
12
+ def ttl_value
13
+ has_ttl? ? @ttl.to_i : nil
14
+ end
15
+
16
+ def has_ttl?
17
+ @ttl ? true : false
18
+ end
19
+
20
+ end
21
+ end
@@ -8,6 +8,7 @@ module CouchPillow
8
8
  extend MultiDBDirective
9
9
  extend RenameDirective
10
10
  extend MigrateDirective
11
+ extend TTLDirective
11
12
 
12
13
  attr_accessor :id
13
14
 
@@ -39,7 +40,6 @@ module CouchPillow
39
40
  # @param hash The document
40
41
  # @param id The id of the document
41
42
  # @param cas CAS value of the document, from the CB client. Optional.
42
- # @param flags Flags of the document, from the CB client. Optional.
43
43
  #
44
44
  def initialize hash = {},
45
45
  id = SecureRandom.hex,
@@ -86,6 +86,7 @@ module CouchPillow
86
86
  _timestamp!
87
87
  validate!
88
88
  opts[:cas] = @cas
89
+ opts[:ttl] ||= self.class.ttl_value
89
90
  self.class._default_db.set(db_id, _to_save, opts)
90
91
  end
91
92
 
@@ -1,5 +1,5 @@
1
1
  module CouchPillow
2
2
  GEM_NAME = "couchpillow"
3
3
  NAME = "CouchPillow"
4
- VERSION = "0.4.9"
4
+ VERSION = "0.4.10"
5
5
  end
data/lib/couchpillow.rb CHANGED
@@ -23,6 +23,7 @@ require 'couchpillow/directives/attribute'
23
23
  require 'couchpillow/directives/multi_db'
24
24
  require 'couchpillow/directives/rename'
25
25
  require 'couchpillow/directives/migrate'
26
+ require 'couchpillow/directives/ttl'
26
27
 
27
28
  require 'couchpillow/errors'
28
29
  require 'couchpillow/boolean'
data/test/helper.rb CHANGED
@@ -10,6 +10,7 @@ class FakeCouchbaseServer
10
10
  def initialize
11
11
  @storage = {}
12
12
  @cas = {}
13
+ @ttl = {}
13
14
  end
14
15
 
15
16
 
@@ -17,12 +18,20 @@ class FakeCouchbaseServer
17
18
  raise Couchbase::Error::KeyExists if @storage.has_key?(id) && opts[:cas] && @cas[id] != opts[:cas]
18
19
  @storage[id] = data
19
20
  @cas[id] = SecureRandom.hex(8)
21
+ @ttl[id] = opts[:ttl] if opts[:ttl]
22
+ data
20
23
  end
21
24
 
22
25
 
23
26
  def delete id
24
27
  @storage.delete(id)
25
28
  @cas.delete(id)
29
+ @ttl.delete(id)
30
+ end
31
+
32
+
33
+ def ttl_value id
34
+ @ttl[id]
26
35
  end
27
36
 
28
37
 
@@ -82,7 +82,7 @@ class TestDocument < Minitest::Test
82
82
  assert_equal 'too', d.me
83
83
  assert_equal 'robin', d.batman
84
84
  assert_equal 123, d.apple
85
- assert d.save!
85
+ assert d.save!, d.inspect
86
86
  end
87
87
 
88
88
 
@@ -472,7 +472,7 @@ class TestDocument < Minitest::Test
472
472
  end
473
473
 
474
474
 
475
- def test_ttl_support
475
+ def test_ttl_support_from_opts
476
476
  d = Class.new(Document) do
477
477
  type 'test'
478
478
 
@@ -489,6 +489,26 @@ class TestDocument < Minitest::Test
489
489
  end
490
490
 
491
491
 
492
+ def test_ttl_directive
493
+ klass = Class.new(Document) do
494
+ type 'test'
495
+
496
+ ttl 10
497
+
498
+ attribute :foo do
499
+ type String
500
+ end
501
+ end
502
+
503
+ d = klass.new( foo: "bla" )
504
+ d.save!
505
+
506
+ assert_equal 10, CouchPillow.db.ttl_value("test::#{d.id}")
507
+ end
508
+
509
+
510
+
511
+
492
512
  def test_custom_db_connection
493
513
  conn1 = FakeCouchbaseServer.new
494
514
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchpillow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Tedja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-27 00:00:00.000000000 Z
11
+ date: 2015-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchbase
@@ -83,6 +83,7 @@ files:
83
83
  - lib/couchpillow/directives/migrate.rb
84
84
  - lib/couchpillow/directives/multi_db.rb
85
85
  - lib/couchpillow/directives/rename.rb
86
+ - lib/couchpillow/directives/ttl.rb
86
87
  - lib/couchpillow/directives/type.rb
87
88
  - lib/couchpillow/directives/type_prefix.rb
88
89
  - lib/couchpillow/document.rb
@@ -112,8 +113,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
113
  version: '0'
113
114
  requirements: []
114
115
  rubyforge_project:
115
- rubygems_version: 2.4.6
116
+ rubygems_version: 2.4.8
116
117
  signing_key:
117
118
  specification_version: 4
118
119
  summary: Document wrapper for Couchbase
119
120
  test_files: []
121
+ has_rdoc: