default_value_for 3.6.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -21
  3. data/Rakefile +0 -9
  4. data/default_value_for.gemspec +6 -5
  5. data/test.rb +20 -0
  6. metadata +29 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdfb798901eea229f953dfb541d5efe0b2decb31863326fc0c0a489e2f76f2c5
4
- data.tar.gz: 96d72a6a620685ba5c5bb2212f955bb0e33b44198f7657c8d24665411329a16d
3
+ metadata.gz: 0e4ad2e33ddca870f51f8a1c4aef12281b2cc0fe679834eaebb33f6691434431
4
+ data.tar.gz: 862a55e06fbca022177db11193eca2572174891375510010a7e6e074a870e9e6
5
5
  SHA512:
6
- metadata.gz: 3ac180c638bbaabbfa7d95a98ece04682c99abd8c602a84a5471d9403e8f8bbdf34f6aba3e31da03946913340036be35389ae7ce4cdd84f73ab6ef05c53ea4c0
7
- data.tar.gz: 289f0da4d133b294840521a3378e716d2b5d2efd8a41e99b7f113a6134b7c6d73fc718f9859d1059fcd1b585d654f0c7307b6f1b2be9aced03651c21b9abe118
6
+ metadata.gz: d24e7cded2995ee32877835bc8ff4eb8eccad4ee68447d5c66c869932d61fe6ef50807b88a14e64f93f8dcd9d4cb6b85fd1730f490e2266c9ffc16ca0a57054c
7
+ data.tar.gz: '050180f430ef62cdf88390ebe32adad62b862dbc6f7000c82ae73a286a571f6159035c258f1488864fe5f9507524c33124dd4aa633ae55210194eca0abc866f6'
data/README.md CHANGED
@@ -20,21 +20,35 @@ u.last_seen # => Mon Sep 22 17:28:38 +0200 2008
20
20
 
21
21
  ## Installation
22
22
 
23
- ### Rails 3.2 - 4.2 / Ruby 1.9.3 and higher
23
+ ### On Rails 6.1+ / Ruby 3.0+
24
24
 
25
- The current version of default_value_for (3.x+) is compatible with Rails 3.2 or higher, and Ruby 1.9.3 and higher.
25
+ The objective is to support all supported rubies and rails versions. If you need to support end of life versions, please see the sections below and use a prior release.
26
26
 
27
27
  Add it to your Gemfile:
28
28
 
29
29
  ```ruby
30
- gem "default_value_for", "~> 3.0"
30
+ gem "default_value_for", "~> 4.0"
31
31
  ```
32
32
 
33
- This gem is signed using PGP with the Phusion Software Signing key: http://www.phusion.nl/about/gpg. That key in turn is signed by the rubygems-openpgp Certificate Authority: http://www.rubygems-openpgp-ca.org/.
33
+ Version 4.0.0 supports rails 6.1+ and ruby 3.0+. It adds support for rails 7.2. It drops support for rubies less than 3.0 and rails less than 6.1. This is the reason for the major version bump as it drops support for many combinations of older ruby and rails versions.
34
+
35
+ ### On Rails 3.2 - 6.0 / Ruby 1.9.3 - 2.7
36
+
37
+ To use default_value_for with older versions of Ruby and Rails, you must use the previous stable release, 3.6.0 or others in the 3.x.y release. This version works with Rails 3.0, 3.1, and 3.2; and Ruby 1.8.7 and higher. It **does not** work with Rails 4.
38
+
39
+ default_value_for (3.x+) is compatible with Rails 3.2-6.1, and Ruby 1.9.3 and higher.
40
+
41
+ Note:
42
+ * Version 3.5.0: Added basic rails 7.0 support
43
+ * Version 3.6.0: Added basic rails 7.1 support
34
44
 
35
- You can verify the authenticity of the gem by following The Complete Guide to Verifying Gems with rubygems-openpgp: http://www.rubygems-openpgp-ca.org/blog/the-complete-guide-to-verifying-gems-with-rubygems-openpgp.html
45
+ Add it to your Gemfile:
46
+
47
+ ```ruby
48
+ gem "default_value_for", "~> 3.0"
49
+ ```
36
50
 
37
- ## Rails 3.0 - 3.1 / Ruby 1.9.3 and lower
51
+ ## On Rails 3.0 - 3.1 / Ruby 1.9.3 and lower
38
52
 
39
53
  To use default_value_for with older versions of Ruby and Rails, you must use the previous stable release, 2.0.3. This version works with Rails 3.0, 3.1, and 3.2; and Ruby 1.8.7 and higher. It **does not** work with Rails 4.
40
54
 
@@ -42,7 +56,7 @@ To use default_value_for with older versions of Ruby and Rails, you must use the
42
56
  gem "default_value_for", "~> 2.0.3"
43
57
  ```
44
58
 
45
- ### Rails 2
59
+ ### On Rails 2
46
60
 
47
61
  To use default_value_for with Rails 2.x you must use an older version:
48
62
 
@@ -346,25 +360,30 @@ class User < ActiveRecord::Base
346
360
  end
347
361
  ```
348
362
 
349
- We recommend you to alias chain your initialize method in models where you use `default_value_for`:
363
+ We recommend you to use Module#prepend in models where you use `default_value_for`:
350
364
 
351
365
  ```ruby
352
- class User < ActiveRecord::Base
353
- default_value_for :age, 20
354
-
355
- def initialize_with_my_app
356
- initialize_without_my_app(:name => 'Name cannot be changed in constructor')
366
+ module UserCustomInitialize
367
+ def initialize
368
+ # Do your pre-initialize work
369
+ super
370
+ # Do any post-initialize work
357
371
  end
372
+ end
373
+ ```
358
374
 
359
- alias_method_chain :initialize, :my_app
375
+ ```ruby
376
+ class User < ActiveRecord::Base
377
+ default_value_for :age, 20
378
+ prepend UserCustomInitialize
360
379
  end
361
380
  ```
362
381
 
363
- Also, stick with the following rules:
382
+ Also, take the following precautions:
364
383
 
365
- * There is no need to +alias_method_chain+ your initialize method in models that don't use `default_value_for`.
384
+ * Make sure you always call super in your prepended method.
366
385
 
367
- * Make sure that +alias_method_chain+ is called *after* the last `default_value_for` occurrence.
386
+ * It's generally safer to call super first and do your customizations afterwards to ensure everything is setup first.
368
387
 
369
388
  If your default value is accidentally similar to default_value_for's options hash wrap your default value like this:
370
389
 
@@ -537,13 +556,21 @@ That's an awful lot of code. Using `default_value_for` is easier, don't you thin
537
556
 
538
557
  ### What about other plugins?
539
558
 
540
- I've only been able to find 2 similar plugins:
559
+ There are other ways to accomplish similar results as `default_value_for`.
560
+
561
+ From Rails:
562
+ * [attribute default](https://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html#method-i-attribute)
563
+ * [schema migration column defaults](https://edgeguides.rubyonrails.org/active_record_migrations.html)
541
564
 
542
- * Default Value: http://agilewebdevelopment.com/plugins/default_value
565
+ Other plugins:
566
+ * [Defaults](https://github.com/fnando/defaults)
567
+ * [attribute-defaults](https://github.com/bsm/attribute-defaults)
568
+ * [has_defaults](https://github.com/makandra/has_defaults)
543
569
 
544
- * ActiveRecord Defaults: http://agilewebdevelopment.com/plugins/activerecord_defaults
570
+ Each of these has limitations and should be evaluated based on your use cases. Two areas where `default_value_for` excels is deriving
571
+ defaults based on the current object or determining the behavior for `nil` values.
545
572
 
546
- 'Default Value' appears to be unmaintained; its SVN link is broken. This leaves only 'ActiveRecord Defaults'. However, it is semantically dubious, which leaves it wide open for corner cases. For example, it is not clearly specified what ActiveRecord Defaults will do when attributes are protected by +attr_protected+ or +attr_accessible+. It is also not clearly specified what one is supposed to do if one needs a custom +initialize+ method in the model.
573
+ If there are other options or uses cases where you've found this gem or another one is useful, please open a pull request to update this page.
547
574
 
548
575
  I've taken my time to thoroughly document default_value_for's behavior.
549
576
 
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  task :default => :test
2
2
 
3
- require 'bundler'
4
3
  require "bundler/gem_tasks"
5
4
 
6
5
  desc "Run unit tests."
@@ -9,14 +8,6 @@ task :test do
9
8
  end
10
9
 
11
10
  rails_versions = %w(
12
- 3.2
13
- 4.0
14
- 4.1
15
- 4.2
16
- 5.0
17
- 5.1
18
- 5.2
19
- 6.0
20
11
  6.1
21
12
  7.0
22
13
  7.1
@@ -1,23 +1,24 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{default_value_for}
3
- s.version = "3.6.0"
3
+ s.version = "4.0.0"
4
4
  s.summary = %q{Provides a way to specify default values for ActiveRecord models}
5
5
  s.description = %q{The default_value_for plugin allows one to define default values for ActiveRecord models in a declarative manner}
6
6
  s.email = %q{software-signing@phusion.nl}
7
7
  s.homepage = %q{https://github.com/FooBarWidget/default_value_for}
8
8
  s.authors = ["Hongli Lai"]
9
9
  s.license = 'MIT'
10
- s.required_ruby_version = '>= 1.9.3'
10
+ s.required_ruby_version = '>= 3.0.0'
11
11
  s.files = ['default_value_for.gemspec',
12
12
  'LICENSE.TXT', 'Rakefile', 'README.md', 'test.rb',
13
13
  'init.rb',
14
14
  'lib/default_value_for.rb',
15
15
  'lib/default_value_for/railtie.rb'
16
16
  ]
17
- s.add_dependency 'activerecord', '>= 3.2.0', '< 7.2'
18
- s.add_development_dependency 'actionpack', '>= 3.2.0', '< 7.2'
19
- s.add_development_dependency 'railties', '>= 3.2.0', '< 7.2'
17
+ s.add_dependency 'activerecord', '>= 6.1', '< 7.3'
18
+ s.add_development_dependency 'actionpack', '>= 6.1', '< 7.3'
19
+ s.add_development_dependency 'railties', '>= 6.1', '< 7.3'
20
20
  s.add_development_dependency 'minitest', '>= 5.0'
21
21
  s.add_development_dependency 'minitest-around'
22
22
  s.add_development_dependency 'appraisal'
23
+ s.add_development_dependency 'bundler'
23
24
  end
data/test.rb CHANGED
@@ -62,6 +62,7 @@ end
62
62
 
63
63
  require 'default_value_for'
64
64
 
65
+ puts "\nTesting with ruby version #{RUBY_VERSION}"
65
66
  puts "\nTesting with Active Record version #{ActiveRecord::VERSION::STRING}"
66
67
  puts "\nTesting with Action Pack version #{ActionPack::VERSION::STRING}\n\n"
67
68
 
@@ -291,6 +292,25 @@ class DefaultValuePluginTest < Minitest::Test
291
292
  assert object.instance_variable_get('@initialized')
292
293
  end
293
294
 
295
+ def test_doesnt_conflict_with_prependeed_initialize_method_in_model_class
296
+ m = Object.const_set("BookOverride", Module.new)
297
+ m.define_method(:initialize) do |*args|
298
+ @initialized = true
299
+ super(:count => 5678)
300
+ end
301
+
302
+ Book.class_eval do
303
+ prepend BookOverride
304
+
305
+ default_value_for :number, 1234
306
+ end
307
+
308
+ object = Book.new
309
+ assert_equal 1234, object.number
310
+ assert_equal 5678, object.count
311
+ assert object.instance_variable_get('@initialized')
312
+ end
313
+
294
314
  def test_model_instance_is_passed_to_the_given_block
295
315
  instance = nil
296
316
  Book.default_value_for :number do |n|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: default_value_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hongli Lai
@@ -16,60 +16,60 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.0
19
+ version: '6.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.2'
22
+ version: '7.3'
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: 3.2.0
29
+ version: '6.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.2'
32
+ version: '7.3'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: actionpack
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 3.2.0
39
+ version: '6.1'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '7.2'
42
+ version: '7.3'
43
43
  type: :development
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 3.2.0
49
+ version: '6.1'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '7.2'
52
+ version: '7.3'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: railties
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 3.2.0
59
+ version: '6.1'
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
- version: '7.2'
62
+ version: '7.3'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 3.2.0
69
+ version: '6.1'
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
- version: '7.2'
72
+ version: '7.3'
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: minitest
75
75
  requirement: !ruby/object:Gem::Requirement
@@ -112,6 +112,20 @@ dependencies:
112
112
  - - ">="
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
+ - !ruby/object:Gem::Dependency
116
+ name: bundler
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
115
129
  description: The default_value_for plugin allows one to define default values for
116
130
  ActiveRecord models in a declarative manner
117
131
  email: software-signing@phusion.nl
@@ -139,14 +153,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
153
  requirements:
140
154
  - - ">="
141
155
  - !ruby/object:Gem::Version
142
- version: 1.9.3
156
+ version: 3.0.0
143
157
  required_rubygems_version: !ruby/object:Gem::Requirement
144
158
  requirements:
145
159
  - - ">="
146
160
  - !ruby/object:Gem::Version
147
161
  version: '0'
148
162
  requirements: []
149
- rubygems_version: 3.3.27
163
+ rubygems_version: 3.5.11
150
164
  signing_key:
151
165
  specification_version: 4
152
166
  summary: Provides a way to specify default values for ActiveRecord models