dolly 0.8.1 → 0.9.0

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: ec31e28ba3ea993fcc77368790c27de2eb72ed47
4
- data.tar.gz: a0acd3b7ff6a58acc555ee5eb37788fd580aebb0
3
+ metadata.gz: c0ed634c57601285c5f226c689864684e556edbe
4
+ data.tar.gz: 343cf2e87366a95ca10a22cd76a7e9b014fe8eeb
5
5
  SHA512:
6
- metadata.gz: 9b9aec49a44695f4e080e8ec88c1631c11f34d767b6f91daa9fda0b9049c8298c350b24d59f2b6edb80a570154da37bbec5d1308f05f92ca161c14d3e04f8668
7
- data.tar.gz: c30dd5b88024142efdc7b4faaab1815d5083a858e5e2cfb84913f8cae98c18646511f74a0a6a0aac6126862755349b4bc8a592fe35c560e7313449f43c3cc9ab
6
+ metadata.gz: 46eb110e75de2a3511cd5682bc5f8a4caddf11c4c8b41c2af20dd09b29e5413c9380385981c4b957655ac163f24b7a17beb6b43dac012695eaf6d1b2a2794275
7
+ data.tar.gz: 4cab1eb32ab93835832897fda1ed3a300063df79e1e6f6895024355939843608ba1c3a3168635d63d4a339cc39f4f06eb05322a673e91f03babee3146f180bbb
@@ -137,14 +137,18 @@ module Dolly
137
137
 
138
138
  def init_properties options = {}
139
139
  raise Dolly::ResourceNotFound if options['error'] == 'not_found'
140
- #TODO: right now not listed properties will be ignored
141
140
  options.each do |k, v|
142
141
  next unless respond_to? :"#{k}="
143
142
  send(:"#{k}=", v)
144
143
  end
144
+ initialize_default_properties options if self.properties.present?
145
145
  init_doc options
146
146
  end
147
147
 
148
+ def initialize_default_properties options
149
+ _properties.reject { |property| options.keys.include? property.name }.each { |property| self.doc[property.name] ||= property.default }
150
+ end
151
+
148
152
  def init_doc options
149
153
  self.doc ||= {}
150
154
  #TODO: define what will be the preference _id or id
@@ -2,7 +2,7 @@ module Dolly
2
2
  class Property
3
3
  attr_writer :value
4
4
  attr_accessor :name
5
- attr_reader :class_name
5
+ attr_reader :class_name, :default
6
6
 
7
7
  def initialize opts = {}
8
8
  @class_name = opts.delete(:class_name) if opts.present?
data/lib/dolly/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dolly
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -22,6 +22,10 @@ class FooBaz < Dolly::Document
22
22
  end
23
23
  end
24
24
 
25
+ class TestFoo < Dolly::Document
26
+ property :default_test_property, class_name: String, default: 'FOO'
27
+ end
28
+
25
29
  class DocumentTest < ActiveSupport::TestCase
26
30
  DB_BASE_PATH = "http://localhost:5984/test".freeze
27
31
 
@@ -334,6 +338,16 @@ class DocumentTest < ActiveSupport::TestCase
334
338
  assert_equal foobaz.foo, {'foo' => 'bar', 'bar' => 'bar'}
335
339
  end
336
340
 
341
+ test 'default should populate before save' do
342
+ test_foo = TestFoo.new
343
+ assert_equal 'FOO', test_foo.doc['default_test_property']
344
+ end
345
+
346
+ test 'default should be overridden by params' do
347
+ test_foo = TestFoo.new(default_test_property: 'bar')
348
+ assert_equal 'bar', test_foo.doc['default_test_property']
349
+ end
350
+
337
351
  private
338
352
  def generic_response rows, count = 1
339
353
  {total_rows: count, offset:0, rows: rows}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dolly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - javierg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-09 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties