groupy 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -2
- data/lib/groupy.rb +11 -2
- data/test/groupy_test.rb +1 -1
- data/test/with_database_test.rb +6 -2
- metadata +31 -3
data/Rakefile
CHANGED
@@ -33,7 +33,7 @@ spec = Gem::Specification.new do |s|
|
|
33
33
|
|
34
34
|
# Change these as appropriate
|
35
35
|
s.name = "groupy"
|
36
|
-
s.version = "0.2.
|
36
|
+
s.version = "0.2.2"
|
37
37
|
s.summary = "Categorise Active Records in nested groups with magical scopes, ? methods, and constants."
|
38
38
|
s.author = "Matthew Rudy Jacobs"
|
39
39
|
s.email = "MatthewRudyJacobs@gmail.com"
|
@@ -52,7 +52,8 @@ spec = Gem::Specification.new do |s|
|
|
52
52
|
s.add_dependency("activesupport")
|
53
53
|
|
54
54
|
# If your tests use any gems, include them here
|
55
|
-
|
55
|
+
s.add_development_dependency("activerecord")
|
56
|
+
s.add_development_dependency("sqlite3-ruby")
|
56
57
|
end
|
57
58
|
|
58
59
|
# This task actually builds the gem. We also regenerate a static
|
data/lib/groupy.rb
CHANGED
@@ -73,7 +73,11 @@ module Groupy
|
|
73
73
|
def initialize(&block)
|
74
74
|
super(:all, &block)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
|
+
def subgroups
|
78
|
+
super().merge(:all => self.values)
|
79
|
+
end
|
80
|
+
|
77
81
|
def attach!(klass, column_name, options)
|
78
82
|
self.subgroups.each do |group_name, group_values|
|
79
83
|
|
@@ -110,7 +114,12 @@ module Groupy
|
|
110
114
|
|
111
115
|
klass.class_eval <<-RUBY
|
112
116
|
def self.all_#{column_name.to_s.pluralize}
|
113
|
-
self
|
117
|
+
self.#{column_name.to_s.pluralize}(:all)
|
118
|
+
end
|
119
|
+
|
120
|
+
# self.roles(:non_superadmin) => ["some", "list", "of", "roles"]
|
121
|
+
def self.#{column_name.to_s.pluralize}(subgroup_name)
|
122
|
+
self.groupies[#{column_name.inspect}].subgroups[subgroup_name]
|
114
123
|
end
|
115
124
|
RUBY
|
116
125
|
end
|
data/test/groupy_test.rb
CHANGED
@@ -45,7 +45,7 @@ class GroupyTest < ActiveSupport::TestCase
|
|
45
45
|
end
|
46
46
|
|
47
47
|
test "subgroups" do
|
48
|
-
assert_equal [:healthy, :fruit, :apple, :orange, :rice, :unhealthy, :fried_egg, :bacon].sort_by(&:to_s), Food.groupies[:dish].subgroups.keys.sort_by(&:to_s)
|
48
|
+
assert_equal [:all, :healthy, :fruit, :apple, :orange, :rice, :unhealthy, :fried_egg, :bacon].sort_by(&:to_s), Food.groupies[:dish].subgroups.keys.sort_by(&:to_s)
|
49
49
|
assert_equal ["apple", "orange", "rice"], Food.groupies[:dish].subgroups[:healthy]
|
50
50
|
assert_equal ["apple", "orange"], Food.groupies[:dish].subgroups[:fruit]
|
51
51
|
assert_equal ["apple"], Food.groupies[:dish].subgroups[:apple]
|
data/test/with_database_test.rb
CHANGED
@@ -5,8 +5,7 @@ require 'active_record'
|
|
5
5
|
|
6
6
|
ActiveRecord::Base.establish_connection(
|
7
7
|
:adapter => "sqlite3",
|
8
|
-
:
|
9
|
-
:database => "groupy_test"
|
8
|
+
:database => ":memory:"
|
10
9
|
)
|
11
10
|
|
12
11
|
ActiveRecord::Schema.define(:version => 0) do
|
@@ -44,4 +43,9 @@ class WithDatabaseTest < ActiveSupport::TestCase
|
|
44
43
|
assert_equal 1, Something.medium_sizes.count
|
45
44
|
end
|
46
45
|
|
46
|
+
test "subgroup shortcut" do
|
47
|
+
assert_equal ["small", "medium", "large"], Something.sizes(:all)
|
48
|
+
assert_equal ["small"], Something.sizes(:small)
|
49
|
+
end
|
50
|
+
|
47
51
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groupy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthew Rudy Jacobs
|
@@ -32,6 +32,34 @@ dependencies:
|
|
32
32
|
version: "0"
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activerecord
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: sqlite3-ruby
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
35
63
|
description:
|
36
64
|
email: MatthewRudyJacobs@gmail.com
|
37
65
|
executables: []
|