rich_enums 0.1.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/.gitignore +11 -0
- data/.idea/workspace.xml +96 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rich_enums/version.rb +3 -0
- data/lib/rich_enums.rb +69 -0
- data/rich_enums.gemspec +29 -0
- metadata +63 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: eab0bd822f4eb8fa1effa5e5f176b9ac6e415144d88bdc226911f00e856bcc72
|
|
4
|
+
data.tar.gz: aa627494d9273b5425070ecb25b3bcb13cfa08ead40d777f4f3219b55c09b846
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7142c1bcd655de15d9fc33dcc6f798ef75416f07735f6d1e841fe29b9955408ef2a1120dff4b4c7ecc33e5e5988246e125c318b879053240ca6f738b15d88448
|
|
7
|
+
data.tar.gz: aebc09dea6f653dacc1906c1cbe0fc2740a77acff280ebde356cba4d6c6fe3566cf08a98be801e31ffe46d1d8e8cf85a4bddfa47eefc4c0651865b894024fd88
|
data/.gitignore
ADDED
data/.idea/workspace.xml
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ChangeListManager">
|
|
4
|
+
<list default="true" id="0dad223b-0d0c-4b56-bf84-a35f47fa0bd2" name="Changes" comment="">
|
|
5
|
+
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
|
6
|
+
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
7
|
+
<change afterPath="$PROJECT_DIR$/.rspec" afterDir="false" />
|
|
8
|
+
<change afterPath="$PROJECT_DIR$/.travis.yml" afterDir="false" />
|
|
9
|
+
<change afterPath="$PROJECT_DIR$/CODE_OF_CONDUCT.md" afterDir="false" />
|
|
10
|
+
<change afterPath="$PROJECT_DIR$/Gemfile" afterDir="false" />
|
|
11
|
+
<change afterPath="$PROJECT_DIR$/LICENSE.txt" afterDir="false" />
|
|
12
|
+
<change afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
|
13
|
+
<change afterPath="$PROJECT_DIR$/Rakefile" afterDir="false" />
|
|
14
|
+
<change afterPath="$PROJECT_DIR$/bin/console" afterDir="false" />
|
|
15
|
+
<change afterPath="$PROJECT_DIR$/bin/setup" afterDir="false" />
|
|
16
|
+
<change afterPath="$PROJECT_DIR$/lib/rich_enums.rb" afterDir="false" />
|
|
17
|
+
<change afterPath="$PROJECT_DIR$/lib/rich_enums/version.rb" afterDir="false" />
|
|
18
|
+
<change afterPath="$PROJECT_DIR$/rich_enums.gemspec" afterDir="false" />
|
|
19
|
+
<change afterPath="$PROJECT_DIR$/spec/rich_enums_spec.rb" afterDir="false" />
|
|
20
|
+
<change afterPath="$PROJECT_DIR$/spec/spec_helper.rb" afterDir="false" />
|
|
21
|
+
</list>
|
|
22
|
+
<option name="SHOW_DIALOG" value="false" />
|
|
23
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
24
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
25
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
26
|
+
</component>
|
|
27
|
+
<component name="Git.Settings">
|
|
28
|
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
29
|
+
</component>
|
|
30
|
+
<component name="MarkdownSettingsMigration">
|
|
31
|
+
<option name="stateVersion" value="1" />
|
|
32
|
+
</component>
|
|
33
|
+
<component name="ProjectId" id="25AxdAyVOo0qOEcwr5Ba2ImunPf" />
|
|
34
|
+
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
|
35
|
+
<component name="ProjectViewState">
|
|
36
|
+
<option name="hideEmptyMiddlePackages" value="true" />
|
|
37
|
+
<option name="showLibraryContents" value="true" />
|
|
38
|
+
</component>
|
|
39
|
+
<component name="PropertiesComponent">
|
|
40
|
+
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
|
41
|
+
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
|
42
|
+
<property name="nodejs_package_manager_path" value="npm" />
|
|
43
|
+
<property name="settings.editor.selected.configurable" value="configurable.group.tools" />
|
|
44
|
+
</component>
|
|
45
|
+
<component name="RunAnythingCache">
|
|
46
|
+
<option name="myCommands">
|
|
47
|
+
<command value="gem install rich_enums" />
|
|
48
|
+
</option>
|
|
49
|
+
</component>
|
|
50
|
+
<component name="RunManager">
|
|
51
|
+
<configuration name="IRB: rich_enums" type="IrbRunConfigurationType" factoryName="IRB console" temporary="true">
|
|
52
|
+
<module name="rich_enums" />
|
|
53
|
+
<IRB_RUN_CONFIG NAME="RUBY_ARGS" VALUE="" />
|
|
54
|
+
<IRB_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$" />
|
|
55
|
+
<IRB_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
|
|
56
|
+
<IRB_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
|
|
57
|
+
<IRB_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
|
|
58
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" BUNDLE_MODE="AUTO" bundleExecEnabled="true" />
|
|
59
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
|
60
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" track_test_folders="true" runner="rcov" ENABLE_BRANCH_COVERAGE="true" ENABLE_FORKED_COVERAGE="true">
|
|
61
|
+
<COVERAGE_PATTERN ENABLED="true">
|
|
62
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
|
63
|
+
</COVERAGE_PATTERN>
|
|
64
|
+
</EXTENSION>
|
|
65
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.rails.run.RailsRunConfigurationExtension" SCRATCH_USE_RAILS_RUNNER="false" />
|
|
66
|
+
<IRB_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$USER_HOME$/.rbenv/versions/2.7.4/bin/irb" />
|
|
67
|
+
<IRB_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
|
|
68
|
+
<IRB_RUN_CONFIG NAME="CONSOLE_TYPE" VALUE="IRB" />
|
|
69
|
+
<method v="2" />
|
|
70
|
+
</configuration>
|
|
71
|
+
<recent_temporary>
|
|
72
|
+
<list>
|
|
73
|
+
<item itemvalue="Ruby Console.IRB: rich_enums" />
|
|
74
|
+
</list>
|
|
75
|
+
</recent_temporary>
|
|
76
|
+
</component>
|
|
77
|
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
78
|
+
<component name="SpringUtil" SPRING_PRE_LOADER_OPTION="true" RAKE_SPRING_PRE_LOADER_OPTION="true" RAILS_SPRING_PRE_LOADER_OPTION="true" />
|
|
79
|
+
<component name="TaskManager">
|
|
80
|
+
<task active="true" id="Default" summary="Default task">
|
|
81
|
+
<changelist id="0dad223b-0d0c-4b56-bf84-a35f47fa0bd2" name="Changes" comment="" />
|
|
82
|
+
<created>1644983778288</created>
|
|
83
|
+
<option name="number" value="Default" />
|
|
84
|
+
<option name="presentableId" value="Default" />
|
|
85
|
+
<updated>1644983778288</updated>
|
|
86
|
+
<workItem from="1644983779909" duration="2058000" />
|
|
87
|
+
</task>
|
|
88
|
+
<servers />
|
|
89
|
+
</component>
|
|
90
|
+
<component name="TypeScriptGeneratedFilesManager">
|
|
91
|
+
<option name="version" value="3" />
|
|
92
|
+
</component>
|
|
93
|
+
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
|
94
|
+
<SUITE FILE_PATH="coverage/rich_enums@IRB__rich_enums.rcov" NAME="IRB: rich_enums Coverage Results" MODIFIED="1644985416414" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="rcov" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" MODULE_NAME="rich_enums" />
|
|
95
|
+
</component>
|
|
96
|
+
</project>
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 TODO: Write your name
|
|
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,44 @@
|
|
|
1
|
+
# RichEnums
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rich_enums`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'rich_enums'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle install
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install rich_enums
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rich_enums. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rich_enums/blob/master/CODE_OF_CONDUCT.md).
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
41
|
+
|
|
42
|
+
## Code of Conduct
|
|
43
|
+
|
|
44
|
+
Everyone interacting in the RichEnums project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rich_enums/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "rich_enums"
|
|
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(__FILE__)
|
data/bin/setup
ADDED
data/lib/rich_enums.rb
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require "rich_enums/version"
|
|
2
|
+
|
|
3
|
+
module RichEnums
|
|
4
|
+
class Error < StandardError; end
|
|
5
|
+
|
|
6
|
+
def self.included(base)
|
|
7
|
+
base.extend ClassMethods
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
module ClassMethods
|
|
11
|
+
def rich_enum(column_symbol_value_string_options)
|
|
12
|
+
# rich_enum column1: { symbol1: [value1, string1], ... }, **options
|
|
13
|
+
# will transform to
|
|
14
|
+
# 1. enum column1: { symbol1: value1, ...}, to define the enums along with any options provided
|
|
15
|
+
# and
|
|
16
|
+
# 2. Class method "column1_names" that will map the enum values to the full String description
|
|
17
|
+
# and can be accessed by ClassName.<column>_names which will return a hash like { symbol1: string1, symbol2: string2 ...}
|
|
18
|
+
# e.g.
|
|
19
|
+
# class Enrollment
|
|
20
|
+
# include EnumMappable
|
|
21
|
+
# rich_enum learner_payment_path: {
|
|
22
|
+
# greenfig_online: [10, 'GreenFig Online'],
|
|
23
|
+
# partner: [20, 'Partner'],
|
|
24
|
+
# partner_online: [30, 'Partner Online'],
|
|
25
|
+
# po_check: [40, 'P.O. / Check'],
|
|
26
|
+
# other: [100, 'Other']
|
|
27
|
+
# }, _prefix: true
|
|
28
|
+
# end
|
|
29
|
+
# will result in i. enum definitions for learner_payment_path and
|
|
30
|
+
# ii. a class method called learner_payment_path_names
|
|
31
|
+
# Calling learner_payment_path_names returns
|
|
32
|
+
# {"greenfig_online"=>"GreenFig Online", "partner"=>"Partner", "partner_online"=>"Partner Online",
|
|
33
|
+
# "po_check"=>"P.O. / Check", "other"=>"Other"}
|
|
34
|
+
# 3. Instance method "column1_name" will return the String associated with the enum value
|
|
35
|
+
# e = Enrollment.new
|
|
36
|
+
# e.learner_payment_path_po_check! -> normal enum method to update the object with enum value
|
|
37
|
+
# e.learner_payment_path --> :po_check -> provides the symbol associated with enum value
|
|
38
|
+
# e.learner_payment_path_name --> "P.O. / Check" -> our custom method that returns the string/description
|
|
39
|
+
# TODO: explore if enum options in Array format instead of Hash format will need to be handled
|
|
40
|
+
|
|
41
|
+
raise 'rich_enum error' unless column_symbol_value_string_options.keys.count.positive?
|
|
42
|
+
|
|
43
|
+
# extract out the column
|
|
44
|
+
column = column_symbol_value_string_options.keys.first
|
|
45
|
+
|
|
46
|
+
# extract the Enum options for the column which may be in standard enum hash format or our custom format
|
|
47
|
+
symbol_value_string = column_symbol_value_string_options.delete(column)
|
|
48
|
+
# at this point, only the enum options like _prefix etc. are present in the original argument
|
|
49
|
+
|
|
50
|
+
# create two hashes from the provided input - 1 to be used to define the enum and the other for the name map
|
|
51
|
+
split_hash = symbol_value_string.each_with_object({ for_enum: {}, for_display: {} }) do |(symbol, value_string), obj|
|
|
52
|
+
obj[:for_enum][symbol] = value_string.is_a?(Array) ? value_string.first : value_string
|
|
53
|
+
obj[:for_display][symbol.to_s] = value_string.is_a?(Array) ? value_string.second : symbol.to_s
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# 1. Define the Enum
|
|
57
|
+
enum "#{column}": split_hash[:for_enum], **column_symbol_value_string_options
|
|
58
|
+
|
|
59
|
+
# 2. Define our custom class method
|
|
60
|
+
# - the data to be returned by our custom method is available os a class instance variable
|
|
61
|
+
instance_variable_set("@#{column}_names", split_hash[:for_display])
|
|
62
|
+
# - the custom method is just a getter for the class instance variable
|
|
63
|
+
define_singleton_method("#{column}_names") { instance_variable_get("@#{column}_names") }
|
|
64
|
+
|
|
65
|
+
# 3. Define our custom instance method to show the String associated with the enum value
|
|
66
|
+
define_method("#{column}_name") { self.class.send("#{column}_names")[send(column.to_s)] }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
data/rich_enums.gemspec
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative 'lib/rich_enums/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = 'rich_enums'
|
|
5
|
+
spec.version = RichEnums::VERSION
|
|
6
|
+
spec.authors = %w[harunkumars rtdp]
|
|
7
|
+
spec.email = %w[harun@betacraft.io rtdp@betacraft.io]
|
|
8
|
+
|
|
9
|
+
spec.summary = 'Provides a rich_enum class method to include String descriptions during Enum definitions'
|
|
10
|
+
# spec.description = 'TODO: Write a longer description or delete this line.'
|
|
11
|
+
spec.homepage = 'https://github.com/betacraft/rich_enums'
|
|
12
|
+
spec.license = 'MIT'
|
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
|
14
|
+
|
|
15
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/betacraft/rich_enums'
|
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/betacraft/rich_enums/README.md'
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = 'exe'
|
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ['lib']
|
|
29
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rich_enums
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- harunkumars
|
|
8
|
+
- rtdp
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: exe
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2022-02-16 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description:
|
|
15
|
+
email:
|
|
16
|
+
- harun@betacraft.io
|
|
17
|
+
- rtdp@betacraft.io
|
|
18
|
+
executables: []
|
|
19
|
+
extensions: []
|
|
20
|
+
extra_rdoc_files: []
|
|
21
|
+
files:
|
|
22
|
+
- ".gitignore"
|
|
23
|
+
- ".idea/workspace.xml"
|
|
24
|
+
- ".rspec"
|
|
25
|
+
- ".travis.yml"
|
|
26
|
+
- CODE_OF_CONDUCT.md
|
|
27
|
+
- Gemfile
|
|
28
|
+
- LICENSE.txt
|
|
29
|
+
- README.md
|
|
30
|
+
- Rakefile
|
|
31
|
+
- bin/console
|
|
32
|
+
- bin/setup
|
|
33
|
+
- lib/rich_enums.rb
|
|
34
|
+
- lib/rich_enums/version.rb
|
|
35
|
+
- rich_enums.gemspec
|
|
36
|
+
homepage: https://github.com/betacraft/rich_enums
|
|
37
|
+
licenses:
|
|
38
|
+
- MIT
|
|
39
|
+
metadata:
|
|
40
|
+
homepage_uri: https://github.com/betacraft/rich_enums
|
|
41
|
+
source_code_uri: https://github.com/betacraft/rich_enums
|
|
42
|
+
changelog_uri: https://github.com/betacraft/rich_enums/README.md
|
|
43
|
+
post_install_message:
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: 2.3.0
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '0'
|
|
57
|
+
requirements: []
|
|
58
|
+
rubygems_version: 3.1.6
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: Provides a rich_enum class method to include String descriptions during Enum
|
|
62
|
+
definitions
|
|
63
|
+
test_files: []
|