bonk 0.0.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.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ syntax: glob
2
+
3
+ *.gem
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/.hgignore ADDED
@@ -0,0 +1,19 @@
1
+ syntax: glob
2
+
3
+ *.gem
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bonk.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 Steven! Ragnarök
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.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Bonk
2
+
3
+ *Why is it called bonk?* __Because it's a really hard tap.__
4
+
5
+ Bonk is a gem which adds the super cool bonk method to Ruby's `Object` class.
6
+ It can be thought of as `#map` for individual objects or a really hard `#tap`.
7
+ The semantics of Bonk are identical to `[object].map{|o| ... }.first` but
8
+ without all that tedious mucking about in hyperspace.
9
+
10
+ Why would you bother using bonk?
11
+
12
+ - I dunno, I just like to avoid unnecessary temporary variables.
13
+ - Bonk came about because I wanted to take an ActiveRecord model and send
14
+ them through a reporting script I wrote that took hashes of information. I tried
15
+ to do the transformation inline but realized that what I wanted, `#map` for
16
+ `Object`, didn't exist. So I made it using ___the power of Ruby___.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'bonk'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install bonk
31
+
32
+ ## Usage
33
+
34
+ ```ruby
35
+ Project.find(42).owner.bonk do |o|
36
+ { :id => o.id, :name => o.realname,
37
+ :problem => "Never updated credit card information." }
38
+ end
39
+ ```
40
+
41
+ ## Disclaimer
42
+
43
+ Don't trust this gem with nuclear submarine controls. I seriously conceived it
44
+ and wrote it over two train rides after a late night conversation with my none
45
+ too amused girlfriend.
46
+
47
+ ## Contributing
48
+
49
+ 1. File an issue explaining the semantics of your proposed extension.
50
+ 1. Get it approved or make your own simple gem.
51
+ 1. Fork it on [GitHub] or [BitBucket].
52
+ 2. Create your feature branch.
53
+ 3. Commit your changes.
54
+ 4. Push to the branch.
55
+ 5. Create a new Pull Request.
56
+
57
+ [GitHub]: https://github.com/nuclearsandwich/bonk
58
+ [BitBucket]: http://bitbucket.org/nuclearsandwich/bonk
59
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bonk.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bonk/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Steven! Ragnarök"]
6
+ gem.email = ["steven@nuclearsandwich.com"]
7
+ gem.description = <<EOF
8
+ A simple RubyGem which adds the method Object#bonk. Bonk imitiates the semantics
9
+ of Enumerable#map but for solitary objects.
10
+ EOF
11
+ gem.summary = %q{A really hard #tap. Bonk is Enumerable#map for Object.}
12
+ gem.homepage = "http://code.nuclearsandwich.com/bonk/overview"
13
+
14
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ gem.name = "bonk"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = Bonk::VERSION
20
+ gem.add_development_dependency 'minitest', '~>2.8.1'
21
+ end
data/lib/bonk.rb ADDED
@@ -0,0 +1,11 @@
1
+ require_relative "bonk/version"
2
+
3
+ module Bonk
4
+ module Bonk::InstanceMethods
5
+ def bonk
6
+ yield self
7
+ end
8
+ end
9
+
10
+ ::Object.send :include, Bonk::InstanceMethods
11
+ end
@@ -0,0 +1,3 @@
1
+ module Bonk
2
+ VERSION = "0.0.1"
3
+ end
data/test/bonk_test.rb ADDED
@@ -0,0 +1,33 @@
1
+ require "minitest/autorun"
2
+ require "./lib/bonk"
3
+
4
+ class BonkTest < MiniTest::Unit::TestCase
5
+ def setup
6
+ @object = Object.new
7
+ end
8
+
9
+ def test_object_responds_to_bonk
10
+ assert_respond_to @object, :bonk
11
+ end
12
+
13
+ def test_bonk_passes_in_its_callee
14
+ temp_obj = :didnt_run
15
+ @object.bonk do |obj|
16
+ temp_obj = obj
17
+ end
18
+
19
+ assert_equal @object, temp_obj
20
+ end
21
+
22
+ def test_bonk_returns_the_value_of_the_block
23
+ assert_equal :funky_monkey, @object.bonk{ :funky_monkey }
24
+ end
25
+
26
+ def test_bonk_does_replace_its_callee
27
+ obj_id = @object.object_id
28
+ @object.bonk{ |o| o = :a_funkier_monkey_than_ever }
29
+
30
+ assert_equal obj_id, @object.object_id
31
+ end
32
+ end
33
+
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bonk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steven! Ragnarök
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: &2161457180 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.8.1
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2161457180
25
+ description: ! 'A simple RubyGem which adds the method Object#bonk. Bonk imitiates
26
+ the semantics
27
+
28
+ of Enumerable#map but for solitary objects.
29
+
30
+ '
31
+ email:
32
+ - steven@nuclearsandwich.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .hgignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - bonk.gemspec
44
+ - lib/bonk.rb
45
+ - lib/bonk/version.rb
46
+ - test/bonk_test.rb
47
+ homepage: http://code.nuclearsandwich.com/bonk/overview
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.10
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: ! 'A really hard #tap. Bonk is Enumerable#map for Object.'
71
+ test_files:
72
+ - test/bonk_test.rb