From 6e86e102727b51f505f0bdcb90de9fac5c6404cd Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Mon, 21 Sep 2015 21:56:35 +0100 Subject: [PATCH] First commit --- .gitignore | 9 +++++++++ .travis.yml | 4 ++++ CODE_OF_CONDUCT.md | 13 +++++++++++++ Gemfile | 4 ++++ LICENSE.txt | 21 ++++++++++++++++++++ README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++ Rakefile | 10 ++++++++++ bin/console | 14 ++++++++++++++ bin/setup | 7 +++++++ inny.gemspec | 33 +++++++++++++++++++++++++++++++ lib/inny.rb | 11 +++++++++++ lib/inny/version.rb | 3 +++ test/inny_test.rb | 24 +++++++++++++++++++++++ test/test_helper.rb | 4 ++++ 14 files changed, 204 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 Gemfile create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 Rakefile create mode 100755 bin/console create mode 100755 bin/setup create mode 100644 inny.gemspec create mode 100644 lib/inny.rb create mode 100644 lib/inny/version.rb create mode 100644 test/inny_test.rb create mode 100644 test/test_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cb6eeb --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/.bundle/ +/.yardoc +/Gemfile.lock +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6fb8618 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: ruby +rvm: + - 2.2.3 +before_install: gem install bundler -v 1.10.6 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..ce9bee7 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -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/) diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..021bb73 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in inny.gemspec +gemspec diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..34d5ccc --- /dev/null +++ b/LICENSE.txt @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..16031c3 --- /dev/null +++ b/README.md @@ -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). + diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..d6c5113 --- /dev/null +++ b/Rakefile @@ -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 diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..e0c5322 --- /dev/null +++ b/bin/console @@ -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 diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..b65ed50 --- /dev/null +++ b/bin/setup @@ -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 diff --git a/inny.gemspec b/inny.gemspec new file mode 100644 index 0000000..3ab2597 --- /dev/null +++ b/inny.gemspec @@ -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 diff --git a/lib/inny.rb b/lib/inny.rb new file mode 100644 index 0000000..ef3c41e --- /dev/null +++ b/lib/inny.rb @@ -0,0 +1,11 @@ +require "inny/version" + +module Inny + def in?(*list) + list.include?(self) + end +end + +class Object + include Inny +end diff --git a/lib/inny/version.rb b/lib/inny/version.rb new file mode 100644 index 0000000..0596b70 --- /dev/null +++ b/lib/inny/version.rb @@ -0,0 +1,3 @@ +module Inny + VERSION = "1.0.0" +end diff --git a/test/inny_test.rb b/test/inny_test.rb new file mode 100644 index 0000000..68df350 --- /dev/null +++ b/test/inny_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..9aec82f --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,4 @@ +$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +require 'inny' + +require 'minitest/autorun'