active_type 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile.3.2.mysql2.lock +1 -1
- data/Gemfile.3.2.sqlite3.lock +1 -1
- data/Gemfile.4.2.mysql2.lock +1 -1
- data/Gemfile.4.2.pg.lock +1 -1
- data/Gemfile.4.2.sqlite3.lock +1 -1
- data/Gemfile.5.2.mysql2.lock +1 -1
- data/Gemfile.5.2.pg.lock +1 -1
- data/Gemfile.5.2.sqlite3.lock +1 -1
- data/Gemfile.6.0.pg.lock +1 -1
- data/README.md +30 -7
- data/lib/active_type/change_association.rb +31 -0
- data/lib/active_type/record.rb +4 -2
- data/lib/active_type/{extended_record.rb → record_extension.rb} +3 -3
- data/lib/active_type/{extended_record → record_extension}/inheritance.rb +8 -4
- data/lib/active_type/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cca938174e6902624f069ca895ff0ee565f2db0696ef0460702a125ee84c303
|
4
|
+
data.tar.gz: 3821a7c56f508d8b3f90d8301e3488844f0dc5bf905780358f6925c6137a1211
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5624b33d08104097164b692a39f4f31262ccfb86f05de711851f179cdc1c4f06d46d41712bd915eac557aee96f473b9f3aa83c42edba7c047e686cfbd5798726
|
7
|
+
data.tar.gz: f17e251805aad979ad202afe86d69ebe997a7fb8e0ad6a4843ce49d2c125ed11c81779791c2ec7d6ba6dcdad31c5fa1cf953ef3163d1600f8e8eef2c30c19fd2
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## Unreleased
|
6
|
+
|
7
|
+
## 1.2.0 (2019-06-18)
|
8
|
+
|
9
|
+
* Fixed: Using `has_many` et al in an extended record ignored given scopes.
|
10
|
+
* Added: `change_association` on ActiveType::Record to change assocation options.
|
11
|
+
|
12
|
+
|
5
13
|
## 1.1.1 (2019-05-07)
|
6
14
|
|
7
15
|
* Improved dirty tracking (`#changes?` etc) for virtual attributes to bring it more in line with
|
data/Gemfile.3.2.mysql2.lock
CHANGED
data/Gemfile.3.2.sqlite3.lock
CHANGED
data/Gemfile.4.2.mysql2.lock
CHANGED
data/Gemfile.4.2.pg.lock
CHANGED
data/Gemfile.4.2.sqlite3.lock
CHANGED
data/Gemfile.5.2.mysql2.lock
CHANGED
data/Gemfile.5.2.pg.lock
CHANGED
data/Gemfile.5.2.sqlite3.lock
CHANGED
data/Gemfile.6.0.pg.lock
CHANGED
data/README.md
CHANGED
@@ -363,6 +363,31 @@ sign_up.is_a?(SignUp) # => true
|
|
363
363
|
```
|
364
364
|
|
365
365
|
|
366
|
+
Associations
|
367
|
+
------------
|
368
|
+
|
369
|
+
Sometimes, you have an association, and a form model for that association. Instead of always casting the associations manually, you can use the `change_association` macro to override an association's options. For example.
|
370
|
+
|
371
|
+
|
372
|
+
```
|
373
|
+
class Credential < ActiveRecord::Base
|
374
|
+
end
|
375
|
+
|
376
|
+
class User < ActiveRecord::Base
|
377
|
+
has_many :credentials
|
378
|
+
end
|
379
|
+
|
380
|
+
class SignUpCredential < ActiveType::Record[Credential]
|
381
|
+
end
|
382
|
+
|
383
|
+
class SignUp < ActiveType::Record[User]
|
384
|
+
change_association :credentials, class_name: 'SignUpCredential'
|
385
|
+
end
|
386
|
+
```
|
387
|
+
|
388
|
+
Now, if you load `credentials`, you will automatically receive records of type `SignUpCredential`.
|
389
|
+
|
390
|
+
|
366
391
|
Supported Rails versions
|
367
392
|
------------------------
|
368
393
|
|
@@ -389,13 +414,11 @@ Now run `bundle install` and restart your server.
|
|
389
414
|
Development
|
390
415
|
-----------
|
391
416
|
|
392
|
-
- We run tests against several ActiveRecord versions.
|
393
|
-
- You can bundle all versions with `rake
|
394
|
-
- You can run specs against all
|
395
|
-
- You can run specs against a single
|
396
|
-
|
397
|
-
If you are getting testing failures due to Mysql trying to connect as `root` user, you can put your Mysql credentials into `spec/support/database.yml`.
|
398
|
-
See `spec/support/database.sample.yml` for an example.
|
417
|
+
- We run tests against several ActiveRecord and Ruby versions using [gemika](https://github.com/makandra/gemika).
|
418
|
+
- You can bundle all versions with `rake matrix:install`.
|
419
|
+
- You can run specs against all Gemfiles compatible with your current ruby version with `rake matrix:spec`.
|
420
|
+
- You can run specs against a single Gemfile with `BUNDLE_GEMFILE=Gemfile<variant> bundle exec rspec spec`.
|
421
|
+
- When you make a pull request, tests are automatically run against all variants and Rubies on travis.ci.
|
399
422
|
|
400
423
|
If you would like to contribute:
|
401
424
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ActiveType
|
2
|
+
|
3
|
+
module ChangeAssociation
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
def change_association(association_name, new_scope, new_options = nil)
|
10
|
+
if (existing_association = self.reflect_on_association(association_name))
|
11
|
+
if new_scope.is_a?(Hash)
|
12
|
+
new_options = new_scope
|
13
|
+
new_scope = nil
|
14
|
+
end
|
15
|
+
original_options = existing_association.options
|
16
|
+
if ActiveRecord::VERSION::MAJOR > 3
|
17
|
+
new_scope ||= existing_association.scope
|
18
|
+
public_send(existing_association.macro, association_name, new_scope, original_options.merge(new_options))
|
19
|
+
else
|
20
|
+
public_send(existing_association.macro, association_name, original_options.merge(new_options))
|
21
|
+
end
|
22
|
+
else
|
23
|
+
raise ArgumentError, "unrecognized association `#{association_name}`"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/active_type/record.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'active_type/virtual_attributes'
|
2
|
-
require 'active_type/
|
2
|
+
require 'active_type/record_extension'
|
3
3
|
require 'active_type/nested_attributes'
|
4
|
+
require 'active_type/change_association'
|
4
5
|
|
5
6
|
module ActiveType
|
6
7
|
|
@@ -10,7 +11,8 @@ module ActiveType
|
|
10
11
|
|
11
12
|
include VirtualAttributes
|
12
13
|
include NestedAttributes
|
13
|
-
include
|
14
|
+
include RecordExtension
|
15
|
+
include ChangeAssociation
|
14
16
|
|
15
17
|
end
|
16
18
|
|
@@ -1,9 +1,8 @@
|
|
1
|
-
require 'active_type/
|
2
|
-
require 'active_type/extended_record/inheritance'
|
1
|
+
require 'active_type/record_extension/inheritance'
|
3
2
|
|
4
3
|
module ActiveType
|
5
4
|
|
6
|
-
module
|
5
|
+
module RecordExtension
|
7
6
|
|
8
7
|
extend ActiveSupport::Concern
|
9
8
|
|
@@ -15,6 +14,7 @@ module ActiveType
|
|
15
14
|
include VirtualAttributes
|
16
15
|
include NestedAttributes
|
17
16
|
include Inheritance
|
17
|
+
include ChangeAssociation
|
18
18
|
|
19
19
|
self.extended_record_base_class = base
|
20
20
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ActiveType
|
2
2
|
|
3
|
-
module
|
3
|
+
module RecordExtension
|
4
4
|
|
5
5
|
module Inheritance
|
6
6
|
|
@@ -18,7 +18,11 @@ module ActiveType
|
|
18
18
|
unless options[:foreign_key]
|
19
19
|
options = options.merge(foreign_key: extended_record_base_class.name.foreign_key)
|
20
20
|
end
|
21
|
-
|
21
|
+
if ActiveRecord::VERSION::MAJOR > 3
|
22
|
+
[scope, options]
|
23
|
+
else
|
24
|
+
[options]
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
module ClassMethods
|
@@ -32,11 +36,11 @@ module ActiveType
|
|
32
36
|
end
|
33
37
|
|
34
38
|
def has_many(name, *args, &extension)
|
35
|
-
super(name, Inheritance.add_foreign_key_option(extended_record_base_class, *args), &extension)
|
39
|
+
super(name, *Inheritance.add_foreign_key_option(extended_record_base_class, *args), &extension)
|
36
40
|
end
|
37
41
|
|
38
42
|
def has_one(name, *args, &extension)
|
39
|
-
super(name, Inheritance.add_foreign_key_option(extended_record_base_class, *args), &extension)
|
43
|
+
super(name, *Inheritance.add_foreign_key_option(extended_record_base_class, *args), &extension)
|
40
44
|
end
|
41
45
|
|
42
46
|
private
|
data/lib/active_type/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_type
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Kraze
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -89,8 +89,7 @@ files:
|
|
89
89
|
- Rakefile
|
90
90
|
- active_type.gemspec
|
91
91
|
- lib/active_type.rb
|
92
|
-
- lib/active_type/
|
93
|
-
- lib/active_type/extended_record/inheritance.rb
|
92
|
+
- lib/active_type/change_association.rb
|
94
93
|
- lib/active_type/nested_attributes.rb
|
95
94
|
- lib/active_type/nested_attributes/association.rb
|
96
95
|
- lib/active_type/nested_attributes/builder.rb
|
@@ -99,6 +98,8 @@ files:
|
|
99
98
|
- lib/active_type/no_table.rb
|
100
99
|
- lib/active_type/object.rb
|
101
100
|
- lib/active_type/record.rb
|
101
|
+
- lib/active_type/record_extension.rb
|
102
|
+
- lib/active_type/record_extension/inheritance.rb
|
102
103
|
- lib/active_type/type_caster.rb
|
103
104
|
- lib/active_type/util.rb
|
104
105
|
- lib/active_type/version.rb
|
@@ -123,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
124
|
version: '0'
|
124
125
|
requirements: []
|
125
126
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.7.
|
127
|
+
rubygems_version: 2.7.8
|
127
128
|
signing_key:
|
128
129
|
specification_version: 4
|
129
130
|
summary: Make any Ruby object quack like ActiveRecord
|