hobosupport 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,5 +1,12 @@
1
1
  require 'echoe'
2
2
 
3
+ namespace "test" do
4
+ desc "Run the doctests"
5
+ task :doctest do |t|
6
+ exit(1) if !system("rubydoctest test/*.rdoctest test/hobosupport/*.rdoctest")
7
+ end
8
+ end
9
+
3
10
  Echoe.new('hobosupport') do |p|
4
11
  p.author = "Tom Locke"
5
12
  p.email = "tom@tomlocke.com"
@@ -8,7 +15,7 @@ Echoe.new('hobosupport') do |p|
8
15
  p.project = "hobo"
9
16
 
10
17
  p.changelog = "CHANGES.txt"
11
- p.version = "0.8.5"
18
+ p.version = "0.8.6"
12
19
 
13
20
  p.development_dependencies = []
14
21
  end
data/hobosupport.gemspec CHANGED
@@ -1,103 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
1
2
 
2
- # Gem::Specification for Hobosupport-0.8.5
3
- # Originally generated by Echoe
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{hobosupport}
5
+ s.version = "0.8.6"
4
6
 
5
- --- !ruby/object:Gem::Specification
6
- name: hobosupport
7
- version: !ruby/object:Gem::Version
8
- version: 0.8.5
9
- platform: ruby
10
- authors:
11
- - Tom Locke
12
- autorequire:
13
- bindir: bin
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Tom Locke"]
9
+ s.date = %q{2009-05-14}
10
+ s.description = %q{Core Ruby extensions from the Hobo project}
11
+ s.email = %q{tom@tomlocke.com}
12
+ s.extra_rdoc_files = ["lib/hobo_support/array.rb", "lib/hobo_support/blankslate.rb", "lib/hobo_support/enumerable.rb", "lib/hobo_support/fixes/chronic.rb", "lib/hobo_support/fixes/module.rb", "lib/hobo_support/fixes/pp.rb", "lib/hobo_support/fixes.rb", "lib/hobo_support/hash.rb", "lib/hobo_support/implies.rb", "lib/hobo_support/metaid.rb", "lib/hobo_support/methodcall.rb", "lib/hobo_support/methodphitamine.rb", "lib/hobo_support/module.rb", "lib/hobo_support/string.rb", "lib/hobo_support.rb", "lib/hobosupport.rb", "README.txt"]
13
+ s.files = ["CHANGES.txt", "lib/hobo_support/array.rb", "lib/hobo_support/blankslate.rb", "lib/hobo_support/enumerable.rb", "lib/hobo_support/fixes/chronic.rb", "lib/hobo_support/fixes/module.rb", "lib/hobo_support/fixes/pp.rb", "lib/hobo_support/fixes.rb", "lib/hobo_support/hash.rb", "lib/hobo_support/implies.rb", "lib/hobo_support/metaid.rb", "lib/hobo_support/methodcall.rb", "lib/hobo_support/methodphitamine.rb", "lib/hobo_support/module.rb", "lib/hobo_support/string.rb", "lib/hobo_support.rb", "lib/hobosupport.rb", "Manifest", "Manifest.txt", "Rakefile", "README.txt", "test/hobosupport/enumerable.rdoctest", "test/hobosupport/hash.rdoctest", "test/hobosupport/implies.rdoctest", "test/hobosupport/metaid.rdoctest", "test/hobosupport/methodphitamine.rdoctest", "test/hobosupport/module.rdoctest", "test/hobosupport.rdoctest", "hobosupport.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://hobocentral.net/hobosupport}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Hobosupport", "--main", "README.txt"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{hobo}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Core Ruby extensions from the Hobo project}
14
21
 
15
- date: 2008-12-09 00:00:00 +00:00
16
- default_executable:
17
- dependencies: []
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
18
25
 
19
- description: Core Ruby extensions from the Hobo project
20
- email: tom@tomlocke.com
21
- executables: []
22
-
23
- extensions: []
24
-
25
- extra_rdoc_files:
26
- - lib/hobo_support/array.rb
27
- - lib/hobo_support/blankslate.rb
28
- - lib/hobo_support/enumerable.rb
29
- - lib/hobo_support/fixes/chronic.rb
30
- - lib/hobo_support/fixes/module.rb
31
- - lib/hobo_support/fixes/pp.rb
32
- - lib/hobo_support/fixes.rb
33
- - lib/hobo_support/hash.rb
34
- - lib/hobo_support/implies.rb
35
- - lib/hobo_support/metaid.rb
36
- - lib/hobo_support/methodcall.rb
37
- - lib/hobo_support/methodphitamine.rb
38
- - lib/hobo_support/module.rb
39
- - lib/hobo_support/string.rb
40
- - lib/hobo_support.rb
41
- - lib/hobosupport.rb
42
- - README.txt
43
- files:
44
- - CHANGES.txt
45
- - lib/hobo_support/array.rb
46
- - lib/hobo_support/blankslate.rb
47
- - lib/hobo_support/enumerable.rb
48
- - lib/hobo_support/fixes/chronic.rb
49
- - lib/hobo_support/fixes/module.rb
50
- - lib/hobo_support/fixes/pp.rb
51
- - lib/hobo_support/fixes.rb
52
- - lib/hobo_support/hash.rb
53
- - lib/hobo_support/implies.rb
54
- - lib/hobo_support/metaid.rb
55
- - lib/hobo_support/methodcall.rb
56
- - lib/hobo_support/methodphitamine.rb
57
- - lib/hobo_support/module.rb
58
- - lib/hobo_support/string.rb
59
- - lib/hobo_support.rb
60
- - lib/hobosupport.rb
61
- - Manifest
62
- - Manifest.txt
63
- - Rakefile
64
- - README.txt
65
- - test/hobosupport/enumerable.rdoctest
66
- - test/hobosupport/hash.rdoctest
67
- - test/hobosupport/implies.rdoctest
68
- - test/hobosupport/metaid.rdoctest
69
- - test/hobosupport/methodphitamine.rdoctest
70
- - test/hobosupport/module.rdoctest
71
- - test/hobosupport.rdoctest
72
- - hobosupport.gemspec
73
- has_rdoc: true
74
- homepage: http://hobocentral.net/hobosupport
75
- post_install_message:
76
- rdoc_options:
77
- - --line-numbers
78
- - --inline-source
79
- - --title
80
- - Hobosupport
81
- - --main
82
- - README.txt
83
- require_paths:
84
- - lib
85
- required_ruby_version: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: "0"
90
- version:
91
- required_rubygems_version: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: "1.2"
96
- version:
97
- requirements: []
98
-
99
- rubyforge_project: hobo
100
- rubygems_version: 1.3.1
101
- specification_version: 2
102
- summary: Core Ruby extensions from the Hobo project
103
- test_files: []
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
@@ -9,14 +9,26 @@ require 'delegate'
9
9
  require 'singleton'
10
10
  require 'blankslate'
11
11
 
12
+ module HoboSupport
13
+ def self.hobo_try(this, *args, &block)
14
+ if args.length==0
15
+ # Hobo style try
16
+ CallIfAvailable.new(this)
17
+ else
18
+ # activesupport 2.3 style try
19
+ this.send(*args, &block)
20
+ end
21
+ end
22
+ end
23
+
12
24
  class Object
13
25
 
14
26
  def _?()
15
27
  self
16
28
  end
17
29
 
18
- def try
19
- CallIfAvailable.new(self)
30
+ def try(*args, &block)
31
+ HoboSupport.hobo_try(self, *args, &block)
20
32
  end
21
33
 
22
34
  end
@@ -26,6 +38,18 @@ class NilClass
26
38
  def _?()
27
39
  SafeNil.instance
28
40
  end
41
+
42
+
43
+ def try(*args)
44
+ if args.length==0
45
+ # Hobo style try
46
+ CallIfAvailable.new(self)
47
+ else
48
+ # activesupport 2.3 style try
49
+ nil
50
+ end
51
+ end
52
+
29
53
  end
30
54
 
31
55
 
@@ -63,4 +87,14 @@ class CallIfAvailable < BlankSlate
63
87
 
64
88
  end
65
89
 
90
+ module ActiveRecord
91
+ module Associations
92
+ class AssociationProxy
66
93
 
94
+ # we need to make sure we don't trigger AssociationCollections' method_missing
95
+ def try(*args, &block)
96
+ HoboSupport.hobo_try(self, *args, &block)
97
+ end
98
+ end
99
+ end
100
+ end
data/lib/hobo_support.rb CHANGED
@@ -1,18 +1,16 @@
1
1
  module HoboSupport
2
2
 
3
- VERSION = "0.8.5"
3
+ VERSION = "0.8.6"
4
4
 
5
5
  end
6
6
 
7
7
 
8
- # Some teeny fixes too diminutive to go elsewhere
8
+ # Some teeny bit and bobs too diminutive to go elsewhere
9
9
 
10
10
  class Object
11
11
 
12
- # Often nice to ask e.g. some_object.is_a?(Symbol, String)
13
- alias_method :is_a_without_multiple_args?, :is_a?
14
- def is_a?(*args)
15
- args.any? {|a| is_a_without_multiple_args?(a) }
12
+ def is_one_of?(*args)
13
+ args.any? {|a| is_a?(a) }
16
14
  end
17
15
 
18
16
  end
@@ -53,4 +51,4 @@ module Kernel
53
51
  args.first
54
52
  end
55
53
 
56
- end
54
+ end
@@ -1,6 +1,6 @@
1
1
  # HoboSupport - Eumerable extensions
2
2
 
3
- >> require 'hobosupport'
3
+ doctest_require: '../../lib/hobosupport'
4
4
 
5
5
  ## `Enumerable#map_and_find`
6
6
 
@@ -117,6 +117,8 @@ Shorthand for `enum.include?(obj)`
117
117
 
118
118
  * `obj.not_in?(enum)`
119
119
 
120
+ Negation of `in?`
121
+
120
122
  >> 3.not_in?(0..10)
121
123
  => false
122
124
  >> 300.not_in?(0..10)
@@ -1,6 +1,7 @@
1
1
  # HoboSupport - Hash extensions
2
2
 
3
- >> require 'hobosupport'
3
+ doctest_require: '../../lib/hobosupport'
4
+ {.hidden}
4
5
 
5
6
  ## `Hash#select_hash`
6
7
 
@@ -1,6 +1,7 @@
1
1
  # HoboSupport - implies
2
2
 
3
- >> require 'hobosupport'
3
+ doctest_require: '../../lib/hobosupport'
4
+ {.hidden}
4
5
 
5
6
  The implies operator comes from Eiffel. Often comes in handy in Hobo's model-permission methods.
6
7
 
@@ -1,6 +1,7 @@
1
1
  # HoboSupport - Metaid
2
2
 
3
- >> require 'hobosupport'
3
+ doctest_require: '../../lib/hobosupport'
4
+ {.hidden}
4
5
 
5
6
  Why the Luck Stiff's essential meta-programming additions to Object. These are probably distributed elsewhere, but they're small enough to throw them in to HoboSupport and remove an external dependency.
6
7
 
@@ -1,6 +1,7 @@
1
1
  # HoboSupport - Methodphitamine
2
2
 
3
- >> require 'hobosupport'
3
+ doctest_require: '../../lib/hobosupport'
4
+ {.hidden}
4
5
 
5
6
  ## `Kernel#it` and `Kernel#its`
6
7
 
@@ -1,6 +1,7 @@
1
1
  # HoboSupport - Module extensions
2
2
 
3
- >> require 'hobosupport'
3
+ doctest_require: '../../lib/hobosupport'
4
+ {.hidden}
4
5
 
5
6
  ## `Module#included_in_class_callbacks`
6
7
 
@@ -13,30 +14,30 @@ When a module is included in a class, it gets a callback on the `included` metho
13
14
  (Note we're using the metaid extensions here too)
14
15
 
15
16
  >>
16
- module M2
17
- def self.included_in_class(klass)
18
- klass.metaclass_eval do
19
- def name_with_shouting; name_without_shouting.upcase; end
20
- alias_method_chain :name, :shouting
21
- end
22
- end
23
- end
24
-
25
- module M1
26
- def self.included(base)
27
- included_in_class_callbacks(base)
28
- end
29
- include M2
30
- end
31
-
32
- class C
33
- def self.name
34
- "my name is C"
35
- end
36
- include M1
37
- end
38
-
39
- C.name
17
+ module M2
18
+ def self.included_in_class(klass)
19
+ klass.metaclass_eval do
20
+ def name_with_shouting; name_without_shouting.upcase; end
21
+ alias_method_chain :name, :shouting
22
+ end
23
+ end
24
+ end
25
+
26
+ module M1
27
+ def self.included(base)
28
+ included_in_class_callbacks(base)
29
+ end
30
+ include M2
31
+ end
32
+
33
+ class C
34
+ def self.name
35
+ "my name is C"
36
+ end
37
+ include M1
38
+ end
39
+
40
+ C.name
40
41
  => "MY NAME IS C"
41
42
 
42
43
 
@@ -45,11 +46,11 @@ When a module is included in a class, it gets a callback on the `included` metho
45
46
  Declares a reader for an instance variable on the class. The attribute is looked up on the superclass if not defined on the receiving class. In other words, the superclass defines a default that subclasses can override. The declaration can also give a default, as shown here.
46
47
 
47
48
  >>
48
- class A
49
- inheriting_cattr_reader :nickname => "Andy"
50
- end
49
+ class A
50
+ inheriting_cattr_reader :nickname => "Andy"
51
+ end
51
52
 
52
- class B < A; end
53
+ class B < A; end
53
54
 
54
55
  `B` has the same nickname as its superclass `A`
55
56
 
@@ -72,17 +73,17 @@ Now we change the nickname of `B`. `A` retains it's existing nickname.
72
73
  In Ruby we use modules to factor out features that are shared by more than one class. By including the module, a class gets the module's features, just as if they were defined inside the class. This mechanism is very simple if the shared features are all instance methods, but starts to get complicated when we want to share class-level features. For example, to create a module that adds class-methods to the including class, Ruby programmers often use the ClassMethods sub-module idiom:
73
74
 
74
75
  >>
75
- module M
76
- def self.included(base)
77
- base.send(:extend, ClassMethods)
78
- end
76
+ module M
77
+ def self.included(base)
78
+ base.send(:extend, ClassMethods)
79
+ end
79
80
 
80
- module ClassMethods
81
- def foo; 123; end
82
- end
83
- end
81
+ module ClassMethods
82
+ def foo; 123; end
83
+ end
84
+ end
84
85
 
85
- class C; include M; end
86
+ class C; include M; end
86
87
 
87
88
  >> C.foo
88
89
  => 123
@@ -92,11 +93,11 @@ It's a shame that such a basic capability isn't more declarative.
92
93
  `classy_module` provides a mechanism for creating a module that, when included, will `class_eval` it's entire body (the block passed to `classy_module`). This means we can write shared class features exactly as we would write them if they were inside the class:
93
94
 
94
95
  >>
95
- MyClassyModule = classy_module do
96
+ MyClassyModule = classy_module do
96
97
 
97
- def self.foo; 123; end
98
+ def self.foo; 123; end
98
99
 
99
- end
100
+ end
100
101
 
101
102
  >> MyClassyModule.class
102
103
  => Module
@@ -4,40 +4,34 @@ HoboSupport is a mixed bag of core ruby extensions that have been extracted from
4
4
 
5
5
  [Hobo]: http://hobocentral.net
6
6
 
7
- >> require 'hobosupport'
7
+ doctest_require: '../lib/hobosupport'
8
+ {.hidden}
9
+
8
10
  >> HoboSupport::VERSION
9
- => "0.7.5"
11
+ => "0.8.6"
10
12
 
11
13
  ## Contents
12
14
 
13
- * [Enumerable](/hobosupport/hobosupport/enumerable/)
14
- * [Hash](/hobosupport/hobosupport/hash/)
15
- * [Implies](/hobosupport/hobosupport/implies/)
16
- * [Metaid](/hobosupport/hobosupport/metaid/)
17
- * [Methodphitamine](/hobosupport/hobosupport/methodphitamine)
18
- * [Module](/hobosupport/hobosupport/module)
15
+ * [Enumerable](/manual/hobosupport/enumerable)
16
+ * [Hash](/manual/hobosupport/hash)
17
+ * [Implies](/manual/hobosupport/implies)
18
+ * [Metaid](/manual/hobosupport/metaid)
19
+ * [Methodphitamine](/manual/hobosupport/methodphitamine)
20
+ * [Module](/manual/hobosupport/module)
19
21
 
20
22
  ## Object extensions
21
23
 
22
- ### `Object#is_a?`
24
+ ### `Object#is_one_of?`
23
25
 
24
- Extended to allow multiple types to be checked in one go
26
+ Like `is_a?` but multiple types to be checked in one go
25
27
 
26
- >> "foo".is_a?(String, Symbol)
27
- => true
28
- >> :foo.is_a?(String, Symbol)
28
+ >> "foo".is_one_of?(String, Symbol)
29
29
  => true
30
- >> 1.is_a?(String, Symbol)
31
- => false
32
-
33
- Still works the old way
34
-
35
- >> "foo".is_a?(String)
30
+ >> :foo.is_one_of?(String, Symbol)
36
31
  => true
37
- >> :foo.is_a?(String)
32
+ >> 1.is_one_of?(String, Symbol)
38
33
  => false
39
34
 
40
-
41
35
  ## Method call extensions
42
36
 
43
37
  ### `Object#_?`
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobosupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Locke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-09 00:00:00 +00:00
12
+ date: 2009-05-14 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15