cattr 0.1.1 → 0.1.2

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.
Files changed (5) hide show
  1. data/README.rdoc +1 -1
  2. data/VERSION +1 -1
  3. data/lib/cattr.rb +4 -1
  4. data/test/test_cattr.rb +18 -0
  5. metadata +3 -3
@@ -1,7 +1,7 @@
1
1
  = cattr
2
2
 
3
3
  Like attr_accessor for instance methods, but creates class methods/variables instead.
4
- Works just like the version for rails (except it doesn't accept blocks and doesn't use eval).
4
+ Works much like the version for rails (except it doesn't accept blocks and doesn't use eval).
5
5
 
6
6
  class Moo
7
7
  cattr_accessor :cow
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,7 +5,10 @@ class Class
5
5
  end
6
6
  def cattr_reader(*meths)
7
7
  meths.each do |meth|
8
- self.class.send(:define_method, meth) { class_variable_get("@@#{meth}") }
8
+ self.class.send(:define_method, meth) do
9
+ return nil unless class_variable_defined? "@@#{meth}"
10
+ return class_variable_get "@@#{meth}"
11
+ end
9
12
  end
10
13
  end
11
14
  def cattr_writer(*meths)
@@ -40,4 +40,22 @@ class TestCattr < Test::Unit::TestCase
40
40
  Moo3.get = 'test'
41
41
  assert_equal('test',Moo3.cow)
42
42
  end
43
+
44
+ should "return nil if not defined" do
45
+ class Foo
46
+ cattr_reader :moo
47
+ end
48
+ assert_equal(nil,Foo.moo)
49
+ end
50
+
51
+ should "assign in class" do
52
+ class Foo2
53
+ cattr_reader :moo
54
+ def self.init
55
+ @@moo = 3
56
+ end
57
+ end
58
+ Foo2.init
59
+ assert_equal(3,Foo2.moo)
60
+ end
43
61
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Bretoi
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-20 00:00:00 -07:00
17
+ date: 2010-07-23 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency