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 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("rubydoctest test/*.rdoctest test/hobosupport/*.rdoctest")
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
- begin
15
- require 'jeweler'
16
- Jeweler::Tasks.new do |gemspec|
17
- gemspec.version = HoboSupport::VERSION
18
- gemspec.name = "hobosupport"
19
- gemspec.email = "tom@tomlocke.com"
20
- gemspec.summary = "Core Ruby extensions from the Hobo project"
21
- gemspec.homepage = "http://hobocentral.net/"
22
- gemspec.authors = ["Tom Locke"]
23
- gemspec.rubyforge_project = "hobosupport"
24
- end
25
- Jeweler::GemcutterTasks.new
26
- Jeweler::RubyforgeTasks.new do |rubyforge|
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
@@ -1,6 +1,6 @@
1
1
  module HoboSupport
2
2
 
3
- VERSION = "0.8.10"
3
+ VERSION = "0.9.0"
4
4
 
5
5
  RAILS_VERSION_FLOAT = Object.const_defined?(:Rails) ? Rails::VERSION::STRING.match(/^\d+\.\d+/)[0].to_f : 0
6
6
 
@@ -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
 
@@ -113,5 +113,9 @@ end
113
113
  if defined? ActiveSupport
114
114
  class ActiveSupport::OrderedHash
115
115
  alias each_pair each
116
+
117
+ def first
118
+ empty? ? nil : [keys.first, values.first]
119
+ end
116
120
  end
117
121
  end
@@ -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
- class_eval %{
28
- def self.#{name}
29
- if defined? @#{name}
30
- @#{name}
31
- elsif superclass.respond_to?('#{name}')
32
- superclass.#{name}
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)
@@ -8,7 +8,7 @@ HoboSupport is a mixed bag of core ruby extensions that have been extracted from
8
8
  {.hidden}
9
9
 
10
10
  >> HoboSupport::VERSION
11
- => "0.8.9"
11
+ => "0.9.0"
12
12
 
13
13
  ## Contents
14
14
 
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.10
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-10-15 00:00:00 +01:00
12
+ date: 2009-11-17 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15