despite 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e7742645cd82797b3a01f027ae0271cc1211892
4
+ data.tar.gz: c5bc1d6d93411ad76e39dadf3e96b86f84187f30
5
+ SHA512:
6
+ metadata.gz: ef4f810b695b20b5f984bbd3b5a71758d9ca91ba1da7fcacaff1623445b7d23c6aa2cc5c8c87b015011e160aba0c65550a541ad8b96d5de083730a67c1afd356
7
+ data.tar.gz: eca685cda12400634230ad1269d07591e688a363df1c8ac2e94f826348e96a134475288a8aef746bc7ec0c71f017c9211aa0a8399debbb0e76fe007208aa0c96
@@ -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
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.3.0
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.3
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rubocop'
7
+ end
8
+
9
+ group :development, :test do
10
+ gem 'rspec'
11
+ gem 'rake'
12
+ end
13
+
14
+ group :test do
15
+ gem 'codeclimate-test-reporter', require: false
16
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nikita Chernukhin
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.
@@ -0,0 +1,92 @@
1
+ # Despite
2
+ [![Build Status](https://travis-ci.org/Nu-hin/despite.svg?branch=master)](https://travis-ci.org/Nu-hin/despite)
3
+ [![Code Climate](https://codeclimate.com/github/Nu-hin/despite/badges/gpa.svg)](https://codeclimate.com/github/Nu-hin/despite)
4
+ [![Test Coverage](https://codeclimate.com/github/Nu-hin/despite/badges/coverage.svg)](https://codeclimate.com/github/Nu-hin/despite/coverage)
5
+
6
+ This gem introduces new advanced verbose flow-control operators to Ruby language.
7
+
8
+ ## Description
9
+
10
+ Have you ever been shown a git blame output with your name and a question: _"What will happen if this is nil?"_ or _"Have you thought of the case when there are no orders for a customer?"_ or _"What if they haven't entered their mobile phone?"_.
11
+
12
+ This gem is designed to stop these stupid questions forever. With `despite` and `even_if` operators introduced by it, is has finally became possible to explicitly and verbosely designate pieces of code you are aware to be faulty as well as to show you don't give a fuck.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'despite'
20
+ ```
21
+
22
+ Or, if you would like just to install this gem globally, execute:
23
+ ```bash
24
+ gem install despite
25
+ ```
26
+
27
+ ## Usage
28
+ The purpose of the `despite` operator is to explicitly demonstrate, that you are aware of some problem or potential error, but you are conciously ignoring it and its possible negative consequences.
29
+
30
+ The `despite` operator accepts an expression and a block. If expression evaluates to `true` the block is executed and the result of the block is returned.
31
+
32
+ The typical usage would be:
33
+ ```ruby
34
+ # Divide by zero openly and proudly
35
+ y = 0
36
+
37
+ despite y == 0 do
38
+ #ZeroDivisionError is raised
39
+ puts x / y
40
+ end
41
+ ```
42
+
43
+ If no block is passed, the operator will return the result of the expression:
44
+
45
+ ```ruby
46
+ x = despite(5) # x == 5
47
+ ```
48
+
49
+ Thus it is possible to chain `despite` calls:
50
+
51
+ ```ruby
52
+ share = nil
53
+
54
+ despite(users.count == 0) && despite(total_income.nil?) do
55
+ # Dividing nil by zero!
56
+ avg_income = total_income / users.count
57
+ end
58
+ ```
59
+
60
+ The `despite` operator is designed to be used only with true expressions. By using it, you are saying: _"Yes, I know that the X is true, but despite that I am going to do Y."_ Thus, if the condition evaluates to `false`, it is considered to be an error in the code, and `Despite::AssertionError` exception is raised.
61
+
62
+ ```ruby
63
+ user.name = 'Donald'
64
+
65
+ # Despite::AssertionError
66
+ despite user.name.nil? do
67
+ puts user.name
68
+ end
69
+ ```
70
+
71
+ However, this behavior is not always desired. Sometimes you cannot be sure the problem is there, but you still would like to demonstrate, that you are aware of the possible negative outcome. For this, `even_if` operator is provided.
72
+
73
+ The usage of `even_if` operator is similar to that of the `despite` operator, except for it doesn't check the value of the condition, and thus the block passed is executed __no matter what__ the condition is.
74
+
75
+ With `even_if` operator you are saying: _"Yes, I am aware that there might be some problem, but I am going to execute this code whatsoever."_
76
+
77
+ ```ruby
78
+ # This even may occasionally work!
79
+ sale_price = even_if product.nil? do
80
+ product.price * 0.95
81
+ end
82
+ ```
83
+
84
+ ## Contributing
85
+
86
+ Feature requests and bug reports are welcome here at GitHub. However if you want to contribute, make sure your pull request passes all the tests, and the new features are 100% covered by tests too. Also make sure you have no warnings with the default [Rubocop](https://github.com/bbatsov/rubocop) configuration. We are aimed to the highest coding standards only!
87
+
88
+
89
+ ## License
90
+
91
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
92
+
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'despite'
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
@@ -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,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'despite/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'despite'
8
+ spec.version = Despite::VERSION
9
+ spec.authors = ['Nikita Chernukhin']
10
+ spec.email = ['nuinuhin@gmail.com']
11
+
12
+ spec.summary = 'Advanced verbose flow control operators for Ruby'
13
+ spec.description = <<-EOF
14
+ This gem introduces 'despite' and 'even_if' flow control operators to
15
+ explicitly designate faulty pieces of code and proudly and openly ignore
16
+ the possible problems.
17
+ EOF
18
+
19
+ spec.homepage = 'https://github.com/nu-hin/despite'
20
+ spec.license = 'MIT'
21
+
22
+ git_files = `git ls-files -z`.split("\x0")
23
+ spec.files = git_files.reject { |f| f.match(%r{^spec/}) }
24
+ spec.require_paths = ['lib']
25
+ end
@@ -0,0 +1,18 @@
1
+ require 'despite/version'
2
+
3
+ # Encapsulates new operator methods which are later included in
4
+ # the global context
5
+ module Despite
6
+ AssertionError = Class.new(StandardError)
7
+
8
+ def even_if(expression)
9
+ block_given? ? yield : expression
10
+ end
11
+
12
+ def despite(expression)
13
+ raise AssertionError unless expression
14
+ block_given? ? yield : expression
15
+ end
16
+ end
17
+
18
+ include Despite
@@ -0,0 +1,3 @@
1
+ module Despite
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: despite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikita Chernukhin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |2
14
+ This gem introduces 'despite' and 'even_if' flow control operators to
15
+ explicitly designate faulty pieces of code and proudly and openly ignore
16
+ the possible problems.
17
+ email:
18
+ - nuinuhin@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ".gitignore"
24
+ - ".rspec"
25
+ - ".ruby-version"
26
+ - ".travis.yml"
27
+ - Gemfile
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - bin/console
32
+ - bin/setup
33
+ - despite.gemspec
34
+ - lib/despite.rb
35
+ - lib/despite/version.rb
36
+ homepage: https://github.com/nu-hin/despite
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.5.1
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Advanced verbose flow control operators for Ruby
60
+ test_files: []