yae 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0b08e3c607e151e0ae96ed463c71557a083ae4e215439f66987cf29baeb2f1c7
4
+ data.tar.gz: 0d7e7febabbe7aa0eb8881e3816a5be81a289f597e8d012d1d919e2a7bfbe9f7
5
+ SHA512:
6
+ metadata.gz: 6da9471e3743883cc584f51e55ea2c5b0f3f7b7c499b738b576ce161ef1bca3bd5b926943e8a31475ccc5c5aa293a26f756c07f470211ddd941378cba86f6bac
7
+ data.tar.gz: cc04e3adc32e9765f70d5d112a4acdab8d77afa7f7508c04b79cb0f6defd6253fb8ed4df28b1ce2034802243cfadf85e55f3f4f71868f7f5c3dd79445ccab788
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Stephen Ierodiaconou
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,40 @@
1
+ # Yae::Enum
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/yae`. 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 'yae'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install yae
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 test` 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]/yae.
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).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "standard/rake"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList["test/**/*_test.rb"]
9
+ end
10
+
11
+ task default: :test
data/lib/yae/enum.rb ADDED
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ # Implements an enum
6
+ module Yae
7
+ class Enum
8
+ class << self
9
+ extend ::Forwardable
10
+
11
+ def inherited(subclass)
12
+ subclass.instance_variable_set(:@enum_store, @enum_store.clone)
13
+ super
14
+ end
15
+
16
+ # Define an entry in the enum
17
+ def define(key, value)
18
+ @enum_store = {} unless enum_store
19
+ enum_store[key] = value
20
+ end
21
+
22
+ # Get the enum value
23
+ def get(key, raises: true)
24
+ return unless enum_store
25
+ raises ? enum_store.fetch(key) : enum_store.fetch(key, nil)
26
+ end
27
+
28
+ # Get multiple keys at once
29
+ def get_multiple(*keys, raises: true)
30
+ keys.map { |key| get(key, raises: raises) }
31
+ end
32
+
33
+ # Check if value is used in enum
34
+ def include?(value)
35
+ !!enum_store&.has_value?(value)
36
+ end
37
+
38
+ # Delegate enumerable methods to underlying hash
39
+ def_delegators :@enum_store,
40
+ :key,
41
+ :key?,
42
+ :keys,
43
+ :values,
44
+ :each,
45
+ :map,
46
+ :select,
47
+ :reject,
48
+ :to_a,
49
+ :to_h
50
+
51
+ # Convert a string to a enum key
52
+ def keyify(name)
53
+ name.gsub(%r{[\-\s/\\]}, "_").downcase.to_sym
54
+ end
55
+
56
+ private
57
+
58
+ attr_reader :enum_store
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Yae
2
+ VERSION = "1.0.0"
3
+ end
data/lib/yae.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "yae/version"
2
+ require "yae/enum"
data/sig/types.rbs ADDED
@@ -0,0 +1,52 @@
1
+ module Yae
2
+ VERSION: String
3
+
4
+ class Enum
5
+ extend ::Forwardable
6
+
7
+ def self.inherited: (Enum subclass) -> void
8
+
9
+ # Define an entry in the enum
10
+ def self.define: (Symbol key, untyped value) -> void
11
+
12
+ # Get the enum value
13
+ def self.get: (Symbol key, ?raises: bool) -> (nil | untyped)
14
+
15
+ # Get multiple keys at once
16
+ def self.get_multiple: (*Symbol keys, ?raises: bool) -> Array[untyped]
17
+
18
+ # Check if value is used in enum
19
+ def self.include?: (untyped value) -> bool
20
+
21
+ # Convert a string to a enum key
22
+ def self.keyify: (String name) -> Symbol
23
+
24
+ # Delegate methods to the hash
25
+ def self.key: (untyped) -> Symbol
26
+
27
+ def self.key?: (Symbol key) -> bool
28
+
29
+ def self.keys: () -> Array[Symbol]
30
+
31
+ def self.values: () -> Array[untyped]
32
+
33
+ def self.each: () { ([Symbol, untyped]) -> void } -> Hash[Symbol, untyped]
34
+
35
+ def self.map: () { ([Symbol, untyped]) -> untyped } -> Array[untyped]
36
+
37
+ def self.to_a: () -> Array[[Symbol, untyped]]
38
+
39
+ def self.select: () { ([Symbol, untyped]) -> boolish } -> Hash[Symbol, untyped]
40
+ | () -> Enumerator[[[Symbol, untyped]], Hash[Symbol, untyped]]
41
+
42
+ def self.reject: () { (Symbol, untyped) -> boolish } -> Hash[Symbol, untyped]
43
+ | () -> Enumerator[[Symbol, untyped], Hash[Symbol, untyped]]
44
+
45
+ def self.to_h: () -> Hash[Symbol, untyped]
46
+
47
+ private
48
+
49
+ attr_reader self.enum_store: Hash[Symbol, untyped]
50
+ end
51
+
52
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yae
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Stephen Ierodiaconou
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: standard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: steep
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: yae provides a simple enum class (enumerated type) implementation (Yae::Enum)
42
+ that can be used to abstract a set of values. It also provides methods to check
43
+ values existence in the enum and to iterate over its contents.
44
+ email:
45
+ - stevegeek@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/yae.rb
54
+ - lib/yae/enum.rb
55
+ - lib/yae/version.rb
56
+ - sig/types.rbs
57
+ homepage: https://github.com/stevegeek/yae
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://github.com/stevegeek/yae
62
+ source_code_uri: https://github.com/stevegeek/yae
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.6.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.3.7
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: yae (Yet Another Enum) provides a simple enum class (enumerated type) implementation,
82
+ Yae::Enum
83
+ test_files: []