simple_enum-scopes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +0 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +25 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +5 -0
- data/lib/simple_enum/scopes.rb +4 -0
- data/lib/simple_enum/scopes/extension.rb +26 -0
- data/lib/simple_enum/scopes/version.rb +5 -0
- data/simple_enum-scopes.gemspec +37 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6260427794b078041d8d306988dbab55968e2560
|
4
|
+
data.tar.gz: f47abd547ae8009a168e02b236ed960032be5297
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 83ee3eb9d106f49eab5f6e533e9082a34f1d091538a29dcd83001b0c5d1387c872c554c28af11125f8b10d1cf3ca69722fa1bb7687109f63c5dc412ef314bbcb
|
7
|
+
data.tar.gz: b871ea4563e6c4a765e0ce98e692da975d8294f28b7bca60d8600ecdc32bcf317b482461204b405e9f70af0248b3b1d1fd82a3b740c186d19931eb6dedf3a168
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/Gemfile.lock
|
data/.travis.yml
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Alexandre Overtus
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# SimpleEnum::Scopes
|
2
|
+
|
3
|
+
SimpleEnum::Scopes is extension of SimpleEnum, which brings scopes to ActiveRecord enum attributes.
|
4
|
+
|
5
|
+
It'll avoid to write a bunch of scopes doing basically the same job.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class Object
|
11
|
+
as_enum :state, [:very_bad, :bad, :good, :very_good]
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
Object.states_as(:bad, :very_good)
|
16
|
+
# Object.where(state_cd: [Object.states[:bad], Object.states[:very_good]])
|
17
|
+
|
18
|
+
|
19
|
+
Object.state_between(:bad, :very_good)
|
20
|
+
# Object.where(state_cd: Object.states[:bad]..Object.states[:very_good])
|
21
|
+
```
|
22
|
+
|
23
|
+
## License
|
24
|
+
|
25
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "simple_enum/multiple"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module SimpleEnum
|
2
|
+
module Scopes
|
3
|
+
module Extension
|
4
|
+
def generate_enum_scopes_extension_for enum, accessor
|
5
|
+
define_range_scope_method(enum, accessor)
|
6
|
+
define_multiple_values_scope_method(enum, accessor)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def define_range_scope_method(enum, accessor)
|
12
|
+
singleton_class.send(:define_method, "#{accessor.name}_between") do |min_val, max_val|
|
13
|
+
where(accessor.source => enum[min_val]..enum[max_val])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def define_multiple_values_scope_method(enum, accessor)
|
18
|
+
# arr can be an array of values or a single value
|
19
|
+
singleton_class.send(:define_method, "#{accessor.name.pluralize}_as") do |arr|
|
20
|
+
targeted_values = Array(arr).map(&:to_s) & enum.keys
|
21
|
+
where(accessor.source => targeted_values.map{ |value| enum[value] })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_enum/scopes/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple_enum-scopes"
|
8
|
+
spec.version = SimpleEnum::Scopes::VERSION
|
9
|
+
spec.authors = ["Alexandre Overtus"]
|
10
|
+
spec.email = ["a.overtus@live.be"]
|
11
|
+
spec.summary = %q{Basic scopes enum support for SimpleEnum.}
|
12
|
+
spec.description = %q{SimpleEnum::Scopes is extension of SimpleEnum, which brings scopes to ActiveRecord enum attributes.}
|
13
|
+
spec.homepage = "https://github.com/aovertus/simple_enum-scopes"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.required_ruby_version = ">= 1.9.3"
|
17
|
+
spec.required_rubygems_version = ">= 2.0.0"
|
18
|
+
|
19
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
20
|
+
# delete this section to allow pushing this gem to any host.
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
23
|
+
else
|
24
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_dependency 'simple_enum', '~> 2.3'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'activerecord', '>= 4.0.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 2.14'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_enum-scopes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexandre Overtus
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: simple_enum
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.14'
|
69
|
+
description: SimpleEnum::Scopes is extension of SimpleEnum, which brings scopes to
|
70
|
+
ActiveRecord enum attributes.
|
71
|
+
email:
|
72
|
+
- a.overtus@live.be
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/simple_enum/scopes.rb
|
87
|
+
- lib/simple_enum/scopes/extension.rb
|
88
|
+
- lib/simple_enum/scopes/version.rb
|
89
|
+
- simple_enum-scopes.gemspec
|
90
|
+
homepage: https://github.com/aovertus/simple_enum-scopes
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata:
|
94
|
+
allowed_push_host: https://rubygems.org
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.9.3
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 2.0.0
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Basic scopes enum support for SimpleEnum.
|
115
|
+
test_files: []
|