hobosupport 0.8.10 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +17 -18
- data/lib/hobo_support.rb +1 -1
- data/lib/hobo_support/array.rb +18 -0
- data/lib/hobo_support/hash.rb +4 -0
- data/lib/hobo_support/module.rb +26 -12
- data/test/hobosupport.rdoctest +1 -1
- metadata +2 -2
data/Rakefile
CHANGED
@@ -2,30 +2,29 @@ require 'activerecord'
|
|
2
2
|
ActiveRecord::ActiveRecordError # hack for https://rails.lighthouseapp.com/projects/8994/tickets/2577-when-using-activerecordassociations-outside-of-rails-a-nameerror-is-thrown
|
3
3
|
require File.dirname(__FILE__) + '/lib/hobo_support.rb'
|
4
4
|
|
5
|
+
RUBY = ENV['RUBY'] || (defined?(JRUBY_VERSION) ? 'jruby' : 'ruby')
|
6
|
+
RUBYDOCTEST = ENV['RUBYDOCTEST'] || "#{RUBY} `which rubydoctest`"
|
7
|
+
|
5
8
|
namespace "test" do
|
6
9
|
desc "Run the doctests"
|
7
10
|
task :doctest do |t|
|
8
|
-
exit(1) if !system("
|
11
|
+
exit(1) if !system("#{RUBYDOCTEST} test/*.rdoctest test/hobosupport/*.rdoctest")
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
12
15
|
# --- build gem via Jeweller --- #
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
rubyforge.doc_task = false
|
28
|
-
end
|
29
|
-
rescue LoadError
|
30
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
require 'jeweler'
|
18
|
+
Jeweler::Tasks.new do |gemspec|
|
19
|
+
gemspec.version = HoboSupport::VERSION
|
20
|
+
gemspec.name = "hobosupport"
|
21
|
+
gemspec.email = "tom@tomlocke.com"
|
22
|
+
gemspec.summary = "Core Ruby extensions from the Hobo project"
|
23
|
+
gemspec.homepage = "http://hobocentral.net/"
|
24
|
+
gemspec.authors = ["Tom Locke"]
|
25
|
+
gemspec.rubyforge_project = "hobosupport"
|
26
|
+
end
|
27
|
+
Jeweler::GemcutterTasks.new
|
28
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
29
|
+
rubyforge.doc_task = false
|
31
30
|
end
|
data/lib/hobo_support.rb
CHANGED
data/lib/hobo_support/array.rb
CHANGED
@@ -17,6 +17,24 @@ class Array
|
|
17
17
|
self
|
18
18
|
end
|
19
19
|
|
20
|
+
# useful function from Rails 2.3
|
21
|
+
if !respond_to? :wrap
|
22
|
+
def self.wrap(object)
|
23
|
+
case object
|
24
|
+
when nil
|
25
|
+
[]
|
26
|
+
when self
|
27
|
+
object
|
28
|
+
else
|
29
|
+
if object.respond_to?(:to_ary)
|
30
|
+
object.to_ary
|
31
|
+
else
|
32
|
+
[object]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
20
38
|
end
|
21
39
|
|
22
40
|
|
data/lib/hobo_support/hash.rb
CHANGED
data/lib/hobo_support/module.rb
CHANGED
@@ -15,27 +15,41 @@ class Module
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Creates a class attribute reader that will delegate to the superclass
|
18
|
-
# if not defined on self
|
18
|
+
# if not defined on self. Default values can be a Proc object that takes the class as a parameter.
|
19
19
|
def inheriting_cattr_reader(*names)
|
20
20
|
names_with_defaults = (names.pop if names.last.is_a?(Hash)) || {}
|
21
21
|
|
22
|
-
names_with_defaults.each do |name, default|
|
23
|
-
instance_variable_set("@#{name}", default) unless instance_variable_get("@#{name}") != nil || superclass.respond_to?(name)
|
24
|
-
end
|
25
|
-
|
26
22
|
(names + names_with_defaults.keys).each do |name|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
23
|
+
ivar_name = "@#{name}"
|
24
|
+
block = names_with_defaults[name]
|
25
|
+
self.send(self.class == Module ? :define_method : :meta_def, name) do
|
26
|
+
if instance_variable_defined? ivar_name
|
27
|
+
instance_variable_get(ivar_name)
|
28
|
+
else
|
29
|
+
superclass.respond_to?(name) && superclass.send(name) ||
|
30
|
+
block && begin
|
31
|
+
result = block.is_a?(Proc) ? block.call(self) : block
|
32
|
+
instance_variable_set(ivar_name, result) if result
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def inheriting_cattr_accessor(*names)
|
40
|
+
names_with_defaults = (names.pop if names.last.is_a?(Hash)) || {}
|
41
|
+
|
42
|
+
names_with_defaults.keys.each do |name|
|
43
|
+
attr_writer name
|
44
|
+
inheriting_cattr_reader names_with_defaults.slice(name)
|
45
|
+
end
|
46
|
+
names.each do |name|
|
47
|
+
attr_writer name
|
48
|
+
inheriting_cattr_reader name
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
39
53
|
# creates a #foo= and #foo? pair, with optional default values, e.g.
|
40
54
|
# bool_attr_accessor :happy => true
|
41
55
|
def bool_attr_accessor(*args)
|
data/test/hobosupport.rdoctest
CHANGED
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.
|
4
|
+
version: 0.9.0
|
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: 2009-
|
12
|
+
date: 2009-11-17 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|