active_record-default_values 1.0.0 → 1.0.1

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: 5fb1fa5af4341b4537a7532d9aee821b8ab6d26c
4
- data.tar.gz: aacfa86c145f875c4b021239f0093d22dc7d01cc
3
+ metadata.gz: 2ca922faefc937af54e3560c52fb03b3f4393c02
4
+ data.tar.gz: 88d8656de39c33a46a672aa2fd959a8adb3a3f44
5
5
  SHA512:
6
- metadata.gz: 0a663a91c8fb613e9155b853b59db717699e0cf16110ca1f980b31d83ddad1b9fc58847a51eea1a52987855d12f6fc519fe3a6f519126f5082a9b4691da88e6a
7
- data.tar.gz: af36aad1ab04076a8e1519b7212c0f67f39ef50b1b048a5cc2dab54778b959aabf8b7d3bf417f30de8f121d5e7677e75262ae3e37af6b936eded8ef1c9ad70d5
6
+ metadata.gz: 7cf4ff9300351b771a5ea19118b4650be518a77225a44dd6d3ac15b8c877113b6b06144e6aeb479b59d52ab6ab6f1267a7e06b239a664addcf5b1f468bc2b60d
7
+ data.tar.gz: 97302ee6c20ad98757e44d070e5fbcb5e6d81dae72d9352b9c7fcc538cd8f2562ecf42f10c9a0a0828598b76444788874967b63f17fad139db285c176b0192ff
data/README.md CHANGED
@@ -27,11 +27,12 @@ class User < ActiveRecord::Base
27
27
  default_value :active, false
28
28
  default_value :add_time, -> { Time.now }
29
29
  default_value :age, 20
30
+ default_value :description, 'Test', if: :blank?
30
31
  end
31
32
 
32
- User.new(first_name: 'Samwise')
33
+ User.new(first_name: 'Samwise', description: '')
33
34
 
34
- => #<User id: nil, first_name: "Samwise", last_name: "Doe", add_time: "2015-05-27 15:35:32", active: false, age: 20>
35
+ => #<User id: nil, first_name: "Samwise", last_name: "Doe", add_time: "2015-05-27 15:35:32", active: false, age: 20, description: "Test">
35
36
  ```
36
37
 
37
38
  ## Contributing
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module DefaultValues
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
@@ -6,10 +6,10 @@ module ActiveRecord
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  class_methods do
9
- def default_value(attr_name, default_value)
9
+ def default_value(attr_name, default_value, **options)
10
10
  after_initialize do
11
11
  value = default_value.respond_to?(:call) ? default_value.call : default_value
12
- send("#{attr_name}=", value) if send(attr_name).nil? && new_record?
12
+ send("#{attr_name}=", value) if send(attr_name).send(options[:if] || :nil?) && new_record?
13
13
  end
14
14
  end
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-default_values
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Baćkowski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2015-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord