groupy 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +108 -0
- data/Rakefile +11 -8
- data/lib/groupy.rb +6 -1
- data/test/test_helper.rb +3 -5
- metadata +115 -79
- data/README +0 -92
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5aaf7c85ef5a4ea110b016cc5d6ba2f5019ff6ef0209bc6153146db6944857fa
|
4
|
+
data.tar.gz: c40deb91bf687c41a642ce2bc9f4e36b28c95c8c3916a00ded4e965b9d5ddae2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24eec4b353c8dde515de7109c42d0895146c499986bcf5eb86b823183520dc4dc7cca90262021b19e49476d5c5911e18bd5df8e44c316770bc9f82b972f39f11
|
7
|
+
data.tar.gz: ff9d25151280abe55bdad25b8f3eddd4f039cbc80d2b899ec5701dd22bb694d44b54b3b3b3c8a098eb7cb1ec7ed7ed0f69ee740d5352fcffd03c0cb1ac048abe
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
Groupy [![Build Status](https://travis-ci.org/matthewrudy/groupy.svg?branch=master)](https://travis-ci.org/matthewrudy/groupy)
|
2
|
+
=======
|
3
|
+
|
4
|
+
Categorise records into nested groups of values.
|
5
|
+
|
6
|
+
Example
|
7
|
+
=======
|
8
|
+
|
9
|
+
Define our groups
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
class Food
|
13
|
+
property :dish, String
|
14
|
+
|
15
|
+
include Groupy
|
16
|
+
groupy :dish do
|
17
|
+
group :healthy do
|
18
|
+
group :fruit do
|
19
|
+
value :apple
|
20
|
+
value :orange
|
21
|
+
end
|
22
|
+
value :rice
|
23
|
+
end
|
24
|
+
|
25
|
+
group :unhealthy do
|
26
|
+
value :fried_egg
|
27
|
+
value :bacon
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
We can then ask a particular food:
|
34
|
+
|
35
|
+
``` ruby
|
36
|
+
apple.healthy?
|
37
|
+
apple.fruit?
|
38
|
+
apple.apple?
|
39
|
+
```
|
40
|
+
|
41
|
+
And we can scope the class by any of these groups
|
42
|
+
|
43
|
+
``` ruby
|
44
|
+
Food.apples.count
|
45
|
+
Food.fruits.all
|
46
|
+
```
|
47
|
+
|
48
|
+
We also get a magic "all_" method
|
49
|
+
|
50
|
+
``` ruby
|
51
|
+
Food.all_dishes
|
52
|
+
```
|
53
|
+
|
54
|
+
You can also tell groupy to add the column name as a suffix
|
55
|
+
|
56
|
+
``` ruby
|
57
|
+
class Something
|
58
|
+
groupy :size, :suffix => true do
|
59
|
+
value :small
|
60
|
+
value :medium
|
61
|
+
value :large
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
something.small_size?
|
66
|
+
```
|
67
|
+
|
68
|
+
Or you may want to store all the values as a conveniently named constant.
|
69
|
+
|
70
|
+
``` ruby
|
71
|
+
class Something
|
72
|
+
groupy :size, :constants => true do
|
73
|
+
value :small
|
74
|
+
value :medium
|
75
|
+
value :large
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
Something::SMALL
|
80
|
+
Something::MEDIUM
|
81
|
+
Something::LARGE
|
82
|
+
```
|
83
|
+
|
84
|
+
Or of course you can do both together
|
85
|
+
|
86
|
+
``` ruby
|
87
|
+
Something::SMALL_SIZE
|
88
|
+
Something::MEDIUM_SIZE
|
89
|
+
Something::LARGE_SIZE
|
90
|
+
```
|
91
|
+
|
92
|
+
Any values will be lowercased and underscored
|
93
|
+
|
94
|
+
``` ruby
|
95
|
+
class Something
|
96
|
+
groupy :type do
|
97
|
+
value :SomeClass
|
98
|
+
value :"Namespace::KlassName"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
something.some_class?
|
103
|
+
something.namespace_klass_name?
|
104
|
+
```
|
105
|
+
|
106
|
+
B00m!
|
107
|
+
|
108
|
+
Copyright (c) 2010 [Matthew Rudy Jacobs], released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/testtask'
|
3
|
-
require '
|
3
|
+
require 'rdoc/task'
|
4
4
|
|
5
5
|
desc 'Default: run unit tests.'
|
6
6
|
task :default => :test
|
@@ -22,7 +22,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
22
22
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
23
|
end
|
24
24
|
|
25
|
-
require
|
25
|
+
require 'rubygems/package_task'
|
26
26
|
|
27
27
|
# This builds the actual gem. For details of what all these options
|
28
28
|
# mean, and other ones you can add, check the documentation here:
|
@@ -33,18 +33,17 @@ spec = Gem::Specification.new do |s|
|
|
33
33
|
|
34
34
|
# Change these as appropriate
|
35
35
|
s.name = "groupy"
|
36
|
-
s.version = "0.
|
36
|
+
s.version = "0.3.0"
|
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"
|
40
40
|
s.homepage = "https://github.com/matthewrudy/groupy"
|
41
41
|
|
42
|
-
s.
|
43
|
-
s.
|
44
|
-
s.rdoc_options = %w(--main README)
|
42
|
+
s.extra_rdoc_files = %w(README.md)
|
43
|
+
s.rdoc_options = %w(--main README.md)
|
45
44
|
|
46
45
|
# Add any extra files to include in the gem
|
47
|
-
s.files = %w(README MIT-LICENSE Rakefile) + Dir.glob("{test,lib}/**/*")
|
46
|
+
s.files = %w(README.md MIT-LICENSE Rakefile) + Dir.glob("{test,lib}/**/*")
|
48
47
|
s.require_paths = ["lib"]
|
49
48
|
|
50
49
|
# If you want to depend on other gems, add them here, along with any
|
@@ -53,7 +52,11 @@ spec = Gem::Specification.new do |s|
|
|
53
52
|
|
54
53
|
# If your tests use any gems, include them here
|
55
54
|
s.add_development_dependency("activerecord")
|
55
|
+
s.add_development_dependency("minitest")
|
56
|
+
s.add_development_dependency("rake")
|
57
|
+
s.add_development_dependency("rdoc")
|
56
58
|
s.add_development_dependency("sqlite3-ruby")
|
59
|
+
s.add_development_dependency("test-unit")
|
57
60
|
end
|
58
61
|
|
59
62
|
# This task actually builds the gem. We also regenerate a static
|
@@ -63,7 +66,7 @@ end
|
|
63
66
|
#
|
64
67
|
# To publish your gem online, install the 'gemcutter' gem; Read more
|
65
68
|
# about that here: http://gemcutter.org/pages/gem_docs
|
66
|
-
|
69
|
+
Gem::PackageTask.new(spec) do |pkg|
|
67
70
|
pkg.gem_spec = spec
|
68
71
|
end
|
69
72
|
|
data/lib/groupy.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/core_ext/class/attribute_accessors'
|
2
|
+
require 'active_support/core_ext/string/inflections'
|
2
3
|
|
3
4
|
module Groupy
|
4
5
|
|
@@ -96,7 +97,11 @@ module Groupy
|
|
96
97
|
scope_name = method_name.to_s.pluralize
|
97
98
|
|
98
99
|
if defined?(ActiveRecord) && klass < ActiveRecord::Base
|
99
|
-
klass.
|
100
|
+
klass.class_eval <<-RUBY
|
101
|
+
def self.#{scope_name}
|
102
|
+
where(#{column_name.inspect} => #{group_values.inspect})
|
103
|
+
end
|
104
|
+
RUBY
|
100
105
|
end
|
101
106
|
end
|
102
107
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,115 +1,151 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: groupy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 3
|
10
|
-
version: 0.2.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Matthew Rudy Jacobs
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2018-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: activesupport
|
23
|
-
|
24
|
-
|
25
|
-
none: false
|
26
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
27
17
|
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
33
20
|
type: :runtime
|
34
|
-
|
35
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
36
28
|
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
37
49
|
prerelease: false
|
38
|
-
|
39
|
-
|
40
|
-
requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
41
52
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
type: :development
|
48
|
-
|
49
|
-
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rdoc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
50
84
|
name: sqlite3-ruby
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
51
91
|
prerelease: false
|
52
|
-
|
53
|
-
|
54
|
-
requirements:
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
55
94
|
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: test-unit
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
61
104
|
type: :development
|
62
|
-
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
63
111
|
description:
|
64
112
|
email: MatthewRudyJacobs@gmail.com
|
65
113
|
executables: []
|
66
|
-
|
67
114
|
extensions: []
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
files:
|
72
|
-
- README
|
115
|
+
extra_rdoc_files:
|
116
|
+
- README.md
|
117
|
+
files:
|
73
118
|
- MIT-LICENSE
|
119
|
+
- README.md
|
74
120
|
- Rakefile
|
121
|
+
- lib/groupy.rb
|
75
122
|
- test/groupy_test.rb
|
76
123
|
- test/test_helper.rb
|
77
124
|
- test/with_database_test.rb
|
78
|
-
- lib/groupy.rb
|
79
|
-
has_rdoc: true
|
80
125
|
homepage: https://github.com/matthewrudy/groupy
|
81
126
|
licenses: []
|
82
|
-
|
127
|
+
metadata: {}
|
83
128
|
post_install_message:
|
84
|
-
rdoc_options:
|
85
|
-
- --main
|
86
|
-
- README
|
87
|
-
require_paths:
|
129
|
+
rdoc_options:
|
130
|
+
- "--main"
|
131
|
+
- README.md
|
132
|
+
require_paths:
|
88
133
|
- lib
|
89
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
-
|
91
|
-
requirements:
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
92
136
|
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
version: "0"
|
98
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
|
-
requirements:
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
101
141
|
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
|
104
|
-
segments:
|
105
|
-
- 0
|
106
|
-
version: "0"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
107
144
|
requirements: []
|
108
|
-
|
109
145
|
rubyforge_project:
|
110
|
-
rubygems_version:
|
146
|
+
rubygems_version: 2.7.7
|
111
147
|
signing_key:
|
112
|
-
specification_version:
|
113
|
-
summary: Categorise Active Records in nested groups with magical scopes, ? methods,
|
148
|
+
specification_version: 4
|
149
|
+
summary: Categorise Active Records in nested groups with magical scopes, ? methods,
|
150
|
+
and constants.
|
114
151
|
test_files: []
|
115
|
-
|
data/README
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
Groupy
|
2
|
-
=======
|
3
|
-
|
4
|
-
Categorise records into nested groups of values.
|
5
|
-
|
6
|
-
Example
|
7
|
-
=======
|
8
|
-
|
9
|
-
Define our groups
|
10
|
-
|
11
|
-
class Food
|
12
|
-
property :dish, String
|
13
|
-
|
14
|
-
include Groupy
|
15
|
-
groupy :dish do
|
16
|
-
group :healthy do
|
17
|
-
group :fruit do
|
18
|
-
value :apple
|
19
|
-
value :orange
|
20
|
-
end
|
21
|
-
value :rice
|
22
|
-
end
|
23
|
-
|
24
|
-
group :unhealthy do
|
25
|
-
value :fried_egg
|
26
|
-
value :bacon
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
We can then ask a particular food:
|
32
|
-
|
33
|
-
apple.healthy?
|
34
|
-
apple.fruit?
|
35
|
-
apple.apple?
|
36
|
-
|
37
|
-
And we can scope the class by any of these groups
|
38
|
-
|
39
|
-
Food.apples.count
|
40
|
-
Food.fruits.all
|
41
|
-
|
42
|
-
We also get a magic "all_" method
|
43
|
-
|
44
|
-
Food.all_dishes
|
45
|
-
|
46
|
-
You can also tell groupy to add the column name as a suffix
|
47
|
-
|
48
|
-
class Something
|
49
|
-
groupy :size, :suffix => true do
|
50
|
-
value :small
|
51
|
-
value :medium
|
52
|
-
value :large
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
something.small_size?
|
57
|
-
|
58
|
-
Or you may want to store all the values as a conveniently named constant.
|
59
|
-
|
60
|
-
class Something
|
61
|
-
groupy :size, :constants => true do
|
62
|
-
value :small
|
63
|
-
value :medium
|
64
|
-
value :large
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
Something::SMALL
|
69
|
-
Something::MEDIUM
|
70
|
-
Something::LARGE
|
71
|
-
|
72
|
-
Or of course you can do both together
|
73
|
-
|
74
|
-
Something::SMALL_SIZE
|
75
|
-
Something::MEDIUM_SIZE
|
76
|
-
Something::LARGE_SIZE
|
77
|
-
|
78
|
-
Any values will be lowercased and underscored
|
79
|
-
|
80
|
-
class Something
|
81
|
-
groupy :type do
|
82
|
-
value :SomeClass
|
83
|
-
value :"Namespace::KlassName"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
something.some_class?
|
88
|
-
something.namespace_klass_name?
|
89
|
-
|
90
|
-
B00m!
|
91
|
-
|
92
|
-
Copyright (c) 2010 [Matthew Rudy Jacobs], released under the MIT license
|