mirror of
https://github.com/danbee/inny
synced 2025-03-04 08:59:10 +00:00
First commit
This commit is contained in:
commit
6e86e10272
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/.bundle/
|
||||
/.yardoc
|
||||
/Gemfile.lock
|
||||
/_yardoc/
|
||||
/coverage/
|
||||
/doc/
|
||||
/pkg/
|
||||
/spec/reports/
|
||||
/tmp/
|
||||
4
.travis.yml
Normal file
4
.travis.yml
Normal file
@ -0,0 +1,4 @@
|
||||
language: ruby
|
||||
rvm:
|
||||
- 2.2.3
|
||||
before_install: gem install bundler -v 1.10.6
|
||||
13
CODE_OF_CONDUCT.md
Normal file
13
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Contributor Code of Conduct
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
||||
|
||||
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/)
|
||||
4
Gemfile
Normal file
4
Gemfile
Normal file
@ -0,0 +1,4 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
# Specify your gem's dependencies in inny.gemspec
|
||||
gemspec
|
||||
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Dan Barber
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
47
README.md
Normal file
47
README.md
Normal file
@ -0,0 +1,47 @@
|
||||
# Inny
|
||||
|
||||
I wrote this gem to scratch a little itch I have had for a while. I never liked
|
||||
the syntax required to check whether an object was in a list of objects:
|
||||
|
||||
```ruby
|
||||
['Egg', 'Bacon', 'Sausage'].include?(thing)
|
||||
```
|
||||
|
||||
I'd much rather ask an object if it was in a list. It just feels like it's the
|
||||
right way round:
|
||||
|
||||
```ruby
|
||||
thing.in?('Egg', 'Bacon', 'Sausage')
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
Add this line to your application's Gemfile:
|
||||
|
||||
```ruby
|
||||
gem 'inny'
|
||||
```
|
||||
|
||||
And then execute:
|
||||
|
||||
$ bundle
|
||||
|
||||
Or install it yourself as:
|
||||
|
||||
$ gem install inny
|
||||
|
||||
## Development
|
||||
|
||||
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.
|
||||
|
||||
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).
|
||||
|
||||
## Contributing
|
||||
|
||||
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/inny. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
||||
|
||||
10
Rakefile
Normal file
10
Rakefile
Normal file
@ -0,0 +1,10 @@
|
||||
require "bundler/gem_tasks"
|
||||
require "rake/testtask"
|
||||
|
||||
Rake::TestTask.new(:test) do |t|
|
||||
t.libs << "test"
|
||||
t.libs << "lib"
|
||||
t.test_files = FileList['test/**/*_test.rb']
|
||||
end
|
||||
|
||||
task :default => :test
|
||||
14
bin/console
Executable file
14
bin/console
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require "bundler/setup"
|
||||
require "inny"
|
||||
|
||||
# You can add fixtures and/or initialization code here to make experimenting
|
||||
# with your gem easier. You can also use a different console, if you like.
|
||||
|
||||
# (If you use this, don't forget to add pry to your Gemfile!)
|
||||
# require "pry"
|
||||
# Pry.start
|
||||
|
||||
require "irb"
|
||||
IRB.start
|
||||
7
bin/setup
Executable file
7
bin/setup
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
bundle install
|
||||
|
||||
# Do any other automated setup that you need to do here
|
||||
33
inny.gemspec
Normal file
33
inny.gemspec
Normal file
@ -0,0 +1,33 @@
|
||||
# coding: utf-8
|
||||
lib = File.expand_path('../lib', __FILE__)
|
||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||
require 'inny/version'
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "inny"
|
||||
spec.version = Inny::VERSION
|
||||
spec.authors = ["Dan Barber"]
|
||||
spec.email = ["github@danbarber.me"]
|
||||
|
||||
spec.summary = %q{Better syntax for testing whether an object is in a list}
|
||||
spec.description = %q{Better syntax for testing whether an object is in a list}
|
||||
spec.homepage = "https://github.com/danbee/inny"
|
||||
spec.license = "MIT"
|
||||
|
||||
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
||||
# delete this section to allow pushing this gem to any host.
|
||||
if spec.respond_to?(:metadata)
|
||||
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
||||
else
|
||||
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
||||
end
|
||||
|
||||
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
||||
spec.bindir = "exe"
|
||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ["lib"]
|
||||
|
||||
spec.add_development_dependency "bundler", "~> 1.10"
|
||||
spec.add_development_dependency "rake", "~> 10.0"
|
||||
spec.add_development_dependency "minitest"
|
||||
end
|
||||
11
lib/inny.rb
Normal file
11
lib/inny.rb
Normal file
@ -0,0 +1,11 @@
|
||||
require "inny/version"
|
||||
|
||||
module Inny
|
||||
def in?(*list)
|
||||
list.include?(self)
|
||||
end
|
||||
end
|
||||
|
||||
class Object
|
||||
include Inny
|
||||
end
|
||||
3
lib/inny/version.rb
Normal file
3
lib/inny/version.rb
Normal file
@ -0,0 +1,3 @@
|
||||
module Inny
|
||||
VERSION = "1.0.0"
|
||||
end
|
||||
24
test/inny_test.rb
Normal file
24
test/inny_test.rb
Normal file
@ -0,0 +1,24 @@
|
||||
require 'test_helper'
|
||||
|
||||
class InnyTest < Minitest::Test
|
||||
def test_that_it_has_a_version_number
|
||||
refute_nil ::Inny::VERSION
|
||||
end
|
||||
|
||||
def test_it_finds_integers
|
||||
assert 8.in?(1, 2, 3) == false
|
||||
assert 8.in?(7, 8, 9) == true
|
||||
end
|
||||
|
||||
def test_it_finds_strings
|
||||
assert 'Egg'.in?('Apple', 'Orange', 'Banana') == false
|
||||
assert 'Egg'.in?('Bacon', 'Sausage', 'Egg') == true
|
||||
end
|
||||
|
||||
def test_it_finds_things_in_an_array
|
||||
list = ['John', 'Jimmy', 'Robert']
|
||||
|
||||
assert 'John Paul'.in?(*list) == false
|
||||
assert 'Jimmy'.in?(*list) == true
|
||||
end
|
||||
end
|
||||
4
test/test_helper.rb
Normal file
4
test/test_helper.rb
Normal file
@ -0,0 +1,4 @@
|
||||
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
||||
require 'inny'
|
||||
|
||||
require 'minitest/autorun'
|
||||
Loading…
Reference in New Issue
Block a user