virtus-group 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjdlNTExNGFjNjgyOTQ1ZWMzNzJlMDczNGUyNmI0MmYzOTZmNmRkZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Y2NjYjg1NDZjYWRiNmY0NzdiOTMxMTgwMmFmMjRiZTU5ODU5Y2NhOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjVjZjc0YzJjZmE1ZjM2ZGQxNjg4NWViZjQ1OGU5OTQ1YjQyNTRiZTY1YmIx
|
10
|
+
NmI1Mjk4OTE0ODE4YTNmMDFlZDAzMTI1MmI3ZmY0ZWQ1NGJmNjc3Y2U0MjEx
|
11
|
+
ZGMzMjJiZjczNTg2MWRkMzFlZGRjMDVlYWMyZTM3MWQxMTZmYTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODJjODMwZjY1Mzk5ZjE4MDUwOWY2ZjQ4ZmQyZDE2MjVmZWI2MDNkMjA0Zjc5
|
14
|
+
NDRiMTAyOWU2YjdjYTVkNjdjZWVmYTM3YjEwNDcyMTc3Yjc3MjQ0MjY1ODA1
|
15
|
+
MGNkM2ZhYWU3MzlkOGU5NmMwYzBhMmU2ZDI5ODk4MjNhNjgyZWE=
|
data/lib/virtus/group.rb
CHANGED
@@ -25,7 +25,13 @@ module Virtus
|
|
25
25
|
|
26
26
|
def group(name, &block)
|
27
27
|
attribute_tracker = AttributeTracker.new(self, &block)
|
28
|
-
|
28
|
+
|
29
|
+
if attribute_group.has_key?(name)
|
30
|
+
attribute_group[name] ||= []
|
31
|
+
attribute_group[name] |= attribute_tracker.tracked_attributes
|
32
|
+
else
|
33
|
+
attribute_group[name] = attribute_tracker.tracked_attributes
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
def attribute_group
|
data/lib/virtus/group/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Virtus::Group, "horizontal inheritance" do
|
4
|
+
let!(:base_class) do
|
5
|
+
Class.new do
|
6
|
+
include Virtus.model
|
7
|
+
include Virtus.group
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let!(:user_class) do
|
12
|
+
Class.new(base_class) do
|
13
|
+
group :user do
|
14
|
+
attribute :email, String
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
let!(:address_class) do
|
20
|
+
Class.new(base_class) do
|
21
|
+
group :address do
|
22
|
+
attribute :city, String
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "base class" do
|
28
|
+
it "should have no attribute groups" do
|
29
|
+
expect(base_class.attribute_group).to be_empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "user class" do
|
34
|
+
it "should have only the user attributes" do
|
35
|
+
expect(user_class.attribute_group).to include :user
|
36
|
+
expect(user_class.attribute_group).not_to include :address
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "address class" do
|
41
|
+
it "should have only the address attributes" do
|
42
|
+
expect(address_class.attribute_group).to include :address
|
43
|
+
expect(address_class.attribute_group).not_to include :user
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Virtus::Group, "inherit from same group" do
|
4
|
+
let!(:user_base_class) do
|
5
|
+
Class.new do
|
6
|
+
include Virtus.model
|
7
|
+
include Virtus.group
|
8
|
+
|
9
|
+
group :user do
|
10
|
+
attribute :email
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let!(:user_class) do
|
16
|
+
Class.new(user_base_class) do
|
17
|
+
group :user do
|
18
|
+
attribute :password, String
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
let!(:other_user_class) do
|
24
|
+
Class.new(user_base_class) do
|
25
|
+
group :user do
|
26
|
+
attribute :token, String
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
let!(:mega_user_class) do
|
32
|
+
Class.new(user_class) do
|
33
|
+
group :user do
|
34
|
+
attribute :token, String
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "user class" do
|
40
|
+
it "should have the email and password attribute" do
|
41
|
+
expect(user_class.attribute_group[:user]).to eq [:email, :password]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "other user class" do
|
46
|
+
it "should have the email and token attribute" do
|
47
|
+
expect(other_user_class.attribute_group[:user]).to eq [:email, :token]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "mega user class" do
|
52
|
+
it "should have the email, password and token attribute" do
|
53
|
+
expect(mega_user_class.attribute_group[:user]).to eq [:email, :password, :token]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when accidentally adding same attribute twice" do
|
58
|
+
let!(:user_class) do
|
59
|
+
Class.new(user_base_class) do
|
60
|
+
group :user do
|
61
|
+
attribute :email, String
|
62
|
+
attribute :password, String
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not add email twice" do
|
68
|
+
expect(user_class.attribute_group[:user]).to eq [:email, :password]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtus-group
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spas Poptchev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -71,6 +71,8 @@ files:
|
|
71
71
|
- lib/virtus/group/attribute_groups.rb
|
72
72
|
- lib/virtus/group/attribute_tracker.rb
|
73
73
|
- lib/virtus/group/version.rb
|
74
|
+
- spec/integration/horizontal_inheritance_spec.rb
|
75
|
+
- spec/integration/inherit_from_same_group_spec.rb
|
74
76
|
- spec/integration/virtus_group_integration_spec.rb
|
75
77
|
- spec/spec_helper.rb
|
76
78
|
- spec/unit/group/attribute_groups_spec.rb
|
@@ -102,6 +104,8 @@ signing_key:
|
|
102
104
|
specification_version: 4
|
103
105
|
summary: Define groups over virtus attributes.
|
104
106
|
test_files:
|
107
|
+
- spec/integration/horizontal_inheritance_spec.rb
|
108
|
+
- spec/integration/inherit_from_same_group_spec.rb
|
105
109
|
- spec/integration/virtus_group_integration_spec.rb
|
106
110
|
- spec/spec_helper.rb
|
107
111
|
- spec/unit/group/attribute_groups_spec.rb
|