freighthopper 0.1.7 → 0.1.8

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.8
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{freighthopper}
8
- s.version = "0.1.7"
8
+ s.version = "0.1.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jacob Rothstein"]
12
- s.date = %q{2010-04-22}
12
+ s.date = %q{2010-06-24}
13
13
  s.default_executable = %q{convert_to_should_syntax}
14
14
  s.description = %q{More core ext}
15
15
  s.email = %q{github@jacobrothstein.com}
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "init.rb",
32
32
  "lib/freighthopper.rb",
33
33
  "pkg/.gitkeep",
34
+ "test/antonym_accessor_test.rb",
34
35
  "test/array_test.rb",
35
36
  "test/define_and_alias_test.rb",
36
37
  "test/float_test.rb",
@@ -44,10 +45,11 @@ Gem::Specification.new do |s|
44
45
  s.homepage = %q{http://github.com/jbr/freighthopper}
45
46
  s.rdoc_options = ["--charset=UTF-8"]
46
47
  s.require_paths = ["lib"]
47
- s.rubygems_version = %q{1.3.6}
48
+ s.rubygems_version = %q{1.3.7}
48
49
  s.summary = %q{Some extensions for riding the rails}
49
50
  s.test_files = [
50
- "test/array_test.rb",
51
+ "test/antonym_accessor_test.rb",
52
+ "test/array_test.rb",
51
53
  "test/define_and_alias_test.rb",
52
54
  "test/float_test.rb",
53
55
  "test/hash_test.rb",
@@ -62,7 +64,7 @@ Gem::Specification.new do |s|
62
64
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
65
  s.specification_version = 3
64
66
 
65
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
68
  else
67
69
  end
68
70
  else
data/lib/freighthopper.rb CHANGED
@@ -10,6 +10,24 @@ class Module
10
10
  def lazy_alias(to, from)
11
11
  define_method(to){|*args| send from, *args}
12
12
  end
13
+
14
+ def antonym_accessor(*args)
15
+ if 2 == args.length
16
+ from, to = args
17
+ define_method("#{to}?") { not send "#{from}?" }
18
+ define_method("#{to}=") {|val| send "#{from}=", ! val }
19
+ elsif args.singular.is_a?(Hash)
20
+ args.singular.each {|from, to| antonym_accessor from, to}
21
+ else
22
+ message = <<-EXCEPTION
23
+ antonym_accessor expects either
24
+ "antonym_accessor :from, :to"
25
+ or "antonym_accessor :from => :to"
26
+ EXCEPTION
27
+
28
+ raise message.unindent
29
+ end
30
+ end
13
31
  end
14
32
 
15
33
  class Array
@@ -120,4 +138,4 @@ if defined?(ActiveRecord)
120
138
  end
121
139
  end
122
140
  end
123
- end
141
+ end
@@ -0,0 +1,52 @@
1
+ require File.instance_eval { expand_path join(dirname(__FILE__), 'test_helper') }
2
+ require 'freighthopper'
3
+
4
+
5
+ class TestClass
6
+ def private?() @private end
7
+ def private=(p) @private = p end
8
+ end
9
+
10
+ class TwoArgumentForm < TestClass
11
+ antonym_accessor :private, :public
12
+ end
13
+
14
+ class HashForm < TestClass
15
+ antonym_accessor :private => :public
16
+ end
17
+
18
+ class ArrayTest < Test::Unit::TestCase
19
+ def self.should_act_like_antonym_accessor
20
+ should 'define a public= method' do
21
+ @instance.public = true
22
+ assert_not @instance.private?
23
+ end
24
+
25
+ should 'define a public? method' do
26
+ @instance.private = false
27
+ assert @instance.public?
28
+ end
29
+ end
30
+
31
+ context 'two argument form' do
32
+ setup {@instance = TwoArgumentForm.new}
33
+ should_act_like_antonym_accessor
34
+ end
35
+
36
+ context 'hash form' do
37
+ setup {@instance = HashForm.new}
38
+ should_act_like_antonym_accessor
39
+ end
40
+
41
+ context 'anything else' do
42
+ should 'raise' do
43
+ begin
44
+ TestClass.antonym_accessor :foo
45
+ rescue => e
46
+ assert e.message =~ /antonym_accessor expects/
47
+ ensure
48
+ assert_not_nil e
49
+ end
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freighthopper
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 11
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 7
9
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jacob Rothstein
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-22 00:00:00 -07:00
18
+ date: 2010-06-24 00:00:00 -07:00
18
19
  default_executable: convert_to_should_syntax
19
20
  dependencies: []
20
21
 
@@ -40,6 +41,7 @@ files:
40
41
  - init.rb
41
42
  - lib/freighthopper.rb
42
43
  - pkg/.gitkeep
44
+ - test/antonym_accessor_test.rb
43
45
  - test/array_test.rb
44
46
  - test/define_and_alias_test.rb
45
47
  - test/float_test.rb
@@ -59,27 +61,32 @@ rdoc_options:
59
61
  require_paths:
60
62
  - lib
61
63
  required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
62
65
  requirements:
63
66
  - - ">="
64
67
  - !ruby/object:Gem::Version
68
+ hash: 3
65
69
  segments:
66
70
  - 0
67
71
  version: "0"
68
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
69
74
  requirements:
70
75
  - - ">="
71
76
  - !ruby/object:Gem::Version
77
+ hash: 3
72
78
  segments:
73
79
  - 0
74
80
  version: "0"
75
81
  requirements: []
76
82
 
77
83
  rubyforge_project:
78
- rubygems_version: 1.3.6
84
+ rubygems_version: 1.3.7
79
85
  signing_key:
80
86
  specification_version: 3
81
87
  summary: Some extensions for riding the rails
82
88
  test_files:
89
+ - test/antonym_accessor_test.rb
83
90
  - test/array_test.rb
84
91
  - test/define_and_alias_test.rb
85
92
  - test/float_test.rb