active_redis_orm 0.0.5 → 0.0.6

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: 76ee3727d5395eeabf2d760c12804c8f1e44599f
4
- data.tar.gz: 1a306062eb3d4efdc56f1f7cfe3d35e76d2ec728
3
+ metadata.gz: 1e1021d6d4648f60ea3e3a7fe147b34c3e6bcf55
4
+ data.tar.gz: 24eda56cdfd8fac30bb28da108c3afe8dbc2f763
5
5
  SHA512:
6
- metadata.gz: 2886bd6a3a46e1ec1990ae972e30f7aee3ddbdfa660dacbd6a9214c4449a317e1680d3bba32ab1217936c9229c12a9f885801eb860d991ec7ac9318aaf9a91e7
7
- data.tar.gz: 112cfe96ba02cea3a7e6256b535630ccf49b1741d394af0912acd5a05dec4c1237d9c854f66aa4a09c90518e80f0e44e853a54df52292ec7dde2d421f7f636e8
6
+ metadata.gz: a232580244b896dbf48b713d6d3e4710c188ce1bc622b8f116ea8ae3a6ccbec4637234e2af65eb4d1452bb6a6c7f39a0049f282276906eb3750e0521a6aa6f0a
7
+ data.tar.gz: 9385c39fb427b4f1bc5b4a416ecfa98c461df4f099aaaef428c7dae2b642dfd97206ff952f34383c75bc72ba928355b6c86e7b8934ea634ef68040f30a6269d0
@@ -81,6 +81,10 @@ module ActiveRedis
81
81
  else
82
82
  string_field(field_name, options)
83
83
  end
84
+
85
+ if options[:default]
86
+ set_default(field_name, options[:default])
87
+ end
84
88
  end
85
89
 
86
90
  def string_field(field_name, options)
@@ -391,11 +395,18 @@ module ActiveRedis
391
395
  if value.blank?
392
396
  nil
393
397
  else
394
- Date.parse(value)
398
+ Date.parse(value) rescue nil
395
399
  end
396
400
  end
397
401
  end
398
402
 
403
+ def #{field_name}=(value)
404
+ value = ActiveRedis::NilObject.new if (Date.parse(value.to_s) rescue nil).blank?
405
+ #{field_name}_will_change!
406
+ value = ActiveRedis::NilObject.new if value.nil?
407
+ @attributes[:#{field_name}] = value
408
+ end
409
+
399
410
  def set_#{field_name}(value)
400
411
  #{field_name}_object.value = value.last.to_s
401
412
  after_set(:#{field_name})
@@ -443,5 +454,18 @@ module ActiveRedis
443
454
  end
444
455
  }
445
456
  end
457
+
458
+ def set_default(field_name, default)
459
+ before_create do
460
+ if send(field_name).blank?
461
+ if default.is_a?(Proc)
462
+ value = default.call(self)
463
+ else
464
+ value = default
465
+ end
466
+ send("#{field_name}=", value)
467
+ end
468
+ end
469
+ end
446
470
  end
447
471
  end
@@ -3,5 +3,9 @@ module ActiveRedis
3
3
  def nil?
4
4
  true
5
5
  end
6
+
7
+ def present?
8
+ false
9
+ end
6
10
  end
7
11
  end
@@ -44,9 +44,9 @@ module ActiveRedis
44
44
  end
45
45
 
46
46
  def perform_create
47
+ #TODO: check if no object exists under that id
48
+ @id ||= SecureRandom.uuid().delete('-')
47
49
  run_callbacks :create do
48
- #TODO: check if no object exists under that id
49
- @id ||= SecureRandom.uuid().delete('-')
50
50
  perform_save
51
51
  end
52
52
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRedis
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -3,10 +3,19 @@ require "active_redis_orm"
3
3
  describe ActiveRedis do
4
4
  class AttributesObject < ActiveRedis::Base
5
5
  attr_accessible :foo, :bar, :list
6
+ field :foo, default: lambda{|item| item.id}
7
+ field :bar, default: "barbar"
8
+ field :list
6
9
  end
7
10
 
8
11
  it "deals with attributes in string or symbol implementation" do
9
12
  AttributesObject.should be_attr_accessible("bar")
10
13
  AttributesObject.should be_attr_accessible(:bar)
11
14
  end
15
+
16
+ it "sets the defaults" do
17
+ item = AttributesObject.create(list: "123")
18
+ item.foo.should == item.id
19
+ item.bar.should == "barbar"
20
+ end
12
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_redis_orm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Caspy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-23 00:00:00.000000000 Z
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler