bendy 0.2.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4306a2e20ac95b53a3164c99bda7a90d666f6395
4
+ data.tar.gz: b367e2b8e13d80b269aed5251652267a21f0cece
5
+ SHA512:
6
+ metadata.gz: f5a493b98829a08b8b9f4a8a4cbdd584f0a5b6575d820b3b968e52e3f9861d9025a957f07a4dddc1aaffd23c6bc666afd2bcaf5f51ec81dcea71ebe82b023ff2
7
+ data.tar.gz: 4411425b820fdd4e065db60ef52cb552315bbacdae5d6304304e5a1cd919e898e76d57077382e52724fd92d8e8b4162f38d4b1e822fc45cc4598b5b746c82b2c
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bendy.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Chris Wilson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # Bendy
2
+
3
+ This is a collection of helpful utilities in use at Bendyworks.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bendy'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bendy
18
+
19
+ ## Usage
20
+
21
+ Since this gem includes many different facets (see what I... nevermind) you
22
+ are best off reading the code for things that catch your eye.
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it ( http://github.com/<my-github-username>/bendy/fork )
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
@@ -0,0 +1,17 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ task default: [:test]
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs.push 'lib'
9
+ t.test_files = FileList['spec/**/*_spec.rb']
10
+ t.verbose = true
11
+ end
12
+
13
+ RDoc::Task.new do |rdoc|
14
+ rdoc.rdoc_files.include("README.md", "lib/**/*.rb")
15
+ rdoc.options << '--format=bootstrap'
16
+ rdoc.options << '--markup=markdown'
17
+ end
@@ -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 'bendy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bendy"
8
+ spec.version = Bendy::VERSION
9
+ spec.authors = ["Chris Wilson", "Will Strinz"]
10
+ spec.email = ["chris@bendyworks.com"]
11
+ spec.summary = %q{A collection of helpful libraries}
12
+ spec.description = %q{This gem is a cornucopia of software bric-à-brac, for great justice}
13
+ spec.homepage = "https://github.com/twopoint718/bendygem"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake", "< 11"
23
+
24
+ spec.required_ruby_version = '>= 2.0.0'
25
+ end
@@ -0,0 +1,10 @@
1
+ require "bendy/version"
2
+
3
+ ##
4
+ # The Bendy library of useful code and odds and ends. These snippets of
5
+ # code have been useful to the Bendyworks team at times and so are
6
+ # collected here for ease of use. Please see individual docs for more
7
+ # information on usage.
8
+
9
+ module Bendy
10
+ end
@@ -0,0 +1,31 @@
1
+ ##
2
+ # We're using refinements to *freedom patch* `Array` in a safe way.
3
+
4
+ module Bendy
5
+
6
+
7
+ refine Array do
8
+
9
+ ##
10
+ # `tails` produces all sub-arrays by successively dropping leading
11
+ # elements:
12
+ #
13
+ # [1, 2, 3].tails
14
+ # # => [[1, 2, 3], [2, 3], [3], []]
15
+
16
+ def tails
17
+ (self.length + 1).times.map{ |i| self.drop(i) }
18
+ end
19
+
20
+ ##
21
+ # `inits` produces all sub-arrays by successively taking leading
22
+ # elements:
23
+ #
24
+ # [1, 2, 3].tails
25
+ # # => [[], [1], [1, 2], [1, 2, 3]]</tt>
26
+
27
+ def inits
28
+ (self.length + 1).times.map{ |i| self.take(i) }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ module Bendy
2
+
3
+ ##
4
+ # Some logical methods
5
+
6
+ module Logical
7
+
8
+ ##
9
+ # Material implication
10
+ # `implies` is the common case where if the first thing is true, then pay
11
+ # attention to the second thing. But if the first thing is false then the
12
+ # whole thing is true: `implies(foo, foo[:bar])`
13
+
14
+ def implies(p)
15
+ !!p ? yield : true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ module Bendy
2
+ refine Object do
3
+
4
+ ##
5
+ # `try` acts like a normal method call, unless it is being called
6
+ # on a nil object, in which case it returns nil:
7
+ #
8
+ # nil.try(:to_i) # => nil
9
+ # "10".try(:to_i) # => 10
10
+ #
11
+ # Copied pretty much verbatim from ActiveSupport: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/try.rb
12
+
13
+ def try(*a, &b)
14
+ if a.empty? && block_given?
15
+ yield self
16
+ else
17
+ public_send(*a, &b) if respond_to?(a.first)
18
+ end
19
+ end
20
+ end
21
+
22
+ refine NilClass do
23
+ def try(*args)
24
+ nil
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Bendy
2
+ VERSION = "0.2.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'bendy/array'
4
+
5
+ using Bendy
6
+
7
+ describe Array do
8
+ before do
9
+ @array = [1, 2, 3]
10
+ end
11
+
12
+ describe 'Array#tails' do
13
+ it 'produces all sub-arrays by dropping successive elements' do
14
+ @array.tails.must_equal [[1, 2, 3], [2, 3], [3], []]
15
+ end
16
+ end
17
+
18
+ describe 'Array#inits' do
19
+ it 'produces all sub-arrays by taking successive elements' do
20
+ @array.inits.must_equal [[], [1], [1, 2], [1, 2, 3]]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'bendy/logical'
4
+
5
+ describe Bendy::Logical do
6
+ describe '#implies' do
7
+ include Bendy::Logical
8
+
9
+ it 'true -> false = false' do
10
+ implies(true){false}.must_equal false
11
+ end
12
+
13
+ it 'true -> true = true' do
14
+ implies(true){true}.must_equal true
15
+ end
16
+
17
+ it 'false -> true = true' do
18
+ implies(false){true}.must_equal true
19
+ end
20
+
21
+ it 'false -> false = true' do
22
+ implies(false){false}.must_equal true
23
+ end
24
+
25
+ it 'you can use the value of the second argument' do
26
+ implies(true){:yeah}.must_equal :yeah
27
+ end
28
+
29
+ it 'here is a more realistic example' do
30
+ foo = { bar: 1 }
31
+ implies(foo){foo[:bar]}.must_equal 1
32
+ end
33
+
34
+ it 'here is a more realistic example' do
35
+ foo = nil
36
+ implies(foo){foo[:bar]}.must_equal true
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'bendy/object'
4
+
5
+ using Bendy
6
+
7
+ describe Object do
8
+ describe 'Object#try' do
9
+ it 'returns nil when called on a nil value' do
10
+ nil.try(:to_i).must_equal nil
11
+ end
12
+
13
+ it 'calls public method for passed symbol on normal values' do
14
+ "1".try(:to_i).must_equal 1
15
+ end
16
+
17
+ it 'block syntax' do
18
+ [1, 2, 3].try(:map){ |v| v + 1 }.must_equal [2, 3, 4]
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bendy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Wilson
8
+ - Will Strinz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-06-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.5'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "<"
33
+ - !ruby/object:Gem::Version
34
+ version: '11'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "<"
40
+ - !ruby/object:Gem::Version
41
+ version: '11'
42
+ description: This gem is a cornucopia of software bric-à-brac, for great justice
43
+ email:
44
+ - chris@bendyworks.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bendy.gemspec
55
+ - lib/bendy.rb
56
+ - lib/bendy/array.rb
57
+ - lib/bendy/logical.rb
58
+ - lib/bendy/object.rb
59
+ - lib/bendy/version.rb
60
+ - spec/bendy/array_spec.rb
61
+ - spec/bendy/logical_spec.rb
62
+ - spec/bendy/object_spec.rb
63
+ homepage: https://github.com/twopoint718/bendygem
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.0
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.2.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: A collection of helpful libraries
87
+ test_files:
88
+ - spec/bendy/array_spec.rb
89
+ - spec/bendy/logical_spec.rb
90
+ - spec/bendy/object_spec.rb