groupify 0.6.0.rc1 → 0.6.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,91 @@
1
+ module Groupify
2
+ module Mongoid
3
+
4
+ # Usage:
5
+ # class User
6
+ # include Mongoid::Document
7
+ #
8
+ # acts_as_named_group_member
9
+ # ...
10
+ # end
11
+ #
12
+ # user.named_groups << :admin
13
+ #
14
+ module NamedGroupMember
15
+ extend ActiveSupport::Concern
16
+ include MemberScopedAs
17
+
18
+ included do
19
+ field :named_groups, type: Array, default: -> { [] }
20
+
21
+ after_initialize do
22
+ named_groups.extend NamedGroupCollection
23
+ named_groups.member = self
24
+ end
25
+ end
26
+
27
+ def in_named_group?(named_group, opts={})
28
+ named_groups.as(opts[:as]).include?(named_group)
29
+ end
30
+
31
+ def in_any_named_group?(*args)
32
+ opts = args.extract_options!
33
+ group_names = args.flatten
34
+
35
+ group_names.each do |named_group|
36
+ return true if in_named_group?(named_group)
37
+ end
38
+
39
+ return false
40
+ end
41
+
42
+ def in_all_named_groups?(*args)
43
+ opts = args.extract_options!
44
+ named_groups = args.flatten.to_set
45
+
46
+ named_groups.subset? self.named_groups.as(opts[:as]).to_set
47
+ end
48
+
49
+ def in_only_named_groups?(*args)
50
+ opts = args.extract_options!
51
+ named_groups = args.flatten.to_set
52
+ named_groups == self.named_groups.as(opts[:as]).to_set
53
+ end
54
+
55
+ def shares_any_named_group?(other, opts={})
56
+ in_any_named_group?(other.named_groups, opts)
57
+ end
58
+
59
+ module ClassMethods
60
+ def in_named_group(named_group, opts={})
61
+ in_any_named_group(named_group, opts)
62
+ end
63
+
64
+ def in_any_named_group(*named_groups)
65
+ named_groups.flatten!
66
+ return none unless named_groups.present?
67
+
68
+ self.in(named_groups: named_groups.flatten)
69
+ end
70
+
71
+ def in_all_named_groups(*named_groups)
72
+ named_groups.flatten!
73
+ return none unless named_groups.present?
74
+
75
+ where(:named_groups.all => named_groups.flatten)
76
+ end
77
+
78
+ def in_only_named_groups(*named_groups)
79
+ named_groups.flatten!
80
+ return none unless named_groups.present?
81
+
82
+ where(named_groups: named_groups.flatten)
83
+ end
84
+
85
+ def shares_any_named_group(other, opts={})
86
+ in_any_named_group(other.named_groups, opts)
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -17,4 +17,4 @@ module Groupify
17
17
  end
18
18
 
19
19
  end
20
- end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Groupify
2
- VERSION = "0.6.0.rc1"
2
+ VERSION = "0.6.0.rc2"
3
3
  end
@@ -271,6 +271,19 @@ describe Groupify::ActiveRecord do
271
271
  expect(destination.managers).to include(manager)
272
272
  end
273
273
 
274
+ it "moves membership types" do
275
+ source = Group.create!
276
+ destination = Organization.create!
277
+
278
+ source.add(user)
279
+ source.add(manager, as: 'manager')
280
+
281
+ destination.merge!(source)
282
+ expect(source.destroyed?).to be true
283
+
284
+ expect(destination.users.as(:manager)).to include(manager)
285
+ end
286
+
274
287
  it "fails to merge if the destination group cannot contain the source group's members" do
275
288
  source = Organization.create!
276
289
  destination = Group.create!
@@ -242,6 +242,19 @@ describe Groupify::Mongoid do
242
242
  expect(destination.tasks.to_a).to include(task)
243
243
  end
244
244
 
245
+ it "moves membership types" do
246
+ source = MongoidGroup.create!
247
+ destination = MongoidProject.create!
248
+
249
+ source.add(user)
250
+ source.add(manager, as: 'manager')
251
+
252
+ destination.merge!(source)
253
+ expect(source.destroyed?).to be true
254
+
255
+ expect(destination.users.as(:manager)).to include(manager)
256
+ end
257
+
245
258
  it "fails to merge if the destination group cannot contain the source group's members" do
246
259
  source = MongoidProject.create!
247
260
  destination = MongoidGroup.create!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groupify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.rc1
4
+ version: 0.6.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - dwbutler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-18 00:00:00.000000000 Z
11
+ date: 2014-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -130,11 +130,23 @@ files:
130
130
  - groupify.gemspec
131
131
  - lib/groupify.rb
132
132
  - lib/groupify/adapter/active_record.rb
133
+ - lib/groupify/adapter/active_record/group.rb
134
+ - lib/groupify/adapter/active_record/group_member.rb
135
+ - lib/groupify/adapter/active_record/group_membership.rb
136
+ - lib/groupify/adapter/active_record/model.rb
137
+ - lib/groupify/adapter/active_record/named_group_collection.rb
138
+ - lib/groupify/adapter/active_record/named_group_member.rb
133
139
  - lib/groupify/adapter/mongoid.rb
140
+ - lib/groupify/adapter/mongoid/group.rb
141
+ - lib/groupify/adapter/mongoid/group_member.rb
142
+ - lib/groupify/adapter/mongoid/member_scoped_as.rb
143
+ - lib/groupify/adapter/mongoid/model.rb
144
+ - lib/groupify/adapter/mongoid/named_group_collection.rb
145
+ - lib/groupify/adapter/mongoid/named_group_member.rb
134
146
  - lib/groupify/railtie.rb
135
147
  - lib/groupify/version.rb
136
- - spec/groupify/active_record_spec.rb
137
- - spec/groupify/mongoid_spec.rb
148
+ - spec/active_record_spec.rb
149
+ - spec/mongoid_spec.rb
138
150
  - spec/spec_helper.rb
139
151
  homepage: https://github.com/dwbutler/groupify
140
152
  licenses:
@@ -161,6 +173,6 @@ signing_key:
161
173
  specification_version: 4
162
174
  summary: Group functionality for Rails
163
175
  test_files:
164
- - spec/groupify/active_record_spec.rb
165
- - spec/groupify/mongoid_spec.rb
176
+ - spec/active_record_spec.rb
177
+ - spec/mongoid_spec.rb
166
178
  - spec/spec_helper.rb