enumeric 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2cc3d4e0e77220a3b572e5bb8e520c19bf4fd2906f4cf40aaf429c7daab56549
4
+ data.tar.gz: 4b4834e72b7c3c0350257c910a1fb108bb1a9c9d176113a1bc43c0843296d318
5
+ SHA512:
6
+ metadata.gz: 744839e83d5715138822ffc8078ed63bea854d2c1f08bd92959a81aeba809c006336e6860af56bb0388cc593669403ee6490210d0c06bc40972a87e0aefb7141
7
+ data.tar.gz: d2bcc8aed5bd12a96ae08400668d54fd89266610c4dde318b2ad31bd9e40e838059ef54552cb67d4c585cb2ebb54f663fe770c17b63b1642b1529361501ed1eb
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # v0.1.0
2
+
3
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in enumeric.gemspec
4
+ gemspec
5
+
6
+ gem "byebug", "~> 11.1"
7
+ gem "rake", "~> 12.0"
8
+ gem "rspec", "~> 3.0"
9
+ gem "rubocop", "~> 1.9"
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ enumeric (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ byebug (11.1.3)
11
+ diff-lcs (1.4.4)
12
+ parallel (1.20.1)
13
+ parser (3.0.0.0)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.0.0)
16
+ rake (12.3.3)
17
+ regexp_parser (2.0.3)
18
+ rexml (3.2.4)
19
+ rspec (3.10.0)
20
+ rspec-core (~> 3.10.0)
21
+ rspec-expectations (~> 3.10.0)
22
+ rspec-mocks (~> 3.10.0)
23
+ rspec-core (3.10.1)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-expectations (3.10.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-mocks (3.10.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-support (3.10.2)
32
+ rubocop (1.9.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 3.0.0.0)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ regexp_parser (>= 1.8, < 3.0)
37
+ rexml
38
+ rubocop-ast (>= 1.2.0, < 2.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (>= 1.4.0, < 3.0)
41
+ rubocop-ast (1.4.1)
42
+ parser (>= 2.7.1.5)
43
+ ruby-progressbar (1.11.0)
44
+ unicode-display_width (2.0.0)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ byebug (~> 11.1)
51
+ enumeric!
52
+ rake (~> 12.0)
53
+ rspec (~> 3.0)
54
+ rubocop (~> 1.9)
55
+
56
+ BUNDLED WITH
57
+ 2.1.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 labocho
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,62 @@
1
+ # Enumeric
2
+
3
+ Enumeric makes you can define "enum" like in other languages on Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'enumeric'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install enumeric
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ module Foo
25
+ # The following code defines constants: Colors, Colors::RED, Colors::GREEN, Colors::BLUE.
26
+ Colors = Enumeric.define(
27
+ RED: 0,
28
+ GREEN: 1,
29
+ BLUE: 2,
30
+ )
31
+
32
+ def hex(color)
33
+ # You can use it in pattern matching
34
+ case color
35
+ in Colors::RED
36
+ "#ff0000"
37
+ in Colors::GREEN
38
+ "#00ff00"
39
+ in Colors::BLUE
40
+ "#0000ff"
41
+ end
42
+ end
43
+ end
44
+
45
+ Foo::Colors.names #=> [:RED, :GREEN, :BLUE]
46
+ Foo::Colors.values #=> [0, 1, 2]
47
+ ```
48
+
49
+ ## Development
50
+
51
+ 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.
52
+
53
+ 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).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/labocho/enumeric.
58
+
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "enumeric"
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/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/enumeric.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/enumeric/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "enumeric"
5
+ spec.version = Enumeric::VERSION
6
+ spec.authors = ["labocho"]
7
+ spec.email = ["labocho@penguinlab.jp"]
8
+
9
+ spec.summary = %q{Creates object like `enum` in other programming language}
10
+ spec.description = %q{Creates object like `enum` in other programming language}
11
+ spec.homepage = "https://github.com/labocho/enumeric"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.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/labocho/enumeric"
19
+ spec.metadata["changelog_uri"] = "https://github.com/labocho/enumeric/blob/master/CHANGELOG.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
@@ -0,0 +1,3 @@
1
+ module Enumeric
2
+ VERSION = "0.1.1"
3
+ end
data/lib/enumeric.rb ADDED
@@ -0,0 +1,57 @@
1
+ require "enumeric/version"
2
+
3
+ module Enumeric
4
+ class Error < StandardError; end
5
+
6
+ module ModuleMethods
7
+ def self.extended(klass)
8
+ class << klass
9
+ attr_reader :name_and_values
10
+ end
11
+ end
12
+
13
+ def include?(value)
14
+ values.include?(value)
15
+ end
16
+
17
+ def name(value)
18
+ names_by_value[value]
19
+ end
20
+
21
+ def names
22
+ @names ||= name_and_values.keys.freeze
23
+ end
24
+
25
+ def values
26
+ @values ||= name_and_values.values.freeze
27
+ end
28
+
29
+ private
30
+ def names_by_value
31
+ @names_by_value ||= name_and_values.invert.freeze
32
+ end
33
+ end
34
+
35
+ module_function
36
+ # @param values [Hash<Symbol, Object>]
37
+ # @return [Module]
38
+ def define(name_and_values)
39
+ name_and_values_frozen = name_and_values.each_with_object({}) {|(name, value), h|
40
+ raise Error, "`#{name.inspect}` is not a Symbol" unless name.is_a?(Symbol)
41
+ raise Error, "`#{value.inspect}` does not have `freeze` method" unless value.respond_to?(:freeze)
42
+
43
+ h[name] = value.freeze
44
+ }.freeze
45
+
46
+ m = Module.new do
47
+ @name_and_values = name_and_values_frozen
48
+ @name_and_values.each do |k, v|
49
+ const_set(k, v)
50
+ end
51
+
52
+ extend ModuleMethods
53
+ end
54
+
55
+ m
56
+ end
57
+ end
data/rubocop.yml ADDED
@@ -0,0 +1,127 @@
1
+ AllCops:
2
+ Exclude:
3
+ - bin/*
4
+ - node_modules/**/*
5
+ NewCops: enable
6
+
7
+ Layout/CaseIndentation:
8
+ EnforcedStyle: end
9
+
10
+ Layout/EndAlignment:
11
+ EnforcedStyleAlignWith: variable
12
+
13
+ Layout/LineLength:
14
+ Enabled: false
15
+
16
+ Layout/EmptyLinesAroundAccessModifier:
17
+ EnforcedStyle: only_before
18
+
19
+ Layout/SpaceInLambdaLiteral:
20
+ EnforcedStyle: require_space
21
+
22
+ Layout/SpaceInsideBlockBraces:
23
+ SpaceBeforeBlockParameters: false
24
+
25
+ Layout/SpaceInsideHashLiteralBraces:
26
+ EnforcedStyle: no_space
27
+
28
+ Metrics/AbcSize:
29
+ Enabled: false
30
+
31
+ Metrics/BlockLength:
32
+ Enabled: false
33
+
34
+ Metrics/ClassLength:
35
+ Enabled: false
36
+
37
+ Metrics/CyclomaticComplexity:
38
+ Enabled: false
39
+
40
+ Metrics/MethodLength:
41
+ Enabled: false
42
+
43
+ Metrics/ModuleLength:
44
+ Enabled: false
45
+
46
+ Metrics/PerceivedComplexity:
47
+ Enabled: false
48
+
49
+ Naming/HeredocDelimiterNaming:
50
+ Enabled: false
51
+
52
+ Naming/MethodParameterName:
53
+ Enabled: false
54
+
55
+ Naming/PredicateName:
56
+ Enabled: false
57
+
58
+ Style/Alias:
59
+ EnforcedStyle: prefer_alias_method
60
+
61
+ Style/AsciiComments:
62
+ Enabled: false
63
+
64
+ Style/BlockDelimiters:
65
+ Enabled: false
66
+
67
+ Style/Documentation:
68
+ Enabled: false
69
+
70
+ Style/EmptyCaseCondition:
71
+ Enabled: false
72
+
73
+ Style/EmptyMethod:
74
+ EnforcedStyle: expanded
75
+
76
+ Style/FrozenStringLiteralComment:
77
+ Enabled: false
78
+
79
+ Style/HashSyntax:
80
+ Exclude:
81
+ - Rakefile
82
+ - "**/*.rake"
83
+
84
+ Style/Lambda:
85
+ EnforcedStyle: literal
86
+
87
+ Style/IfUnlessModifier:
88
+ Enabled: false
89
+
90
+ Style/MultilineBlockChain:
91
+ Enabled: false
92
+
93
+ Style/NumericLiterals:
94
+ Enabled: false
95
+
96
+ Style/NumericPredicate:
97
+ Enabled: false
98
+
99
+ Style/PercentLiteralDelimiters:
100
+ PreferredDelimiters:
101
+ '%i': '()'
102
+ '%w': '()'
103
+ '%r': '()'
104
+
105
+ Style/SpecialGlobalVars:
106
+ Enabled: false
107
+
108
+ Style/StringLiterals:
109
+ EnforcedStyle: double_quotes
110
+
111
+ Style/StringLiteralsInInterpolation:
112
+ EnforcedStyle: double_quotes
113
+
114
+ Style/SymbolArray:
115
+ Enabled: false
116
+
117
+ Style/TrailingCommaInArguments:
118
+ EnforcedStyleForMultiline: consistent_comma
119
+
120
+ Style/TrailingCommaInArrayLiteral:
121
+ EnforcedStyleForMultiline: consistent_comma
122
+
123
+ Style/TrailingCommaInHashLiteral:
124
+ EnforcedStyleForMultiline: consistent_comma
125
+
126
+ Style/ZeroLengthPredicate:
127
+ Enabled: false
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enumeric
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - labocho
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Creates object like `enum` in other programming language
14
+ email:
15
+ - labocho@penguinlab.jp
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - CHANGELOG.md
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/console
30
+ - bin/rspec
31
+ - bin/rubocop
32
+ - bin/setup
33
+ - enumeric.gemspec
34
+ - lib/enumeric.rb
35
+ - lib/enumeric/version.rb
36
+ - rubocop.yml
37
+ homepage: https://github.com/labocho/enumeric
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ homepage_uri: https://github.com/labocho/enumeric
42
+ source_code_uri: https://github.com/labocho/enumeric
43
+ changelog_uri: https://github.com/labocho/enumeric/blob/master/CHANGELOG.md
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.4.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.3.3
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Creates object like `enum` in other programming language
63
+ test_files: []