Skip to content

Commit

Permalink
[US5772] Use a class variable @@all_attributes instead of using fattr.
Browse files Browse the repository at this point in the history
  • Loading branch information
kalbasit committed Mar 22, 2012
1 parent 9e31d91 commit ed97979
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/zuora/attributes.rb
@@ -1,5 +1,3 @@
require 'fattr'

module Zuora
module Attributes
def self.included(base)
Expand All @@ -16,10 +14,19 @@ module ClassMethods
# can be applied to those attributes.
def define_attributes(&block)
yield self
fattrs class_variable_get(:@@wsdl_attributes)
class_variable_get(:@@wsdl_attributes).each do |attr|
# writable attributes with dirty support
class_eval <<-EVAL
@@all_attributes << "#{attr}".to_sym
define_method "#{attr}" do
@#{attr}
end
define_method "#{attr}?" do
#{attr} ? true : false
end
# writable attributes with dirty support
define_method "#{attr}=" do |value|
return if value == @#{attr}
Expand Down Expand Up @@ -65,6 +72,7 @@ def attr_accessor(attribute)
define_method "\#{attribute}=" do |value|
#{storage_name}[attribute] = value
@@all_attributes << attribute.to_sym
super
end
end
Expand Down Expand Up @@ -114,7 +122,7 @@ def restrain(*args)
alias_method :restrain_attributes, :restrain

def attributes
self.fattrs.map(&:to_sym)
class_variable_get(:@@all_attributes).map(&:to_sym)
end

# the name to use when referencing remote Zuora objects
Expand All @@ -137,6 +145,7 @@ def inherited(subclass)
subclass.send(:class_variable_set, :@@restrain_attributes, [])
subclass.send(:class_variable_set, :@@write_only_attributes, [])
subclass.send(:class_variable_set, :@@deferred_attributes, [])
subclass.send(:class_variable_set, :@@all_attributes, [])

subclass.send(:define_attribute_methods, wsdl_attrs)
end
Expand Down Expand Up @@ -186,7 +195,7 @@ def deferred_attributes

# a hash representation of all attributes including their values
def attributes
self.class.fattrs.inject({}){|h,a| h.update a.to_sym => send(a)}
self.class.attributes.inject({}){|h,a| h.update a.to_sym => send(a)}
end
alias_method :to_hash, :attributes

Expand Down

0 comments on commit ed97979

Please sign in to comment.