gists 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ .bundle
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.8.7-p249@gists
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source :rubygems
2
+
3
+ gem 'rake'
4
+
5
+ group :development do
6
+ gem 'jeweler'
7
+ end
8
+
9
+ group :test do
10
+ gem 'rspec'
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Bradley Grzesiak
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ = gists
2
+
3
+ Stupid little methods that probably should be in ruby core, but aren't.
4
+
5
+ = Installation
6
+
7
+ It's a gem. Install it how you want.
8
+
9
+ Bundler-enabled projects:
10
+ gem 'gists'
11
+ Other projects:
12
+ $ gem install gists
13
+ require 'gists'
14
+
15
+ == Note on Patches/Pull Requests
16
+
17
+ * Fork the project.
18
+ * Make your feature addition or bug fix.
19
+ * Add tests for it. This is important so I don't break it in a
20
+ future version unintentionally.
21
+ * Commit, do not mess with rakefile, version, or history.
22
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
23
+ * Send me a pull request. Bonus points for topic branches.
24
+
25
+ == Copyright
26
+
27
+ Copyright (c) 2010 Bradley Grzesiak. See LICENSE for details.
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require :default, :development, :test
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "gists"
9
+ gem.summary = %Q{A bunch of utility functions extracted from gists}
10
+ gem.description = %Q{Since gist.github.com is such a fantastic library of random utility functions, this gem is meant to collect the best and pull them into your everyday toolbox.}
11
+ gem.email = "brad@bendyworks.com"
12
+ gem.homepage = "http://github.com/listrophy/gists"
13
+ gem.authors = ["Bradley Grzesiak"]
14
+ gem.add_development_dependency "rspec", ">= 1.3.0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "gists #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{gists}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Bradley Grzesiak"]
12
+ s.date = %q{2010-07-31}
13
+ s.description = %q{Since gist.github.com is such a fantastic library of random utility functions, this gem is meant to collect the best and pull them into your everyday toolbox.}
14
+ s.email = %q{brad@bendyworks.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".rvmrc",
23
+ "Gemfile",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "gists.gemspec",
29
+ "lib/gists.rb",
30
+ "spec/in_spec.rb",
31
+ "spec/random_in_spec.rb",
32
+ "spec/spec.opts",
33
+ "spec/spec_helper.rb",
34
+ "spec/surround_spec.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/listrophy/gists}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.6}
40
+ s.summary = %q{A bunch of utility functions extracted from gists}
41
+ s.test_files = [
42
+ "spec/in_spec.rb",
43
+ "spec/random_in_spec.rb",
44
+ "spec/spec_helper.rb",
45
+ "spec/surround_spec.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
54
+ else
55
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,35 @@
1
+ module Kernel
2
+
3
+ # Pick a random value from the values passed in
4
+ #
5
+ # Parameters can be:
6
+ # * A list of arguments: <tt>random_in(1,2,3,4)</tt>
7
+ # * An enumerable: <tt>random_in([1,2,3,4])</tt> or <tt>random_in(1..4)</tt>
8
+ def random_in(a, *b)
9
+ b.any? ? [a, *b][rand(b.count+1)] : a.to_a[rand(a.count)]
10
+ end
11
+ end
12
+
13
+ class Object
14
+
15
+ # Converse of <tt>include?</tt>
16
+ #
17
+ # Example: <tt>Rails.env.in?(['development', 'test'])</tt>
18
+ def in? enumerable
19
+ enumerable.include? self
20
+ end
21
+ end
22
+
23
+ class String
24
+
25
+ # Normal use case:
26
+ #
27
+ # <tt>'foo'.surround('%') # returns: '%foo%'</tt>
28
+ #
29
+ # You can pass both sides, too
30
+ #
31
+ # <tt>'bar'.surround('<', '>')</tt>
32
+ def surround *args
33
+ args[0] + self + args[args.count == 1 ? 0 : 1]
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'Object#in?' do
4
+
5
+ context 'when self is in the enumerable' do
6
+
7
+ class Includes
8
+ include Enumerable
9
+ def include? *args
10
+ true
11
+ end
12
+ end
13
+
14
+ it 'returns true' do
15
+ self.in?(Includes.new).should be_true
16
+ end
17
+
18
+ end
19
+
20
+ context 'when self is not in the enumerable' do
21
+
22
+ class DoesNotInclude
23
+ include Enumerable
24
+ def include? *args
25
+ false
26
+ end
27
+ end
28
+
29
+ it 'returns false' do
30
+ self.in?(DoesNotInclude.new).should be_false
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'random_in' do
4
+
5
+ before do
6
+ self.should_receive(:rand).with(4).exactly(4).times.and_return(0, 1, 2, 3)
7
+ end
8
+
9
+ it 'works with arrays' do
10
+ (0..3).each do |expect|
11
+ random_in([0, 1, 2, 3]).should == expect
12
+ end
13
+ end
14
+
15
+ it 'works with parameter lists' do
16
+ (0..3).each do |expect|
17
+ random_in(0,1,2,3).should == expect
18
+ end
19
+ end
20
+
21
+ it 'works with ranges' do
22
+ (0..3).each do |expect|
23
+ random_in(0..3).should == expect
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'gists'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'String#surround' do
4
+
5
+ context 'given one arg' do
6
+ it 'surrounds the string with the arg' do
7
+ 'foo'.surround('bar').should == 'barfoobar'
8
+ end
9
+ end
10
+
11
+ context 'given two args' do
12
+ it 'prepends the first arg' do
13
+ 'bar'.surround('foo', 'baz').should match(/^foobar/)
14
+ end
15
+ it 'appends the second arg' do
16
+ 'bar'.surround('foo', 'baz').should match(/barbaz$/)
17
+ end
18
+ end
19
+
20
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gists
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Bradley Grzesiak
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-31 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :development
22
+ name: rspec
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 3
30
+ - 0
31
+ version: 1.3.0
32
+ requirement: *id001
33
+ prerelease: false
34
+ description: Since gist.github.com is such a fantastic library of random utility functions, this gem is meant to collect the best and pull them into your everyday toolbox.
35
+ email: brad@bendyworks.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.rdoc
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - .rvmrc
47
+ - Gemfile
48
+ - LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ - VERSION
52
+ - gists.gemspec
53
+ - lib/gists.rb
54
+ - spec/in_spec.rb
55
+ - spec/random_in_spec.rb
56
+ - spec/spec.opts
57
+ - spec/spec_helper.rb
58
+ - spec/surround_spec.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/listrophy/gists
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.6
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: A bunch of utility functions extracted from gists
89
+ test_files:
90
+ - spec/in_spec.rb
91
+ - spec/random_in_spec.rb
92
+ - spec/spec_helper.rb
93
+ - spec/surround_spec.rb