rich_enums 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eab0bd822f4eb8fa1effa5e5f176b9ac6e415144d88bdc226911f00e856bcc72
4
- data.tar.gz: aa627494d9273b5425070ecb25b3bcb13cfa08ead40d777f4f3219b55c09b846
3
+ metadata.gz: 46447b40cc9c43e26f1543e974579f45b0df6df7cf8f8266228d6938668a8524
4
+ data.tar.gz: bb0ec8a360ed8b6ef49b038fb56bace8b3511a70146667d9a12d426dedba9b10
5
5
  SHA512:
6
- metadata.gz: 7142c1bcd655de15d9fc33dcc6f798ef75416f07735f6d1e841fe29b9955408ef2a1120dff4b4c7ecc33e5e5988246e125c318b879053240ca6f738b15d88448
7
- data.tar.gz: aebc09dea6f653dacc1906c1cbe0fc2740a77acff280ebde356cba4d6c6fe3566cf08a98be801e31ffe46d1d8e8cf85a4bddfa47eefc4c0651865b894024fd88
6
+ metadata.gz: 8680649383f45fedc1b388500b8f5c06dfb34e6450b16e20583d24d6a774b68ddf177eb18025dbb00ccbc4d8c6f297214e183bad7535dc01655e02a1b26297a2
7
+ data.tar.gz: 7c8e3743e48bd6bf09c76b4bcf4f81c8927ce6070f86e02a69d8122de5af7b783c1cd6d5f51f1c4900a1407f2031432441d8727e2a83ebb67dfe5fdc11e44c4e
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .idea
13
+ /*.gem
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rich_enums (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.5.0)
10
+ rake (12.3.3)
11
+ rspec (3.11.0)
12
+ rspec-core (~> 3.11.0)
13
+ rspec-expectations (~> 3.11.0)
14
+ rspec-mocks (~> 3.11.0)
15
+ rspec-core (3.11.0)
16
+ rspec-support (~> 3.11.0)
17
+ rspec-expectations (3.11.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.11.0)
20
+ rspec-mocks (3.11.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.11.0)
23
+ rspec-support (3.11.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ rake (~> 12.0)
30
+ rich_enums!
31
+ rspec (~> 3.0)
32
+
33
+ BUNDLED WITH
34
+ 2.1.4
@@ -1,3 +1,3 @@
1
1
  module RichEnums
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.2'
3
3
  end
data/lib/rich_enums.rb CHANGED
@@ -46,6 +46,9 @@ module RichEnums
46
46
  # extract the Enum options for the column which may be in standard enum hash format or our custom format
47
47
  symbol_value_string = column_symbol_value_string_options.delete(column)
48
48
  # at this point, only the enum options like _prefix etc. are present in the original argument
49
+ options = column_symbol_value_string_options
50
+ # we allow for an option called alt: to allow the users to tag the alternate mapping. Defaults to 'alt_name'
51
+ alt = options.delete(:alt) || 'alt_name'
49
52
 
50
53
  # create two hashes from the provided input - 1 to be used to define the enum and the other for the name map
51
54
  split_hash = symbol_value_string.each_with_object({ for_enum: {}, for_display: {} }) do |(symbol, value_string), obj|
@@ -54,16 +57,16 @@ module RichEnums
54
57
  end
55
58
 
56
59
  # 1. Define the Enum
57
- enum "#{column}": split_hash[:for_enum], **column_symbol_value_string_options
60
+ enum "#{column}": split_hash[:for_enum], **options
58
61
 
59
62
  # 2. Define our custom class method
60
63
  # - 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])
64
+ instance_variable_set("@#{column}_#{alt.pluralize}", split_hash[:for_display])
62
65
  # - the custom method is just a getter for the class instance variable
63
- define_singleton_method("#{column}_names") { instance_variable_get("@#{column}_names") }
66
+ define_singleton_method("#{column}_#{alt.pluralize}") { instance_variable_get("@#{column}_#{alt.pluralize}") }
64
67
 
65
68
  # 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)] }
69
+ define_method("#{column}_#{alt}") { self.class.send("#{column}_#{alt.pluralize}")[send(column.to_s)] }
67
70
  end
68
71
  end
69
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rich_enums
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - harunkumars
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-02-16 00:00:00.000000000 Z
12
+ date: 2022-03-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -20,11 +20,11 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - ".gitignore"
23
- - ".idea/workspace.xml"
24
23
  - ".rspec"
25
24
  - ".travis.yml"
26
25
  - CODE_OF_CONDUCT.md
27
26
  - Gemfile
27
+ - Gemfile.lock
28
28
  - LICENSE.txt
29
29
  - README.md
30
30
  - Rakefile
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  requirements: []
58
- rubygems_version: 3.1.6
58
+ rubygems_version: 3.2.22
59
59
  signing_key:
60
60
  specification_version: 4
61
61
  summary: Provides a rich_enum class method to include String descriptions during Enum
data/.idea/workspace.xml DELETED
@@ -1,96 +0,0 @@
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>