cattr 0.1.0 → 0.1.1

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 (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/cattr.rb +1 -8
  3. data/test/test_cattr.rb +17 -7
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/cattr.rb CHANGED
@@ -11,14 +11,7 @@ class Class
11
11
  def cattr_writer(*meths)
12
12
  meths.each do |meth|
13
13
  self.class.send(:define_method, :"#{meth}=") do |arg|
14
- # if we can get the class variable it means it exists so
15
- # we don't want to overwrite it.
16
- begin
17
- class_variable_get("@@#{meth}")
18
- rescue NameError
19
- # if we get a nameerror, then it didn't exist so let's set it
20
- class_variable_set("@@#{meth}", arg)
21
- end
14
+ class_variable_set("@@#{meth}", arg)
22
15
  end
23
16
  end
24
17
  end
data/test/test_cattr.rb CHANGED
@@ -6,28 +6,38 @@ class TestCattr < Test::Unit::TestCase
6
6
  cattr_accessor :cow
7
7
  end
8
8
  Moo.cow = 'test'
9
- assert('test',Moo.cow)
9
+ assert_equal('test',Moo.cow)
10
10
  end
11
11
 
12
12
  should "create class setter" do
13
- class Moo
13
+ class Moo1
14
14
  cattr_writer :cow
15
15
  def self.get
16
16
  @@cow
17
17
  end
18
18
  end
19
- Moo.cow = 'test'
20
- assert('test',Moo.get)
19
+ Moo1.cow = 'test'
20
+ assert_equal('test',Moo1.get)
21
+ end
22
+
23
+ should "set and reset attributes" do
24
+ class Moo2
25
+ cattr_accessor :cow
26
+ end
27
+ Moo2.cow = 'test'
28
+ assert('test',Moo2.cow)
29
+ Moo2.cow = 'test2'
30
+ assert_equal('test2',Moo2.cow)
21
31
  end
22
32
 
23
33
  should "create class reder" do
24
- class Moo
34
+ class Moo3
25
35
  cattr_reader :cow
26
36
  def self.get=(arg)
27
37
  @@cow = arg
28
38
  end
29
39
  end
30
- Moo.get = 'test'
31
- assert('test',Moo.cow)
40
+ Moo3.get = 'test'
41
+ assert_equal('test',Moo3.cow)
32
42
  end
33
43
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Bretoi