attribute-defaults 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/attribute_defaults.rb +7 -7
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 829a2fbfba5c83c3fc55fec964f36217b8b097c9
|
4
|
+
data.tar.gz: 77d1a01e2bf364b3dc1ece8c0a896217a051feed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 210c073e8e58439cca6cee8ce424235326dd513fca5c2b3968f02a84f6256119ab1fd45c238df79caac313ac9433564884ecdb0a322c8df96e01fbedb872694c
|
7
|
+
data.tar.gz: e6ac571755c218c86ce5289e030d2d366035d9818071f928b52ee4b216efd5e02347c7cd10ef3767ae165d0a8d67c88b5b94753b76f80bf3b183c873897ca4b6
|
data/lib/attribute_defaults.rb
CHANGED
@@ -13,9 +13,9 @@ module ActiveRecord
|
|
13
13
|
# attr_default :age do |record|
|
14
14
|
# Time.zone.year - record.dob.year
|
15
15
|
# end
|
16
|
-
# attr_default :description, '(none)', :
|
17
|
-
# attr_default :description, '(none)', :
|
18
|
-
# attr_default :description, :
|
16
|
+
# attr_default :description, '(none)', if: :blank
|
17
|
+
# attr_default :description, '(none)', persisted: false
|
18
|
+
# attr_default :description, default: '(none)', persisted: false
|
19
19
|
def attr_default(sym, *args, &block)
|
20
20
|
options = args.extract_options!
|
21
21
|
default = options.delete(:default) || args.shift
|
@@ -23,7 +23,7 @@ module ActiveRecord
|
|
23
23
|
|
24
24
|
evaluator = "__eval_attr_default_for_#{sym}".to_sym
|
25
25
|
setter = "__set_attr_default_for_#{sym}".to_sym
|
26
|
-
block ||= default.is_a?(Proc) ? default :
|
26
|
+
block ||= default.is_a?(Proc) ? default : -> { default }
|
27
27
|
|
28
28
|
after_initialize setter.to_sym
|
29
29
|
define_method(evaluator, &block)
|
@@ -41,9 +41,9 @@ module ActiveRecord
|
|
41
41
|
end
|
42
42
|
|
43
43
|
# Default mass-assignment. Examples:
|
44
|
-
# attr_defaults :
|
45
|
-
# attr_defaults :
|
46
|
-
# attr_defaults :
|
44
|
+
# attr_defaults description: '(none)', age: 12
|
45
|
+
# attr_defaults description: '(none)', age: ->r { Time.zone.year - r.dob.year }
|
46
|
+
# attr_defaults description: '(none)', age: { default: 12, persisted: false }
|
47
47
|
def attr_defaults(pairs)
|
48
48
|
pairs.each do |pair|
|
49
49
|
attr_default *pair
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attribute-defaults
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 6.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 5.0.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 6.0.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,15 +93,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.
|
96
|
+
version: 2.2.0
|
97
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
99
|
- - ">="
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
101
|
+
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.6.8
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Specify default values for ActiveRecord attributes
|