enu 0.0.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: 76d6598c2cfc01b242e4244a82ab4be85662394a803c9a1d06622e1b47330bf3
4
+ data.tar.gz: 99f43dbaed015274a93c4647d7a2a497126035c965751189d943f18616e99e50
5
+ SHA512:
6
+ metadata.gz: 890d0fbc649367e4e961042c506d39ef90f4da985e620b00d6c62e8ffed9ba95dd8f1ed351033b6cb1bc658b66c9fbf44a428aaacca89a7d32bf7ea0882ecc83
7
+ data.tar.gz: da8a992dc56e7e2349c07ac9387a1b1126050fc897c2bbe73a29403daa2ce305abb24f6d631143a3098b5a171e6f9dbc12d40442b72874bcf8b436d153142e79
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /.bundle/
2
+ /coverage/
3
+ /pkg/
4
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ ---
2
+ require:
3
+ - standard/cop/semantic_blocks
4
+
5
+ inherit_gem:
6
+ standard: config/base.yml
7
+
8
+ AllCops:
9
+ DisplayCopNames: true
10
+ Exclude:
11
+ - 'bin/*'
12
+ - 'Gemfile'
13
+ - 'tmp/**/*'
14
+ - 'vendor/**/*'
15
+
16
+ Style/TrailingCommaInHashLiteral:
17
+ EnforcedStyleForMultiline: no_comma
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6
7
+ - 2.3
8
+ - ruby-head
9
+ before_install: gem install bundler -v 2.0.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,100 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ enu (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ ast (2.4.0)
11
+ builder (3.2.3)
12
+ coderay (1.1.2)
13
+ docile (1.3.2)
14
+ ffi (1.11.1)
15
+ formatador (0.2.5)
16
+ guard (2.15.0)
17
+ formatador (>= 0.2.4)
18
+ listen (>= 2.7, < 4.0)
19
+ lumberjack (>= 1.0.12, < 2.0)
20
+ nenv (~> 0.1)
21
+ notiffany (~> 0.0)
22
+ pry (>= 0.9.12)
23
+ shellany (~> 0.0)
24
+ thor (>= 0.18.1)
25
+ guard-compat (1.2.1)
26
+ guard-minitest (2.4.6)
27
+ guard-compat (~> 1.2)
28
+ minitest (>= 3.0)
29
+ jaro_winkler (1.5.3)
30
+ json (2.2.0)
31
+ listen (3.1.5)
32
+ rb-fsevent (~> 0.9, >= 0.9.4)
33
+ rb-inotify (~> 0.9, >= 0.9.7)
34
+ ruby_dep (~> 1.2)
35
+ lumberjack (1.0.13)
36
+ method_source (0.9.2)
37
+ minitest (5.11.3)
38
+ minitest-reporters (1.3.6)
39
+ ansi
40
+ builder
41
+ minitest (>= 5.0)
42
+ ruby-progressbar
43
+ nenv (0.3.0)
44
+ notiffany (0.1.1)
45
+ nenv (~> 0.1)
46
+ shellany (~> 0.0)
47
+ parallel (1.17.0)
48
+ parser (2.6.3.0)
49
+ ast (~> 2.4.0)
50
+ pry (0.12.2)
51
+ coderay (~> 1.1.0)
52
+ method_source (~> 0.9.0)
53
+ rainbow (3.0.0)
54
+ rake (10.5.0)
55
+ rb-fsevent (0.10.3)
56
+ rb-inotify (0.10.0)
57
+ ffi (~> 1.0)
58
+ rb-readline (0.5.5)
59
+ rubocop (0.72.0)
60
+ jaro_winkler (~> 1.5.1)
61
+ parallel (~> 1.10)
62
+ parser (>= 2.6)
63
+ rainbow (>= 2.2.2, < 4.0)
64
+ ruby-progressbar (~> 1.7)
65
+ unicode-display_width (>= 1.4.0, < 1.7)
66
+ rubocop-performance (1.4.0)
67
+ rubocop (>= 0.71.0)
68
+ ruby-progressbar (1.10.1)
69
+ ruby_dep (1.5.0)
70
+ shellany (0.0.1)
71
+ simplecov (0.17.0)
72
+ docile (~> 1.1)
73
+ json (>= 1.8, < 3)
74
+ simplecov-html (~> 0.10.0)
75
+ simplecov-html (0.10.2)
76
+ standard (0.1.0)
77
+ rubocop (~> 0.72.0)
78
+ rubocop-performance (~> 1.4.0)
79
+ thor (0.20.3)
80
+ unicode-display_width (1.6.0)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ bundler (~> 2.0)
87
+ enu!
88
+ guard (~> 2.15)
89
+ guard-minitest (~> 2.4, >= 2.4.6)
90
+ minitest (~> 5.0)
91
+ minitest-reporters (~> 1.3, >= 1.3.6)
92
+ pry (~> 0.12.2)
93
+ rake (~> 10.0)
94
+ rb-readline (~> 0.5.5)
95
+ rubocop (~> 0.72.0)
96
+ simplecov (~> 0.17)
97
+ standard (~> 0.1.0)
98
+
99
+ BUNDLED WITH
100
+ 2.0.2
data/Guardfile ADDED
@@ -0,0 +1,22 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ guard :minitest do
19
+ watch(%r{^test/(.*)\/?(.*)_test\.rb$})
20
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
21
+ watch(%r{^test/test_helper\.rb$}) { "test" }
22
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Alex Musayev
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,51 @@
1
+ # Enu
2
+
3
+ [![Build Status](https://travis-ci.org/dreikanter/enu.svg?branch=master)](https://travis-ci.org/dreikanter/enu)
4
+
5
+ This gem introduce missing enum type for Ruby and Rails.
6
+
7
+ Purpose and features:
8
+
9
+ - Unify enum types definition for Rails model attributes, compatible with ActiveRecord's [enum declarations](https://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html).
10
+ - Use constants instead of magic strings or numbers to define enum values.
11
+ - Support explicit and implicit enum options definition.
12
+ - Keep track on enum references to simplify refactoring.
13
+ - Provide a standardized way to export enum definitions to client-side JavaScript modules, managed by either Webpack or Rails Assets Pipeline.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'enu'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ ```bash
26
+ $ bundle
27
+ ```
28
+
29
+ Or install it yourself as:
30
+
31
+ ```bash
32
+ $ gem install enu
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ [TODO]
38
+
39
+ ## Development
40
+
41
+ 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.
42
+
43
+ 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).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dreikanter/enu. Before sending a PR, please make sure your changes are on a new branch forked from `dev`, and the test coverage is kept at 100%.
48
+
49
+ ## License
50
+
51
+ 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,13 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "rubocop/rake_task"
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
+ RuboCop::RakeTask.new
12
+
13
+ task default: [:rubocop, :test]
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pry"
5
+ require "enu"
6
+
7
+ Pry.start
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/enu.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "enu/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "enu"
7
+ spec.version = Enu::VERSION
8
+ spec.authors = ["Alex Musayev"]
9
+ spec.email = ["alex.musayev@gmail.com"]
10
+
11
+ spec.summary = "Missing enum type for Ruby and Rails"
12
+ spec.description = ""
13
+ spec.homepage = "https://github.com/dreikanter/enu"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "https://github.com/dreikanter/enu/blob/master/CHANGELOG.md"
19
+
20
+ spec.files = Dir.chdir(__dir__) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+
24
+ spec.required_ruby_version = ">= 2.3.0"
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "guard", "~> 2.15"
29
+ spec.add_development_dependency "guard-minitest", "~> 2.4", ">= 2.4.6"
30
+ spec.add_development_dependency "minitest", "~> 5.0"
31
+ spec.add_development_dependency "minitest-reporters", "~> 1.3", ">= 1.3.6"
32
+ spec.add_development_dependency "pry", "~> 0.12.2"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rb-readline", "~> 0.5.5"
35
+ spec.add_development_dependency "rubocop", "~> 0.72.0"
36
+ spec.add_development_dependency "simplecov", "~> 0.17"
37
+ spec.add_development_dependency "standard", "~> 0.1.0"
38
+ end
@@ -0,0 +1,3 @@
1
+ class Enu
2
+ VERSION = "0.0.1"
3
+ end
data/lib/enu.rb ADDED
@@ -0,0 +1,57 @@
1
+ require "enu/version"
2
+
3
+ class Enu
4
+ def self.option(key, value = nil)
5
+ value ||= next_value
6
+
7
+ raise KeyError, "'#{key}' option already exists" if include?(key)
8
+ raise TypeError, "enum values must be integer" unless value.is_a?(Integer)
9
+ raise KeyError, "'#{key}' is a reserved key" if respond_to?(key)
10
+
11
+ str_key = key.to_s
12
+ @options[str_key] = value
13
+
14
+ singleton_class.class_eval do
15
+ define_method(key) { str_key }
16
+ define_method("#{str_key}_value") { value }
17
+ end
18
+ end
19
+
20
+ def self.include?(key)
21
+ options.key?(key.to_s)
22
+ end
23
+
24
+ def self.options
25
+ @options ||= {}
26
+ end
27
+
28
+ def self.keys
29
+ options.keys
30
+ end
31
+
32
+ def self.values
33
+ options.values
34
+ end
35
+
36
+ def self.default
37
+ raise if options.empty?
38
+ options.keys.first.to_s
39
+ end
40
+
41
+ def self.each
42
+ options.each { |key, value| yield key, value }
43
+ end
44
+
45
+ def self.each_pair(&block)
46
+ each(&block)
47
+ end
48
+
49
+ def self.each_with_index(&block)
50
+ each(&block)
51
+ end
52
+
53
+ def self.next_value
54
+ return 0 if values.empty?
55
+ values.max + 1
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Musayev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.4.6
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.4'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.4.6
61
+ - !ruby/object:Gem::Dependency
62
+ name: minitest
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '5.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '5.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: minitest-reporters
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.3'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.3.6
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.3'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.3.6
95
+ - !ruby/object:Gem::Dependency
96
+ name: pry
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: 0.12.2
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: 0.12.2
109
+ - !ruby/object:Gem::Dependency
110
+ name: rake
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '10.0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '10.0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rb-readline
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: 0.5.5
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: 0.5.5
137
+ - !ruby/object:Gem::Dependency
138
+ name: rubocop
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: 0.72.0
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: 0.72.0
151
+ - !ruby/object:Gem::Dependency
152
+ name: simplecov
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '0.17'
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: '0.17'
165
+ - !ruby/object:Gem::Dependency
166
+ name: standard
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: 0.1.0
172
+ type: :development
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - "~>"
177
+ - !ruby/object:Gem::Version
178
+ version: 0.1.0
179
+ description: ''
180
+ email:
181
+ - alex.musayev@gmail.com
182
+ executables: []
183
+ extensions: []
184
+ extra_rdoc_files: []
185
+ files:
186
+ - ".gitignore"
187
+ - ".rubocop.yml"
188
+ - ".travis.yml"
189
+ - CHANGELOG.md
190
+ - Gemfile
191
+ - Gemfile.lock
192
+ - Guardfile
193
+ - LICENSE.txt
194
+ - README.md
195
+ - Rakefile
196
+ - bin/console
197
+ - bin/setup
198
+ - enu.gemspec
199
+ - lib/enu.rb
200
+ - lib/enu/version.rb
201
+ homepage: https://github.com/dreikanter/enu
202
+ licenses:
203
+ - MIT
204
+ metadata:
205
+ homepage_uri: https://github.com/dreikanter/enu
206
+ source_code_uri: https://github.com/dreikanter/enu
207
+ changelog_uri: https://github.com/dreikanter/enu/blob/master/CHANGELOG.md
208
+ post_install_message:
209
+ rdoc_options: []
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: 2.3.0
217
+ required_rubygems_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ requirements: []
223
+ rubygems_version: 3.0.3
224
+ signing_key:
225
+ specification_version: 4
226
+ summary: Missing enum type for Ruby and Rails
227
+ test_files: []