simple_group 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f47630bc3ad16cf66d9aa6fb224de3cb8aa40e2
4
- data.tar.gz: 028ca3ce3d739386e6254457910ba5d4f305d99f
3
+ metadata.gz: 6f1b79e0f95379a33f17b1227b437f53032b140a
4
+ data.tar.gz: 7a7efe44591c5376652791bf4908e5131aa01023
5
5
  SHA512:
6
- metadata.gz: 642dd9661d75bacc87f9f39e3eef6619537fcc7e2986d1d4dfcee1fc7c192a63a28c5859fb826335e89783f58e99ab9aa1ce0cf29859245fc678b43b3505a257
7
- data.tar.gz: ddf13fe7880005e85a95bcedc51206b18acc7675b5b0fdf822581316c10008f9bd33afcc3275aa35e2d0c271c2f4b8459b8b54e1c734ba8b36124590ca992398
6
+ metadata.gz: 65605cac5efaa68e755be72ac38508625f3288c5438432901cf26d41554998febea8dc7bf6a0bfd5301285c3fa9905f8cc19f67c7f7018200c58c93c78247756
7
+ data.tar.gz: 0ed9b29df1ed5728c41748b666dfda6cd0146728e714042923b5c3f8d52f11cc2dc123812f802cc28785329ab890f280e7bbafbf3d3c2c412751a6b3574ceb09
@@ -7,9 +7,11 @@ class SimpleGroupMigration < ActiveRecord::Migration
7
7
  end
8
8
 
9
9
  if ActiveRecord::VERSION::MAJOR < 4
10
- add_index :simple_groups, [:group_item_id, :group_item_type]
11
- add_index :simple_groups, [:group_id, :group_type]
10
+ add_index :simple_group_combinations, [:group_item_id, :group_item_type]
11
+ add_index :simple_group_combinations, [:group_id, :group_type]
12
12
  end
13
+ add_index :simple_group_combinations, [:group_item_id, :group_item_type, :group_id, :group_type],
14
+ unique: true, name: :index_simple_group_combinations
13
15
  end
14
16
 
15
17
  def self.down
@@ -16,6 +16,7 @@ module SimpleGroup
16
16
 
17
17
  validates :group_item_id, presence: true
18
18
  validates :group_id, presence: true
19
+ validates_uniqueness_of :group_id, scope: [:group_type, :group_item_id, :group_item_type]
19
20
  end
20
21
 
21
22
  class GroupNotAllowError < Exception; end
@@ -10,9 +10,18 @@ module SimpleGroup
10
10
  end
11
11
  end
12
12
 
13
+ def include?(model)
14
+ raise SimpleGroup::GroupNotAllowError unless model.class.groupable?
15
+ SimpleGroup::Combination.exists?(group: self, group_item: model)
16
+ end
17
+
18
+ def exclude?(model)
19
+ !include?(model)
20
+ end
21
+
13
22
  def add(model)
14
23
  raise SimpleGroup::GroupNotAllowError unless model.class.groupable?
15
- SimpleGroup::Combination.create(group: self, group_item: model)
24
+ SimpleGroup::Combination.new(group: self, group_item: model).save
16
25
  end
17
26
 
18
27
  def remove(model)
@@ -1,3 +1,3 @@
1
1
  module SimpleGroup
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_group
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toyoaki Oko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-13 00:00:00.000000000 Z
11
+ date: 2015-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler