couch_potato 0.2.26 → 0.2.27
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.
- data/CHANGES.md +7 -1
- data/VERSION.yml +3 -3
- data/lib/couch_potato/persistence/type_caster.rb +2 -0
- data/lib/couch_potato.rb +21 -19
- data/spec/unit/attributes_spec.rb +46 -7
- metadata +2 -2
data/CHANGES.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
## Changes
|
2
2
|
|
3
|
-
###
|
3
|
+
### 0.2.27
|
4
|
+
* workaround for Rails apps using bundler: database name was not initialized from couchdb.yml (langalex)
|
5
|
+
|
6
|
+
### 0.2.26
|
4
7
|
* added to_s(:json) to Date and Time to be able to get properly formatted dates/times for searching with dates/times (langalex)
|
8
|
+
* all times are now stored as UTC (langalex)
|
9
|
+
* added support for Float attributes (arbovm)
|
10
|
+
|
5
11
|
|
6
12
|
### 0.2.25
|
7
13
|
* automatic view updates: when you change the definition of a view couch potato will now update the design document in the database (langalex)
|
data/VERSION.yml
CHANGED
@@ -25,6 +25,8 @@ module CouchPotato
|
|
25
25
|
if type && !value.instance_of?(type)
|
26
26
|
if type == Fixnum
|
27
27
|
value.to_s.scan(/\d/).join.to_i unless value.blank?
|
28
|
+
elsif type == Float
|
29
|
+
value.to_s.scan(/\d+\.?\d*/).join.to_f unless value.blank?
|
28
30
|
else
|
29
31
|
type.json_create value unless value.blank?
|
30
32
|
end
|
data/lib/couch_potato.rb
CHANGED
@@ -7,28 +7,30 @@ require 'ostruct'
|
|
7
7
|
|
8
8
|
JSON.create_id = 'ruby_class'
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
unless defined?(CouchPotato)
|
11
|
+
module CouchPotato
|
12
|
+
Config = Struct.new(:database_name, :validation_framework).new
|
13
|
+
Config.validation_framework = :validatable # default to the validatable gem for validations
|
14
|
+
|
15
|
+
# Returns a database instance which you can then use to create objects and query views. You have to set the CouchPotato::Config.database_name before this works.
|
16
|
+
def self.database
|
17
|
+
@@__database ||= Database.new(self.couchrest_database)
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
# Returns the underlying CouchRest database object if you want low level access to your CouchDB. You have to set the CouchPotato::Config.database_name before this works.
|
21
|
+
def self.couchrest_database
|
22
|
+
@@__couchrest_database ||= CouchRest.database(full_url_to_database)
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
+
private
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
def self.full_url_to_database
|
28
|
+
raise('No Database configured. Set CouchPotato::Config.database_name') unless CouchPotato::Config.database_name
|
29
|
+
if CouchPotato::Config.database_name.match(%r{https?://})
|
30
|
+
CouchPotato::Config.database_name
|
31
|
+
else
|
32
|
+
"http://127.0.0.1:5984/#{CouchPotato::Config.database_name}"
|
33
|
+
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -4,6 +4,7 @@ class Plant
|
|
4
4
|
include CouchPotato::Persistence
|
5
5
|
property :leaf_count
|
6
6
|
property :typed_leaf_count, :type => Fixnum
|
7
|
+
property :typed_leaf_size, :type => Float
|
7
8
|
end
|
8
9
|
|
9
10
|
describe "attributes" do
|
@@ -19,7 +20,7 @@ describe "attributes" do
|
|
19
20
|
describe "attributes" do
|
20
21
|
it "should return the attributes" do
|
21
22
|
plant = Plant.new(:leaf_count => 1)
|
22
|
-
plant.attributes.should == {:leaf_count => 1, :created_at => nil, :updated_at => nil, :typed_leaf_count => nil}
|
23
|
+
plant.attributes.should == {:leaf_count => 1, :created_at => nil, :updated_at => nil, :typed_leaf_count => nil, :typed_leaf_size => nil}
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
@@ -46,12 +47,13 @@ describe "attributes" do
|
|
46
47
|
end
|
47
48
|
|
48
49
|
describe 'typed attributes' do
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
|
51
|
+
before(:each) do
|
52
|
+
@plant = Plant.new
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "fixnum" do
|
56
|
+
it "should convert a string into a fixnum" do
|
55
57
|
@plant.typed_leaf_count = '4'
|
56
58
|
@plant.typed_leaf_count.should == 4
|
57
59
|
end
|
@@ -81,6 +83,43 @@ describe "attributes" do
|
|
81
83
|
@plant.typed_leaf_count.should be_nil
|
82
84
|
end
|
83
85
|
end
|
86
|
+
|
87
|
+
describe "float" do
|
88
|
+
it "should convert a number in a string with a decimal place" do
|
89
|
+
@plant.typed_leaf_size = '0.5001'
|
90
|
+
@plant.typed_leaf_size.should == 0.5001
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should convert a number in a string without a decimal place" do
|
94
|
+
@plant.typed_leaf_size = '5'
|
95
|
+
@plant.typed_leaf_size.should == 5.0
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should leave a float as it is" do
|
99
|
+
@plant.typed_leaf_size = 0.5
|
100
|
+
@plant.typed_leaf_size.should == 0.5
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should leave nil as is" do
|
104
|
+
@plant.typed_leaf_size = nil
|
105
|
+
@plant.typed_leaf_size.should be_nil
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should set the attributes to zero if a string given" do
|
109
|
+
@plant.typed_leaf_size = 'x'
|
110
|
+
@plant.typed_leaf_size.should == 0
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should parse numbers out of a string" do
|
114
|
+
@plant.typed_leaf_size = 'x00.123'
|
115
|
+
@plant.typed_leaf_size.should == 0.123
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should set the attributes to nil if given a blank string" do
|
119
|
+
@plant.typed_leaf_size = ''
|
120
|
+
@plant.typed_leaf_size.should be_nil
|
121
|
+
end
|
122
|
+
end
|
84
123
|
end
|
85
124
|
end
|
86
125
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couch_potato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-05 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|