rekkyo 0.1.0

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: 43c12110a7a3b05da0003a83490ba9a28e38117331ded44d254ed6850bd59eb8
4
+ data.tar.gz: 39b797a2e7859ae7d10e3257ba327128a3ed581621423bd3d3a4d87435a33cb7
5
+ SHA512:
6
+ metadata.gz: 2bf129aaa32a96d1835d7bf9c63b319bf281266f006105ff5b81b05115103918bdf02bf4a3e685453fdd6a24ec9128d510d7771c584dec0a3cec25e89bd3014e
7
+ data.tar.gz: 977c624bd77a82f3e5359cdc30f85ff47f70dcdacada4e4e99fe0a024fc613da88c0c48d63fbd3510c9b87df8684f8d172da699d17ac0b9cfe1d603f262cb6a7
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /Gemfile.lock
5
+ /coverage/
6
+ /doc/
7
+ /gemfiles/*.gemfile.lock
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/AsciiComments:
5
+ Enabled: false
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ Style/RedundantSelf:
11
+ Enabled: false
12
+
13
+ Style/StringLiterals:
14
+ Enabled: true
15
+ EnforcedStyle: double_quotes
16
+
17
+ Layout/EndOfLine:
18
+ Enabled: true
19
+ EnforcedStyle: lf
20
+
21
+ Metrics/BlockLength:
22
+ Exclude:
23
+ - spec/**/*
24
+
25
+ Metrics/MethodLength:
26
+ Exclude:
27
+ - spec/**/*
28
+
29
+ Metrics/LineLength:
30
+ Max: 128
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.5
7
+ - 2.5.3
8
+ gemfile:
9
+ - Gemfile
10
+ - gemfiles/activesupport_5.1.gemfile
11
+ - gemfiles/activesupport_5.2.gemfile
12
+ before_install: gem install bundler -v 1.17.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## Unreleased
2
+
3
+
4
+ ## 0.1.0 (2018-12-07)
5
+
6
+ Initial release
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in rekkyo.gemspec
8
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Yuji Hanamura
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,68 @@
1
+ # Rekkyo
2
+
3
+ [![Build Status](https://travis-ci.org/yujideveloper/rekkyo.svg?branch=master)](https://travis-ci.org/yujideveloper/rekkyo)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/37d6334cedf5b04af831/maintainability)](https://codeclimate.com/github/yujideveloper/rekkyo/maintainability)
5
+
6
+ Rekkyo is a gem for defining an enumerated type in Ruby.
7
+
8
+ This gem is inspired by [`Ruby::Enum`](https://github.com/dblock/ruby-enum) and [`Enum`](https://github.com/LIQIDTechnology/enum_class).
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'rekkyo'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install rekkyo
25
+
26
+ ## Usage
27
+
28
+ ### Basic usage
29
+
30
+ ``` ruby
31
+ class Color
32
+ include Rekkyo::Type
33
+
34
+ member :RED
35
+ member :GREEN
36
+ member :BLUE
37
+ end
38
+
39
+ { color: Color::RED }.to_json # => "{\"color\":\"RED\"}
40
+ ```
41
+
42
+ ### Custom value
43
+
44
+ ``` ruby
45
+ class Color
46
+ include Rekkyo::Type
47
+
48
+ member :RED, "#FF0000"
49
+ member :GREEN, "#00FF00"
50
+ member :BLUE, "#0000FF"
51
+ end
52
+
53
+ { color: Color::RED }.to_json # => "{\"color\":\"#FF0000\"}"
54
+ ```
55
+
56
+ ## Development
57
+
58
+ 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.
59
+
60
+ 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).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yujideveloper/rekkyo.
65
+
66
+ ## License
67
+
68
+ 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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rekkyo"
6
+
7
+ require "pry"
8
+ 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
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gem "activesupport", "~> 5.1.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gem "activesupport", "~> 5.2.0"
6
+
7
+ gemspec path: "../"
data/lib/rekkyo.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rekkyo/version"
4
+
5
+ module Rekkyo
6
+ class Error < StandardError; end
7
+ class DuplicateMemberError < Error
8
+ end
9
+ end
10
+
11
+ require "rekkyo/type"
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
4
+
5
+ module Rekkyo
6
+ module Type
7
+ Member = Struct.new(:key, :value) do
8
+ def match?(value)
9
+ if value.is_a? self.class
10
+ self == value
11
+ else
12
+ self.value == value
13
+ end
14
+ end
15
+
16
+ def to_s
17
+ self.value.to_s
18
+ end
19
+
20
+ if defined? ActiveSupport
21
+ def as_json(options = nil)
22
+ self.to_s.as_json(options)
23
+ end
24
+ end
25
+ end
26
+
27
+ class << self
28
+ def included(klass)
29
+ klass.const_set(:Member, Class.new(Member))
30
+ klass.instance_variable_set(:@members, Set.new)
31
+ klass.extend(ClassMethods)
32
+ end
33
+ end
34
+
35
+ module ClassMethods
36
+ UNSPECIFIED = Object.new.freeze
37
+ private_constant :UNSPECIFIED
38
+
39
+ def member(key, value = UNSPECIFIED)
40
+ value = key if value == UNSPECIFIED
41
+ key = key.upcase.to_sym
42
+
43
+ raise DuplicateMemberError if self.const_defined?(key, false) ||
44
+ @members.any? { |m| m.match? value }
45
+
46
+ m = self::Member.new(key, value).freeze
47
+ @members << m
48
+ self.const_set(key, m)
49
+ end
50
+
51
+ def all
52
+ @members.dup
53
+ end
54
+
55
+ alias members all
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rekkyo
4
+ VERSION = "0.1.0"
5
+ end
data/rekkyo.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "rekkyo/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "rekkyo"
9
+ spec.version = Rekkyo::VERSION
10
+ spec.authors = ["Yuji Hanamura"]
11
+ spec.email = ["yuji.developer@gmail.com"]
12
+
13
+ spec.summary = "An enumerated type in Ruby."
14
+ spec.description = "Rekkyo is a gem for defining an enumerated type in Ruby."
15
+ spec.homepage = "https://github.com/yujideveloper/rekkyo"
16
+ spec.license = "MIT"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ spec.metadata["changelog_uri"] = "https://github.com/yujideveloper/rekkyo/tree/master/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.17"
32
+ spec.add_development_dependency "pry", ">= 0.12.2"
33
+ spec.add_development_dependency "pry-doc", ">= 0.13.5"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.8"
36
+ spec.add_development_dependency "rubocop", ">= 0.61.1"
37
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rekkyo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuji Hanamura
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-07 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: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.12.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.12.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-doc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.61.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.61.1
97
+ description: Rekkyo is a gem for defining an enumerated type in Ruby.
98
+ email:
99
+ - yuji.developer@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - CHANGELOG.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - gemfiles/activesupport_5.1.gemfile
116
+ - gemfiles/activesupport_5.2.gemfile
117
+ - lib/rekkyo.rb
118
+ - lib/rekkyo/type.rb
119
+ - lib/rekkyo/version.rb
120
+ - rekkyo.gemspec
121
+ homepage: https://github.com/yujideveloper/rekkyo
122
+ licenses:
123
+ - MIT
124
+ metadata:
125
+ homepage_uri: https://github.com/yujideveloper/rekkyo
126
+ source_code_uri: https://github.com/yujideveloper/rekkyo
127
+ changelog_uri: https://github.com/yujideveloper/rekkyo/tree/master/CHANGELOG.md
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.7.6
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: An enumerated type in Ruby.
148
+ test_files: []