swifter_enum 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +269 -0
- data/Rakefile +15 -0
- data/lib/swifter_enum/base.rb +33 -0
- data/lib/swifter_enum/generators/enum/enum_generator.rb +13 -0
- data/lib/swifter_enum/generators/enum/templates/enum.rb.tt +19 -0
- data/lib/swifter_enum/railtie.rb +15 -0
- data/lib/swifter_enum/swifter_enum.rb +49 -0
- data/lib/swifter_enum/swifter_enum_validator.rb +17 -0
- data/lib/swifter_enum/version.rb +5 -0
- data/lib/swifter_enum.rb +10 -0
- data/sig/swifter_enum.rbs +4 -0
- data/swifter_enum.gemspec +45 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4faeac3f2e6714d5af882726817712536924044c725a0aa252de4f0e89072f43
|
4
|
+
data.tar.gz: 5c818c9815c9e4e5165475260ffd42b503b815ca7eb92307ea98a703b8c2a933
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 813389dc72d261ac9aa903484829009f8853ce4a0e6c017f8529996f2816858bdd13b4e5294f10b6a1c6dd93d3c1341e5c4e9a651f6b14712bf8fdddf49255a9
|
7
|
+
data.tar.gz: 39941760574f2ac9438ab61537273ed593e0a813200169dcdb68f863251992b8973aada7f3b094ef0aeb6182e7f87fe5bd30d61303bbd643e5bb0313a7f0e1c5
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Rob Jonson
|
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,269 @@
|
|
1
|
+
# SwifterEnum
|
2
|
+
|
3
|
+
SwifterEnum is a Ruby gem for creating enumerated types (enums) in Ruby on Rails applications.
|
4
|
+
It is inspired by Swift's enums, and allows for more expressive and feature-rich enums in your models.
|
5
|
+
|
6
|
+
Rather than simply having a key/value, enums are Classes, and can have defined methods.
|
7
|
+
|
8
|
+
so - after defining
|
9
|
+
|
10
|
+
class Video < ApplicationRecord
|
11
|
+
swifter_enum :camera, CameraEnum
|
12
|
+
end
|
13
|
+
|
14
|
+
you can then define and access methods on your enum like
|
15
|
+
|
16
|
+
`video.camera.icon`
|
17
|
+
or `video.camera.default_exposure`
|
18
|
+
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
gem 'swifter_enum'
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
bundle install
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
### Overview
|
33
|
+
|
34
|
+
|
35
|
+
SwifterEnums act like a normal Rails enum - except that instead of returning symbol values, they return an instance of your selected class
|
36
|
+
|
37
|
+
We have a Video ActiveModel with an enum defined by
|
38
|
+
|
39
|
+
class Video < ApplicationRecord
|
40
|
+
swifter_enum :camera, CameraEnum
|
41
|
+
end
|
42
|
+
|
43
|
+
CameraEnum is a class like the following
|
44
|
+
|
45
|
+
class CameraEnum < SwifterEnum::Base
|
46
|
+
def self.values
|
47
|
+
{ videographer: 0, handcam: 1 }.freeze
|
48
|
+
end
|
49
|
+
|
50
|
+
def icon
|
51
|
+
case @value
|
52
|
+
when :videographer
|
53
|
+
"icons/video-camera"
|
54
|
+
when :handcam
|
55
|
+
"icons/hand-stop"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
This provides a richer approach to enums:
|
61
|
+
|
62
|
+
v = Video.first
|
63
|
+
v.camera => #<CameraEnum:0x0000000134c7c290 @value=:handcam>
|
64
|
+
v.camera.value => :handcam
|
65
|
+
|
66
|
+
#you can set values directly
|
67
|
+
v.camera = :videographer
|
68
|
+
v.camera => #<CameraEnum:0x000000013385f078 @value=:videographer>
|
69
|
+
|
70
|
+
#the purpose of this gem is that you can now define and access methods on the CameraEnum
|
71
|
+
v.camera.icon => "icons/video-camera"
|
72
|
+
|
73
|
+
|
74
|
+
### Using Enums in ActiveRecord Models
|
75
|
+
|
76
|
+
To use an enum in an ActiveRecord model, use the `swifter_enum` class method provided by the gem in exactly the same way that you would normally use `enum`
|
77
|
+
|
78
|
+
Example:
|
79
|
+
|
80
|
+
class Video < ApplicationRecord
|
81
|
+
swifter_enum :camera, CameraEnum
|
82
|
+
|
83
|
+
#optional validation
|
84
|
+
validates :camera, swifter_enum: true
|
85
|
+
end
|
86
|
+
|
87
|
+
Models are by convention stored in `/models/swifter_enum/your_model_enum.rb`
|
88
|
+
|
89
|
+
|
90
|
+
### Enum Class
|
91
|
+
|
92
|
+
Example:
|
93
|
+
|
94
|
+
class CameraEnum < SwifterEnum::Base
|
95
|
+
def self.values
|
96
|
+
{ videographer: 0, handcam: 1 }.freeze
|
97
|
+
end
|
98
|
+
|
99
|
+
def icon
|
100
|
+
case @value
|
101
|
+
when :videographer
|
102
|
+
"icons/video-camera"
|
103
|
+
when :handcam
|
104
|
+
"icons/hand-stop"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
The only requirements for your enum class are
|
110
|
+
|
111
|
+
* Inherit from SwifterEnum::Base
|
112
|
+
* Define self.values which returns a hash of `{symbol: Integer}`
|
113
|
+
|
114
|
+
You can then add whatever methods are useful to you.
|
115
|
+
|
116
|
+
### Migrating an existing enum
|
117
|
+
|
118
|
+
let's say you have an existing enum
|
119
|
+
|
120
|
+
enum :album_status, {
|
121
|
+
waiting_for_footage: 0,
|
122
|
+
waiting_for_upload: 10,
|
123
|
+
uploading: 20,
|
124
|
+
processing_preview: 24,
|
125
|
+
delivered_preview: 26,
|
126
|
+
processing_paid: 30,
|
127
|
+
delivered_paid: 50,
|
128
|
+
processing_failed: 60
|
129
|
+
}, prefix: true
|
130
|
+
|
131
|
+
run the generator to create an appropriate enum class
|
132
|
+
|
133
|
+
`rails g swifter_enum:enum AlbumStatus`
|
134
|
+
|
135
|
+
Insert the values of your enum into `models/swifter_enum_album_status_enum.rb`
|
136
|
+
|
137
|
+
class AlbumStatusEnum < SwifterEnum::Base
|
138
|
+
def self.values
|
139
|
+
{
|
140
|
+
waiting_for_footage: 0,
|
141
|
+
waiting_for_upload: 10,
|
142
|
+
uploading: 20,
|
143
|
+
processing_preview: 24,
|
144
|
+
delivered_preview: 26,
|
145
|
+
processing_paid: 30,
|
146
|
+
delivered_paid: 50,
|
147
|
+
processing_failed: 60
|
148
|
+
}.freeze
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
Now replace the definition in your model file with
|
153
|
+
|
154
|
+
swifter_enum :album_status, AlbumStatusEnum, prefix: true
|
155
|
+
|
156
|
+
Optionally, add
|
157
|
+
|
158
|
+
validates :album_status, swifter_enum: true
|
159
|
+
|
160
|
+
Run your tests and fix any issues.
|
161
|
+
|
162
|
+
The main change is where you were assuming that your enum would return a string value.
|
163
|
+
|
164
|
+
Typically, in my code, I would convert these to a symbol before comparing. So, I have to remove `album_status.to_sym` calls.
|
165
|
+
|
166
|
+
Now I can use `album_status.value` to get a symbol value,
|
167
|
+
|
168
|
+
album_status.value => :uploading
|
169
|
+
|
170
|
+
or if I'm doing a comparison - I can just use `album_status`.
|
171
|
+
|
172
|
+
if album_status == :uploading {} #works as expected
|
173
|
+
if album_status == 'uploading' {} #also works as expected
|
174
|
+
|
175
|
+
|
176
|
+
Now I'm ready to use my enum class by defining new methods.
|
177
|
+
|
178
|
+
For example
|
179
|
+
|
180
|
+
class AlbumStatusEnum < SwifterEnum::Base
|
181
|
+
|
182
|
+
#values set as above
|
183
|
+
|
184
|
+
def delivered?
|
185
|
+
[:delivered_paid, :delivered_preview].include? self.value
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
which allows me to use `model.album_status.delivered?`
|
191
|
+
|
192
|
+
|
193
|
+
### Generator Usage
|
194
|
+
|
195
|
+
SwifterEnum provides a Rails generator to easily create new enum classes. To generate an enum, use the following command:
|
196
|
+
|
197
|
+
rails g swifter_enum:enum [EnumName]
|
198
|
+
|
199
|
+
Replace `[EnumName]` with the desired name for your enum. This will create a new enum file in the `app/models` directory.
|
200
|
+
|
201
|
+
For example, to create a `CameraEnum`, run:
|
202
|
+
|
203
|
+
rails g swifter_enum:enum Camera
|
204
|
+
|
205
|
+
This command will generate a file `app/models/swifter_enum/camera_enum.rb` with the following structure:
|
206
|
+
|
207
|
+
class CameraEnum < SwifterEnum::Base
|
208
|
+
def self.values
|
209
|
+
# Insert your values here. e.g. { foo: 1, bar: 2 }.freeze
|
210
|
+
{ }.freeze
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
After generating your enum, you can add your specific enum values and use it in your ActiveRecord models.
|
215
|
+
|
216
|
+
### Translation and Display
|
217
|
+
|
218
|
+
SwifterEnum supports i18n out of the box. Define translations in your locale files, and use the `.t` method on your enum instances to get the translated string.
|
219
|
+
|
220
|
+
Locale file example (`config/locales/en.yml`):
|
221
|
+
|
222
|
+
en:
|
223
|
+
swifter_enum:
|
224
|
+
enums:
|
225
|
+
camera_enum:
|
226
|
+
videographer: "Videographer"
|
227
|
+
handcam: "Handheld Camera"
|
228
|
+
|
229
|
+
#example usage
|
230
|
+
v.camera.t => "Videographer"
|
231
|
+
|
232
|
+
### Raw Value Escape Hatch
|
233
|
+
|
234
|
+
SwifterEnum is built on top of the normal Rails enum functionality.
|
235
|
+
|
236
|
+
If you're using a framework that needs to access this (Like Administrate), then you can use the `[name]_raw` method
|
237
|
+
|
238
|
+
This also provides the keys method for select forms, so form builders should work (though the label will be `[name]_raw` rather than `[name]`)
|
239
|
+
|
240
|
+
So, if you define Video.camera as a CameraEnum, then Video.camera_raw returns the standard Rails enum which lies beneath.
|
241
|
+
|
242
|
+
Example:
|
243
|
+
|
244
|
+
v.camera => #<CameraEnum:0x000000013385f078 @value=:videographer>
|
245
|
+
|
246
|
+
# Accessing the raw value
|
247
|
+
v.camera_raw => "videographer"
|
248
|
+
|
249
|
+
# Setting the raw value
|
250
|
+
v.camera_raw = "handcam" #or =:handcam
|
251
|
+
v.camera = => #<CameraEnum:0x000000016f7223e0 @value=:handcam>
|
252
|
+
|
253
|
+
v.camera_raw = 0
|
254
|
+
v.camera = => #<CameraEnum:0x000000016f7223e0 @value=:videographer>
|
255
|
+
|
256
|
+
# Getting the mapping
|
257
|
+
Video.camera_raws # => { videographer: 0, handcam: 1 }
|
258
|
+
|
259
|
+
so, for my Administrate dashboard, I would use
|
260
|
+
|
261
|
+
album_status_raw: Field::Select.with_options(searchable: false, collection: ->(field) { field.resource.class.send(field.attribute.to_s.pluralize).keys }),
|
262
|
+
|
263
|
+
## More Info
|
264
|
+
|
265
|
+
See the tests folder for more examples of usage.
|
266
|
+
|
267
|
+
## Contributing
|
268
|
+
|
269
|
+
Bug reports and pull requests are welcome
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rake/testtask"
|
4
|
+
require "bundler/gem_tasks"
|
5
|
+
require "standard/rake"
|
6
|
+
|
7
|
+
# run rake standard:fix to standardise
|
8
|
+
|
9
|
+
Rake::TestTask.new do |t|
|
10
|
+
t.libs << "test"
|
11
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
task default: [:standard, :test]
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module SwifterEnum
|
2
|
+
class Base
|
3
|
+
attr_reader :value
|
4
|
+
|
5
|
+
def self.values
|
6
|
+
{}
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(value)
|
10
|
+
@value = value&.to_sym
|
11
|
+
end
|
12
|
+
|
13
|
+
def ==(other)
|
14
|
+
if other.is_a?(Symbol) || other.is_a?(String)
|
15
|
+
value.to_s == other.to_s
|
16
|
+
else
|
17
|
+
other.instance_of?(self.class) && value == other.value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def t
|
22
|
+
I18n.t("swifter_enum.#{self.class.name.demodulize.underscore}.#{@value}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
@value
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.all
|
30
|
+
values.keys.map { |value| new(value) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "rails/generators/base"
|
2
|
+
|
3
|
+
module SwifterEnum
|
4
|
+
module Generators
|
5
|
+
class EnumGenerator < Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
|
8
|
+
def create_enum_file
|
9
|
+
template "enum.rb.tt", File.join("app/models/swifter_enum", class_path, "#{file_name}_enum.rb")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Add this to your ActiveRecord model with:
|
2
|
+
# swifter_enum :<%= file_name %>, <%= class_name %>Enum
|
3
|
+
|
4
|
+
class <%= class_name %>Enum < SwifterEnum::Base
|
5
|
+
|
6
|
+
def self.values
|
7
|
+
# Insert your values here as you would for a normal enum
|
8
|
+
# { foo: 1, bar: 2 }.freeze
|
9
|
+
|
10
|
+
{ }.freeze
|
11
|
+
end
|
12
|
+
|
13
|
+
# you can now define methods on the enum
|
14
|
+
# this would allow you to access YourModel.<%= file_name %>.squared
|
15
|
+
#def squared
|
16
|
+
# @value * @value
|
17
|
+
#end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SwifterEnum
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
# ActiveRecord integration
|
4
|
+
initializer "swifter_enum.active_record" do
|
5
|
+
ActiveSupport.on_load(:active_record) do
|
6
|
+
include SwifterEnum
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# adding autoload paths
|
11
|
+
initializer "swifter_enum.add_autoload_paths", before: :set_autoload_paths do |app|
|
12
|
+
app.config.autoload_paths += Dir[Rails.root.join("app", "models", "swifter_enum")]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module SwifterEnum
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def swifter_enum(enum_name, enum_klass, enum_options = {})
|
8
|
+
# Define the enum using values from the enum class
|
9
|
+
enum(enum_name => enum_klass.values, **enum_options)
|
10
|
+
|
11
|
+
# Define getter method
|
12
|
+
define_method(enum_name) do
|
13
|
+
enum_klass.new(read_attribute(enum_name))
|
14
|
+
end
|
15
|
+
|
16
|
+
# Define setter method
|
17
|
+
define_method(:"#{enum_name}=") do |new_value|
|
18
|
+
if new_value.is_a?(enum_klass)
|
19
|
+
super(new_value.value)
|
20
|
+
else
|
21
|
+
super(new_value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Raw setter/getter allow escape valve for e.g. administrate
|
26
|
+
# So, if your swifter_enum is
|
27
|
+
# swifter_enum :camera, CameraKind
|
28
|
+
# you can get and set camera_raw with standard enum values
|
29
|
+
# and you can get the mapping with YourClass.camera_raws
|
30
|
+
# This allows you to use andminstrate as an example on camera_raw and expect form selects to work normally.
|
31
|
+
|
32
|
+
# Define raw getter method
|
33
|
+
define_method(:"#{enum_name}_raw") do
|
34
|
+
read_attribute(enum_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Define raw setter method
|
38
|
+
define_method(:"#{enum_name}_raw=") do |new_value|
|
39
|
+
write_attribute(enum_name, new_value)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Define class method to fetch the keys
|
43
|
+
# Rails returns string keys, so copy that
|
44
|
+
define_singleton_method(:"#{enum_name}_raws") do
|
45
|
+
enum_klass.values.transform_keys(&:to_s)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "active_model"
|
2
|
+
|
3
|
+
module SwifterEnum
|
4
|
+
class SwifterEnumValidator < ActiveModel::EachValidator
|
5
|
+
def validate_each(record, attribute, a_value)
|
6
|
+
return if options[:allow_nil] && a_value.nil?
|
7
|
+
|
8
|
+
if !a_value.is_a?(SwifterEnum::Base) || a_value.instance_of?(SwifterEnum::Base)
|
9
|
+
record.errors.add(attribute, "#{a_value.value} is not a valid subclass of SwifterEnum")
|
10
|
+
end
|
11
|
+
|
12
|
+
unless a_value.class.values.key?(a_value.value)
|
13
|
+
record.errors.add(attribute, "#{a_value.value} is not a valid #{attribute} type")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/swifter_enum.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "swifter_enum/base"
|
4
|
+
require "swifter_enum/swifter_enum"
|
5
|
+
require "swifter_enum/swifter_enum_validator"
|
6
|
+
require "swifter_enum/railtie" if defined?(Rails)
|
7
|
+
|
8
|
+
if defined?(Rails::Generators) && Rails.env.development?
|
9
|
+
require "swifter_enum/generators/enum/enum_generator"
|
10
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/swifter_enum/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "swifter_enum"
|
7
|
+
spec.version = SwifterEnum::VERSION
|
8
|
+
spec.authors = ["Rob Jonson"]
|
9
|
+
spec.email = ["rob@hobbyistsoftware.com"]
|
10
|
+
|
11
|
+
spec.summary = "Active Record enum that uses a class, so you can add methods."
|
12
|
+
spec.description = "Simple enum for active record that takes inspiration from Swift's enums to allow you to add logic to your enum definition. This is easy to drop-in as a replacement for regular rails enums, with minimal changes required. Once you switch, then you can easily extend your enums with methods."
|
13
|
+
spec.homepage = "https://github.com/ConfusedVorlon/SwifterEnum"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
#I'm using 3.2 and above. If you're willing/able to test on lower rubies, then please let me know and feel free to change this.
|
17
|
+
spec.required_ruby_version = ">= 3.2.0"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/ConfusedVorlon/SwifterEnum"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/ConfusedVorlon/SwifterEnum"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(File.expand_path(f) == __FILE__) ||
|
28
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_dependency "activerecord", "~> 7.0"
|
36
|
+
spec.add_dependency "activesupport", "~> 7.0"
|
37
|
+
spec.add_dependency "activemodel", "~> 7.0"
|
38
|
+
|
39
|
+
# Specify development dependencies
|
40
|
+
spec.add_development_dependency "sqlite3", "~> 1.4" # For using SQL
|
41
|
+
spec.add_development_dependency "minitest", "~> 5.22"
|
42
|
+
|
43
|
+
# For more information and examples about making a new gem, check out our
|
44
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swifter_enum
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Jonson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '7.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '7.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activemodel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '7.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '7.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.22'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.22'
|
83
|
+
description: Simple enum for active record that takes inspiration from Swift's enums
|
84
|
+
to allow you to add logic to your enum definition. This is easy to drop-in as a
|
85
|
+
replacement for regular rails enums, with minimal changes required. Once you switch,
|
86
|
+
then you can easily extend your enums with methods.
|
87
|
+
email:
|
88
|
+
- rob@hobbyistsoftware.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".standard.yml"
|
94
|
+
- CHANGELOG.md
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/swifter_enum.rb
|
99
|
+
- lib/swifter_enum/base.rb
|
100
|
+
- lib/swifter_enum/generators/enum/enum_generator.rb
|
101
|
+
- lib/swifter_enum/generators/enum/templates/enum.rb.tt
|
102
|
+
- lib/swifter_enum/railtie.rb
|
103
|
+
- lib/swifter_enum/swifter_enum.rb
|
104
|
+
- lib/swifter_enum/swifter_enum_validator.rb
|
105
|
+
- lib/swifter_enum/version.rb
|
106
|
+
- sig/swifter_enum.rbs
|
107
|
+
- swifter_enum.gemspec
|
108
|
+
homepage: https://github.com/ConfusedVorlon/SwifterEnum
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata:
|
112
|
+
homepage_uri: https://github.com/ConfusedVorlon/SwifterEnum
|
113
|
+
source_code_uri: https://github.com/ConfusedVorlon/SwifterEnum
|
114
|
+
changelog_uri: https://github.com/ConfusedVorlon/SwifterEnum
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 3.2.0
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubygems_version: 3.5.6
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Active Record enum that uses a class, so you can add methods.
|
134
|
+
test_files: []
|