Module: EasyAttrs::ClassMethods

Defined in:
lib/easy_attrs.rb

Instance Method Summary collapse

Instance Method Details

#all_attributesObject

all_attributes needs to be public for instances to call it in intialize.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/easy_attrs.rb', line 102

def all_attributes
  @_all_attributes ||= begin
    attributes = []

    # Yes, this is a nested loop.
    # The result is memoized so it only happens when the first instance of
    # the including class is initialized and the length of the ancestor
    # chain is rarely going to be very long (it will of course vary
    # depending on the class hierarchy of the applicaton using EasyAttrs).
    #
    easy_attrs_ancestors.each do |a|
      [:readers, :writers, :accessors, :instance_variables_only].each do |i_var|
        i_var_from_ancestor = a.instance_variable_get("@#{i_var}")

        if i_var_from_ancestor
          attributes.concat(i_var_from_ancestor)
        end
      end
    end

    attributes
  end
end