simpler_enum 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
+ SHA1:
3
+ metadata.gz: 852c5f27e0a8a5ad10d26623f91b83964f1e09e9
4
+ data.tar.gz: 77221d767767b7f3d8345be3a2ce3fb7d3b507bc
5
+ SHA512:
6
+ metadata.gz: 29e8d3f065ca1d8a704f8c8e9918d0760219bf2b5b6a502683d77e8d0028d9f5bd62ad5afbac71a483c9101cb000d1213baacf67a2e6c1e1bdf422087a157cfd
7
+ data.tar.gz: e47c153ede0a48eb12f0164c38390cab04e98bda4bd18b56f2b80d27c537bad31fc230ffa5280e68bf15fac35c08e0a4bdec70ad58c12c0decc970501a8c4d4d
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,50 @@
1
+ AllCops:
2
+ Exclude:
3
+ - '*.gemspec'
4
+ - 'Gemfile'
5
+ - 'Rakefile'
6
+ - 'bin/*'
7
+
8
+ # Accept single-line methods with no body
9
+ SingleLineMethods:
10
+ AllowIfMethodIsEmpty: true
11
+
12
+ # Top-level documentation of clases and modules are needless
13
+ Documentation:
14
+ Enabled: false
15
+
16
+ # Allow to chain of block after another block that spans multiple lines
17
+ MultilineBlockChain:
18
+ Enabled: false
19
+
20
+ # Allow `->` literal for multi line blocks
21
+ Lambda:
22
+ Enabled: false
23
+
24
+ # Both nested and compact are okay
25
+ ClassAndModuleChildren:
26
+ Enabled: false
27
+
28
+ # Specifying param names is unnecessary
29
+ Style/SingleLineBlockParams:
30
+ Enabled: false
31
+
32
+ # Prefer Kernel#sprintf
33
+ FormatString:
34
+ EnforcedStyle: sprintf
35
+
36
+ # Maximum line length
37
+ LineLength:
38
+ Max: 100
39
+
40
+ # Whatever we should use "postfix if/unless"
41
+ IfUnlessModifier:
42
+ MaxLineLength: 100
43
+
44
+ # Maximum method length
45
+ MethodLength:
46
+ Max: 20
47
+
48
+ # Prefer double_quotes strings unless your string literal contains escape chars
49
+ StringLiterals:
50
+ EnforcedStyle: double_quotes
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in simple_enum.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 necojackarc
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,78 @@
1
+ # SimplerEnum [![Build Status](https://travis-ci.org/necojackarc/simpler_enum.svg?branch=master)](https://travis-ci.org/necojackarc/simpler_enum) [![Code Climate](https://codeclimate.com/github/necojackarc/simpler_enum/badges/gpa.svg)](https://codeclimate.com/github/necojackarc/simpler_enum) [![Test Coverage](https://codeclimate.com/github/necojackarc/simpler_enum/badges/coverage.svg)](https://codeclimate.com/github/necojackarc/simpler_enum/coverage)
2
+
3
+ SimplerEnum provides really simple enumerated type.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'simpler_enum'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install simpler_enum
20
+
21
+ ## Usage
22
+
23
+ Any class can include `SimplerEnum` and you can define an enumerated type like this:
24
+
25
+ ```ruby
26
+ require "simpler_enum"
27
+
28
+ class Person
29
+ include SimplerEnum
30
+
31
+ simpler_enum mood: {
32
+ awesome: 0,
33
+ excellent: 1,
34
+ great: 2,
35
+ good: 3,
36
+ fine: 4
37
+ }
38
+
39
+ def initialize(mood: :fine)
40
+ self.mood = mood
41
+ end
42
+ end
43
+ ```
44
+
45
+ ```ruby
46
+ [1] pry(main)> Person.moods
47
+ => {:awesome=>0, :excellent=>1, :great=>2, :good=>3, :fine=>4}
48
+ [2] pry(main)> necojackarc = Person.new(mood: :awesome)
49
+ => #<Person:0x007fd5cbbf5dd0 @mood=0>
50
+ [3] pry(main)> necojackarc.awesome?
51
+ => true
52
+ [4] pry(main)> necojackarc.excellent?
53
+ => false
54
+ [5] pry(main)> necojackarc.great!
55
+ => :great
56
+ [6] pry(main)> necojackarc.awesome?
57
+ => false
58
+ [7] pry(main)> necojackarc.great?
59
+ => true
60
+ [8] pry(main)> necojackarc.mood = :fine
61
+ => :fine
62
+ [9] pry(main)> necojackarc.great?
63
+ => false
64
+ [10] pry(main)> necojackarc.fine?
65
+ => true
66
+ [11] pry(main)> necojackarc.mood = 1
67
+ => 1
68
+ [12] pry(main)> necojackarc.fine?
69
+ => false
70
+ [13] pry(main)> necojackarc.excellent?
71
+ => true
72
+ [14] pry(main)> necojackarc.mood
73
+ => :excellent
74
+ ```
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the [MIT License](http://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 "simple_enum"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,69 @@
1
+ require "active_support"
2
+ require "active_support/core_ext"
3
+ require "simpler_enum/version"
4
+
5
+ module SimplerEnum
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def simpler_enum(single_size_hash)
12
+ fail ArgumentError if single_size_hash.size != 1
13
+
14
+ name, enum_values = single_size_hash.first
15
+
16
+ define_read_enum_values_method_to_class!(name.to_s.pluralize, enum_values)
17
+ define_read_enum_value_method_to_instance!(name)
18
+ define_write_enum_value_method_to_instance!(name)
19
+
20
+ enum_values.each do |key, _|
21
+ define_query_enum_state_method_to_instance!(name, key)
22
+ define_change_enum_state_method_to_instance!(name, key)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def define_read_enum_values_method_to_class!(pluralized_name, enum_values)
29
+ instance_variable_set("@#{pluralized_name}", enum_values)
30
+ define_singleton_method pluralized_name do
31
+ instance_variable_get "@#{pluralized_name}"
32
+ end
33
+ end
34
+
35
+ def define_query_enum_state_method_to_instance!(enum_name, value_name)
36
+ define_method "#{value_name}?" do
37
+ current_value = instance_variable_get("@#{enum_name}")
38
+ current_value == self.class.public_send(enum_name.to_s.pluralize.to_sym)[value_name]
39
+ end
40
+ end
41
+
42
+ def define_change_enum_state_method_to_instance!(enum_name, value_name)
43
+ define_method "#{value_name}!" do
44
+ next_value = self.class.public_send(enum_name.to_s.pluralize.to_sym)[value_name]
45
+ instance_variable_set("@#{enum_name}", next_value)
46
+ public_send(enum_name)
47
+ end
48
+ end
49
+
50
+ def define_read_enum_value_method_to_instance!(enum_name)
51
+ define_method "#{enum_name}" do
52
+ value = instance_variable_get("@#{enum_name}")
53
+ self.class.public_send(enum_name.to_s.pluralize.to_sym).key(value)
54
+ end
55
+ end
56
+
57
+ def define_write_enum_value_method_to_instance!(enum_name)
58
+ define_method "#{enum_name}=" do |value|
59
+ next_value =
60
+ if value.is_a?(Symbol)
61
+ self.class.public_send(enum_name.to_s.pluralize.to_sym)[value]
62
+ else
63
+ value
64
+ end
65
+ instance_variable_set("@#{enum_name}", next_value)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module SimplerEnum
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'simpler_enum/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "simpler_enum"
7
+ spec.version = SimplerEnum::VERSION
8
+ spec.authors = ["necojackarc"]
9
+ spec.email = ["necojackarc@gmail.com"]
10
+
11
+ spec.summary = %q{Simpler Enumerated Type}
12
+ spec.description = %q{simpler_enum provides really simple enumerated type}
13
+ spec.homepage = "https://github.com/necojackarc/simpler_enum"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport"
22
+ spec.add_dependency "i18n"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "rspec-its"
28
+ spec.add_development_dependency "simplecov"
29
+ spec.add_development_dependency "codeclimate-test-reporter"
30
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simpler_enum
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - necojackarc
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: i18n
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
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: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-its
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: codeclimate-test-reporter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: simpler_enum provides really simple enumerated type
126
+ email:
127
+ - necojackarc@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - ".travis.yml"
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - lib/simpler_enum.rb
144
+ - lib/simpler_enum/version.rb
145
+ - simpler_enum.gemspec
146
+ homepage: https://github.com/necojackarc/simpler_enum
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.2.3
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Simpler Enumerated Type
170
+ test_files: []