ruby_enum 0.1.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
+ SHA1:
3
+ metadata.gz: 3c6a72a675c8fb1c4a85809100aec69936f5a817
4
+ data.tar.gz: 860b5ca16bada4964b91e6d254cec40e517c69cb
5
+ SHA512:
6
+ metadata.gz: 5134691adf41fa028d5276548228ee7df8de5788052cffc1748730c39f55954ae5c85f0d04a31c458e96fa8af368e735d342771e868bf2a69d3afc8050b8e58f
7
+ data.tar.gz: 70e290e118a5700ba880daed557ed9a6678eecdcf55b4fec46b60e5c8ecc00b72e1652e08d8e264c3807fdfcbfb9e2f5a21042b8a8e54de177c2502744898f54
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby_enum (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.4.2)
11
+ rspec (3.3.0)
12
+ rspec-core (~> 3.3.0)
13
+ rspec-expectations (~> 3.3.0)
14
+ rspec-mocks (~> 3.3.0)
15
+ rspec-core (3.3.2)
16
+ rspec-support (~> 3.3.0)
17
+ rspec-expectations (3.3.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.3.0)
20
+ rspec-mocks (3.3.2)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.3.0)
23
+ rspec-support (3.3.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.8)
30
+ rake (~> 10.0)
31
+ rspec (~> 3.3.0)
32
+ ruby_enum!
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Lefteris Laskaridis
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,48 @@
1
+ # RubyEnum
2
+
3
+ A simple enumeration type for ruby classes.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruby_enum'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ruby_enum
20
+
21
+ ## Usage
22
+
23
+ To create an enumeration type simply include the `RubyEnum` module and define the enumeration values as follows:
24
+ ```ruby
25
+ class Coordinates
26
+ include RubyEnum
27
+
28
+ enum :north
29
+ enum :south
30
+ enum :west
31
+ enum :east
32
+ ```
33
+
34
+ Including `RubyEnum` in any class will make it a singleton. This means that you can't use `new`, `allocate`, `clone` or `dup` on that class. You can access enumeration values however as follows:
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/[my-github-username]/ruby_enum/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruby_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,3 @@
1
+ module RubyEnum
2
+ VERSION = "0.1.0"
3
+ end
data/lib/ruby_enum.rb ADDED
@@ -0,0 +1,76 @@
1
+ require "ruby_enum/version"
2
+
3
+ module RubyEnum
4
+
5
+ def self.included(base)
6
+ # enmeration instances are singleton values
7
+ base.private_class_method(:new, :allocate)
8
+ base.extend(ClassMethods)
9
+ base.include(InstanceMethods)
10
+ end
11
+
12
+ module InstanceMethods
13
+
14
+ # the value associated with the enumeration instance
15
+ def raw_value
16
+ @_value
17
+ end
18
+
19
+ def clone
20
+ raise TypeError, "can't clone instance of enum #{self.class}"
21
+ end
22
+
23
+ def dup
24
+ raise TypeError, "can't dupe instance of enum #{self.class}"
25
+ end
26
+
27
+ private
28
+
29
+ def initialize(value)
30
+ @_value = value
31
+ end
32
+ end
33
+
34
+ module ClassMethods
35
+
36
+ # enable retrieving enumeration values as constants
37
+ def const_missing(name)
38
+ self[name] || super
39
+ end
40
+
41
+ # defines enumeration values
42
+ def enum(name, value = nil)
43
+ @_instances ||= {}
44
+
45
+ normalized_name = normalize name
46
+ if self[normalized_name]
47
+ raise ArgumentError, "An enumeration value for #{normalized_name} has " \
48
+ "already been defined in #{self.name}."
49
+ else
50
+ value = normalized_name.to_s unless value
51
+ define_instance_accessor_for normalized_name
52
+ @_instances[normalized_name] = new value
53
+ end
54
+ end
55
+
56
+ def [](name)
57
+ @_instances[normalize(name)]
58
+ end
59
+
60
+ def all
61
+ @_instances.map { |_, instance| instance }
62
+ end
63
+
64
+ private
65
+
66
+ def define_instance_accessor_for(name)
67
+ self.class.instance_eval do
68
+ define_method(name) { return self[name] }
69
+ end
70
+ end
71
+
72
+ def normalize(name)
73
+ name.to_s.downcase.to_sym
74
+ end
75
+ end
76
+ end
data/ruby_enum.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_enum/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby_enum"
8
+ spec.version = RubyEnum::VERSION
9
+ spec.authors = ["Lefteris Laskaridis"]
10
+ spec.email = ["l.laskaridis@pamediakopes.gr"]
11
+
12
+ spec.summary = %q{Simple enumeration type for ruby}
13
+ spec.description = %q{Implementation of a simple enumeration type for ruby}
14
+ spec.homepage = "http://www.laskaridis.cm"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.3.0"
25
+ end
data/tags ADDED
@@ -0,0 +1,20 @@
1
+ !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
2
+ !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
3
+ !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
4
+ !_TAG_PROGRAM_NAME Exuberant Ctags //
5
+ !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
6
+ !_TAG_PROGRAM_VERSION 5.9~svn20110310 //
7
+ ClassMethods lib/ruby_enum.rb /^ module ClassMethods$/;" m class:RubyEnum
8
+ Coordinates spec/ruby_enum_spec.rb /^ class Coordinates$/;" c
9
+ Member lib/ruby_enum/member.rb /^ class Member$/;" c class:RubyEnum
10
+ RubyEnum lib/ruby_enum.rb /^module RubyEnum$/;" m
11
+ RubyEnum lib/ruby_enum/member.rb /^module RubyEnum$/;" m
12
+ RubyEnum lib/ruby_enum/version.rb /^module RubyEnum$/;" m
13
+ [] lib/ruby_enum.rb /^ def [](member_name)$/;" f class:RubyEnum.ClassMethods
14
+ enum lib/ruby_enum.rb /^ def enum(name, value = nil)$/;" f class:RubyEnum.ClassMethods
15
+ enumeration_members lib/ruby_enum.rb /^ def enumeration_members$/;" f class:RubyEnum.ClassMethods
16
+ enumeration_value_for lib/ruby_enum.rb /^ def enumeration_value_for(member_name)$/;" f class:RubyEnum.ClassMethods
17
+ find_enumeration_member_by lib/ruby_enum.rb /^ def find_enumeration_member_by(name)$/;" f class:RubyEnum.ClassMethods
18
+ included lib/ruby_enum.rb /^ def self.included(base)$/;" F class:RubyEnum
19
+ initialize lib/ruby_enum/member.rb /^ def initialize(name, value = nil)$/;" f class:RubyEnum.Member
20
+ method_missing lib/ruby_enum.rb /^ def method_missing(name, *args, &blk)$/;" f class:RubyEnum
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_enum
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lefteris Laskaridis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-15 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.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.3.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.3.0
55
+ description: Implementation of a simple enumeration type for ruby
56
+ email:
57
+ - l.laskaridis@pamediakopes.gr
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/ruby_enum.rb
70
+ - lib/ruby_enum/version.rb
71
+ - ruby_enum.gemspec
72
+ - tags
73
+ homepage: http://www.laskaridis.cm
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.6
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Simple enumeration type for ruby
97
+ test_files: []