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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66ce129081c4c70157fc61c40f500d9460660900
|
4
|
+
data.tar.gz: 7be5df77cd9c672f71db5782440237702a7e1c8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f3e28aad6d21326a3497f995b242c055ec764c786d73571bbc72053ee84954277832a3f519e61b1667c0a323d1ed0f02a45eb6f1a343c3611f7cec6091cb624
|
7
|
+
data.tar.gz: 84f5e3b8ceb96051d8af95f0101b5620ac24b54736e4db36ccf8ad6ffe524c787140def2c242fd77d2f27fed8a2999a86803a94a6121ea7e8ea401ae956726cb
|
data/CHANGES.md
CHANGED
@@ -74,7 +74,9 @@ module CouchPotato
|
|
74
74
|
# class Book
|
75
75
|
# property :title
|
76
76
|
# property :year
|
77
|
-
# property :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].
|
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
|
data/lib/couch_potato/version.rb
CHANGED
@@ -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 "
|
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 "
|
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 "
|
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 "
|
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.
|
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-
|
11
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|