Skip to content
This repository
Browse code

Rename _attributes to attribute_set

  • Loading branch information...
commit 371c2c9beb54a19343f81a1636cc0185b3140233 1 parent 342cb26
Piotr Solnica authored June 05, 2012
4  lib/virtus/class_inclusions.rb
@@ -9,8 +9,8 @@ def self.included(descendant)
9 9
 
10 10
   private
11 11
 
12  
-    def _attributes
13  
-      self.class.attributes
  12
+    def attribute_set
  13
+      self.class.attribute_set
14 14
     end
15 15
 
16 16
     def allowed_writer_methods
9  lib/virtus/class_methods.rb
@@ -38,14 +38,13 @@ def self.extended(descendant)
38 38
     # @return [AttributeSet]
39 39
     #
40 40
     # @api public
41  
-    def attributes
42  
-      return @attributes if defined?(@attributes)
  41
+    def attribute_set
  42
+      return @attribute_set if defined?(@attribute_set)
43 43
       superclass  = self.superclass
44 44
       method      = __method__
45 45
       parent      = superclass.public_send(method) if superclass.respond_to?(method)
46  
-      @attributes = AttributeSet.new(parent)
  46
+      @attribute_set = AttributeSet.new(parent)
47 47
     end
48  
-    alias _attributes attributes
49 48
 
50 49
   protected
51 50
 
@@ -99,7 +98,7 @@ def const_missing(name)
99 98
     # @api private
100 99
     def virtus_add_attribute(attribute)
101 100
       super
102  
-      descendants.each { |descendant| descendant.attributes.reset }
  101
+      descendants.each { |descendant| descendant.attribute_set.reset }
103 102
     end
104 103
 
105 104
     # @api private
6  lib/virtus/instance_extensions.rb
@@ -64,13 +64,13 @@ def allowed_writer_methods
64 64
   private
65 65
 
66 66
     # @api private
67  
-    def _attributes
68  
-      @_attributes ||= AttributeSet.new
  67
+    def attribute_set
  68
+      @attribute_set ||= AttributeSet.new
69 69
     end
70 70
 
71 71
     # @api private
72 72
     def virtus_add_attribute(attribute)
73  
-      _attributes << attribute
  73
+      attribute_set << attribute
74 74
     end
75 75
 
76 76
   end # module InstanceExtensions
2  lib/virtus/instance_methods.rb
@@ -140,7 +140,7 @@ def to_hash
140 140
     #
141 141
     # @api private
142 142
     def get_attributes
143  
-      _attributes.each_with_object({}) do |attribute, attributes|
  143
+      attribute_set.each_with_object({}) do |attribute, attributes|
144 144
         name = attribute.name
145 145
         attributes[name] = get_attribute(name) if yield(attribute)
146 146
       end
2  lib/virtus/value_object.rb
@@ -123,7 +123,7 @@ def allowed_writer_methods
123 123
         @allowed_writer_methods ||=
124 124
           begin
125 125
             allowed_writer_methods = super
126  
-            allowed_writer_methods += _attributes.map{|attr| "#{attr.name}="}
  126
+            allowed_writer_methods += attribute_set.map{|attr| "#{attr.name}="}
127 127
             allowed_writer_methods.to_set.freeze
128 128
           end
129 129
       end
6  spec/integration/using_modules_spec.rb
@@ -28,10 +28,10 @@ class Moderator; end
28 28
   end
29 29
 
30 30
   specify 'including a module with attributes into a class' do
31  
-    Examples::User.attributes[:name].should be_instance_of(Virtus::Attribute::String)
  31
+    Examples::User.attribute_set[:name].should be_instance_of(Virtus::Attribute::String)
32 32
 
33  
-    Examples::Admin.attributes[:name].should be_instance_of(Virtus::Attribute::String)
34  
-    Examples::Admin.attributes[:age].should be_instance_of(Virtus::Attribute::Integer)
  33
+    Examples::Admin.attribute_set[:name].should be_instance_of(Virtus::Attribute::String)
  34
+    Examples::Admin.attribute_set[:age].should be_instance_of(Virtus::Attribute::Integer)
35 35
 
36 36
     user = Examples::Admin.new(:name => 'Piotr', :age => 29)
37 37
     user.name.should eql('Piotr')
8  spec/integration/virtus/value_object_spec.rb
@@ -13,11 +13,15 @@ def self.name
13 13
       attribute :longitude, Float
14 14
     end
15 15
   end
  16
+
16 17
   let(:attribute_values) { { :latitude => 10.0, :longitude => 20.0 } }
  18
+
17 19
   let(:instance_with_equal_state) { class_under_test.new(attribute_values) }
  20
+
18 21
   let(:instance_with_different_state) do
19 22
     class_under_test.new(:latitude => attribute_values[:latitude])
20 23
   end
  24
+
21 25
   subject { class_under_test.new(attribute_values) }
22 26
 
23 27
   describe 'initialization' do
@@ -29,8 +33,8 @@ def self.name
29 33
 
30 34
   describe 'writer visibility' do
31 35
     it 'attributes are configured for private writers' do
32  
-      class_under_test.attributes[:latitude].public_reader?.should be(true)
33  
-      class_under_test.attributes[:longitude].public_writer?.should be(false)
  36
+      class_under_test.attribute_set[:latitude].public_reader?.should be(true)
  37
+      class_under_test.attribute_set[:longitude].public_writer?.should be(false)
34 38
     end
35 39
 
36 40
     it 'writer methods are set to private' do
4  spec/unit/virtus/class_methods/attributes_spec.rb → spec/unit/virtus/class_methods/attribute_set_spec.rb
... ...
@@ -1,7 +1,7 @@
1 1
 require 'spec_helper'
2 2
 
3  
-describe Virtus::ClassMethods, '#attributes' do
4  
-  subject { object.attributes }
  3
+describe Virtus::ClassMethods, '#attribute_set' do
  4
+  subject { object.attribute_set }
5 5
 
6 6
   let(:object) { Class.new { extend Virtus::ClassMethods } }
7 7
 
2  spec/unit/virtus/class_methods/attribute_spec.rb
@@ -9,7 +9,7 @@
9 9
   let(:type)       { Virtus::Attribute::String    }
10 10
 
11 11
   def assert_attribute_added(klass, name, attribute_class)
12  
-    attributes = klass.attributes
  12
+    attributes = klass.attribute_set
13 13
     attributes[name].should be_nil
14 14
     subject
15 15
     attribute = attributes[name]
2  spec/unit/virtus/value_object/class_methods/attribute_spec.rb
@@ -6,7 +6,7 @@
6 6
   let(:object)    { Class.new { include Virtus::ValueObject } }
7 7
   let(:name)      { :latitude                                 }
8 8
   let(:type)      { Float                                     }
9  
-  let(:attribute) { object.attributes[name]                   }
  9
+  let(:attribute) { object.attribute_set[name]                }
10 10
 
11 11
   it { should be(object) }
12 12
 

0 notes on commit 371c2c9

Please sign in to comment.
Something went wrong with that request. Please try again.