couch_potato 1.3.0 → 1.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f37912f0e7ed48878e92e5ad8ef34d106359f15
4
- data.tar.gz: 020faa774590847e21f942504cf9fb02df3683e7
3
+ metadata.gz: 66ce129081c4c70157fc61c40f500d9460660900
4
+ data.tar.gz: 7be5df77cd9c672f71db5782440237702a7e1c8c
5
5
  SHA512:
6
- metadata.gz: 6a6fce1ef1c76b01c073ac3706d894d5c567d05afe20ef4177672950f96db1011c9f6aee607852a7d0c605e303250ecec4ad0acbbc9494b30b603a25690924cd
7
- data.tar.gz: 240d66a1fcb88a3214c946fd51e924abf314410c8b14a203423626d6d777633ee0764ebffbfb2e62b707539c218da0b01da29068f717fe2057b69f1f6d9a2921
6
+ metadata.gz: 8f3e28aad6d21326a3497f995b242c055ec764c786d73571bbc72053ee84954277832a3f519e61b1667c0a323d1ed0f02a45eb6f1a343c3611f7cec6091cb624
7
+ data.tar.gz: 84f5e3b8ceb96051d8af95f0101b5620ac24b54736e4db36ccf8ad6ffe524c787140def2c242fd77d2f27fed8a2999a86803a94a6121ea7e8ea401ae956726cb
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Changes
2
2
 
3
+ ### 1.4.0
4
+
5
+ * Added support for passing the model to blocks for computing the default value of a property (Alexander Lang)
6
+
3
7
  ### 1.3.0
4
8
 
5
9
  * Add support for built-in couchdb reduce functions in map reduce specs (Andy Morris)
@@ -74,7 +74,9 @@ module CouchPotato
74
74
  # class Book
75
75
  # property :title
76
76
  # property :year
77
- # property :publisher, :type => Publisher
77
+ # property :publisher, type: Publisher
78
+ # property :published_at, default: -> { Date.current }
79
+ # property :next_year, default: ->(book) { book.year + 1 }
78
80
  # end
79
81
  def property(name, options = {})
80
82
  undefine_attribute_methods
@@ -62,7 +62,11 @@ module CouchPotato
62
62
  value = instance_variable_get("@#{name}")
63
63
  if value.nil? && !options[:default].nil?
64
64
  default = if options[:default].respond_to?(:call)
65
- options[:default].call
65
+ if options[:default].arity == 1
66
+ options[:default].call self
67
+ else
68
+ options[:default].call
69
+ end
66
70
  else
67
71
  clone_attribute(options[:default])
68
72
  end
@@ -1,3 +1,3 @@
1
1
  module CouchPotato
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -7,6 +7,7 @@ class Test
7
7
  property :complex, :default => [1, 2, 3]
8
8
  property :false_value, :default => false
9
9
  property :proc, :default => Proc.new { 1 + 2 }
10
+ property :proc_arity_one, :default => Proc.new {|test| test.test * 2 }
10
11
  end
11
12
 
12
13
  describe 'default properties' do
@@ -14,13 +15,13 @@ describe 'default properties' do
14
15
  recreate_db
15
16
  end
16
17
 
17
- it "should use the default value if nothing is supplied" do
18
+ it "uses the default value if nothing is supplied" do
18
19
  t = Test.new
19
20
 
20
21
  t.test.should == 'Test value'
21
22
  end
22
23
 
23
- it "should persist the default value if nothing is supplied" do
24
+ it "persists the default value if nothing is supplied" do
24
25
  t = Test.new
25
26
  CouchPotato.database.save_document! t
26
27
 
@@ -28,16 +29,16 @@ describe 'default properties' do
28
29
  t.test.should == 'Test value'
29
30
  end
30
31
 
31
- it "should not have the same default for two instances of the object" do
32
+ it "does not have the same default for two instances of the object" do
32
33
  t = Test.new
33
34
  t2 = Test.new
34
35
  t.complex.object_id.should_not == t2.complex.object_id
35
36
  end
36
-
37
- it "should not return the default value when the actual value is empty" do
37
+
38
+ it "does not return the default value when the actual value is empty" do
38
39
  t = Test.new(:complex => []).complex.should == []
39
40
  end
40
-
41
+
41
42
  it "uses the default value also if the default is false" do
42
43
  t = Test.new
43
44
  t.false_value.should == false
@@ -47,4 +48,10 @@ describe 'default properties' do
47
48
  t = Test.new
48
49
  t.proc.should == 3
49
50
  end
51
+
52
+ it 'passes the model to a block with arity 1' do
53
+ t = Test.new
54
+
55
+ expect(t.proc_arity_one).to eql('Test valueTest value')
56
+ end
50
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couch_potato
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Lang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json