attribute-defaults 0.8.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/attribute_defaults.rb +11 -14
  3. metadata +24 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 829a2fbfba5c83c3fc55fec964f36217b8b097c9
4
- data.tar.gz: 77d1a01e2bf364b3dc1ece8c0a896217a051feed
2
+ SHA256:
3
+ metadata.gz: 20a2020ddfe66b9563bd16a17c32e3d1f4290b8637bd0744d39ce5406b0dc857
4
+ data.tar.gz: 85cf4e3fe793ad48589da5c1ab757b216fac6d21c9e715db35366c4db8dbbc69
5
5
  SHA512:
6
- metadata.gz: 210c073e8e58439cca6cee8ce424235326dd513fca5c2b3968f02a84f6256119ab1fd45c238df79caac313ac9433564884ecdb0a322c8df96e01fbedb872694c
7
- data.tar.gz: e6ac571755c218c86ce5289e030d2d366035d9818071f928b52ee4b216efd5e02347c7cd10ef3767ae165d0a8d67c88b5b94753b76f80bf3b183c873897ca4b6
6
+ metadata.gz: 29fc1d06259c94fbf6aacb78cf35b97ea84eea9751a2bcb89c44b0e402c9c8824398b48f4f28d6c41cc4d0f11e3d44676f2e0d6a7d34dbeec20d3a8ceb529aef
7
+ data.tar.gz: 855b3e9f378d0d9c6fb0bb4e61f4783c80b4d66acc3e7766b3e665713bc1cbba69c64d5652643dc6068e3f4a4e1983a9884546b2d22f2ecff6906e94378060d9
@@ -6,7 +6,6 @@ module ActiveRecord
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  module ClassMethods
9
-
10
9
  # Set defaults. Examples:
11
10
  # attr_default :age, 12
12
11
  # attr_default :description, '(none)'
@@ -29,32 +28,30 @@ module ActiveRecord
29
28
  define_method(evaluator, &block)
30
29
 
31
30
  module_eval(<<-EVAL, __FILE__, __LINE__ + 1)
32
- def #{setter}
33
- #{'return if persisted?' if options[:persisted] == false}
34
- return unless self.#{sym}.send(:#{options[:if] || 'nil?'})
35
- value = #{evaluator}#{'(self)' unless block.arity.zero?}
36
- self.#{sym} = value.duplicable? ? value.dup : value
37
- rescue ActiveModel::MissingAttributeError
38
- end
31
+ def #{setter} # def __set_attr_default_for_age
32
+ #{'return if persisted?' if options[:persisted] == false} # return if persisted?
33
+ return unless #{sym}.send(:#{options[:if] || 'nil?'}) # return unless age.nil?
34
+ value = #{evaluator}#{'(self)' unless block.arity.zero?} # value = __eval_attr_default_for_age(self)
35
+ self.#{sym} = value.duplicable? ? value.dup : value # self.age = value.duplicable? ? value.dup : value
36
+ rescue ActiveModel::MissingAttributeError # rescue ActiveModel::MissingAttributeError
37
+ end # end
39
38
  EVAL
40
39
  private evaluator, setter
41
40
  end
42
41
 
43
42
  # Default mass-assignment. Examples:
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 }
43
+ # attr_defaults description: '(none)', age: 12
44
+ # attr_defaults description: '(none)', age: ->r { Time.zone.year - r.dob.year }
45
+ # attr_defaults description: '(none)', age: { default: 12, persisted: false }
47
46
  def attr_defaults(pairs)
48
47
  pairs.each do |pair|
49
- attr_default *pair
48
+ attr_default(*pair)
50
49
  end
51
50
  end
52
-
53
51
  end
54
52
  end
55
53
 
56
54
  class Base
57
55
  include AttributesWithDefaults
58
56
  end
59
-
60
57
  end
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.8.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-08 00:00:00.000000000 Z
11
+ date: 2022-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 5.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 6.0.0
22
+ version: 8.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 5.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 6.0.0
32
+ version: 8.0.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +45,7 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: sqlite3
48
+ name: rspec
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
@@ -59,7 +59,21 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
- name: rspec
62
+ name: rubocop-bsm
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: sqlite3
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
79
  - - ">="
@@ -84,7 +98,8 @@ files:
84
98
  - lib/attribute_defaults.rb
85
99
  homepage: https://github.com/bsm/attribute-defaults
86
100
  licenses: []
87
- metadata: {}
101
+ metadata:
102
+ rubygems_mfa_required: 'true'
88
103
  post_install_message:
89
104
  rdoc_options: []
90
105
  require_paths:
@@ -93,15 +108,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
108
  requirements:
94
109
  - - ">="
95
110
  - !ruby/object:Gem::Version
96
- version: 2.2.0
111
+ version: '2.7'
97
112
  required_rubygems_version: !ruby/object:Gem::Requirement
98
113
  requirements:
99
114
  - - ">="
100
115
  - !ruby/object:Gem::Version
101
116
  version: '0'
102
117
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 2.6.8
118
+ rubygems_version: 3.3.7
105
119
  signing_key:
106
120
  specification_version: 4
107
121
  summary: Specify default values for ActiveRecord attributes