Module: Deprecatable::ClassMethods

Defined in:
lib/acread/deprecatable.rb

Instance Method Summary collapse

Instance Method Details

#accessorsObject



23
24
25
26
# File 'lib/acread/deprecatable.rb', line 23

def accessors
  # TODO: replace this constant by an ActiveRecord inspection
  ACCESSORS
end

#deprecate_attribute(attr, opts = {}) ⇒ Object



12
13
14
15
16
17
# File 'lib/acread/deprecatable.rb', line 12

def deprecate_attribute(attr, opts={})
  opts ||={}
  @deprecated_attributes ||=[]
  @deprecated_attributes << attr.to_s
  overide_accessors attr, opts
end

#deprecated_attributesObject



19
20
21
# File 'lib/acread/deprecatable.rb', line 19

def deprecated_attributes
  @deprecated_attributes
end

#overide_accessors(attr, opts) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/acread/deprecatable.rb', line 28

def overide_accessors(attr, opts)
  msg = "You can't access atribute #{attr}, it has been deprecated"
  accessors.each do |term|
    define_method("#{attr}#{term}") do |*args|
      raise DeprecatedAttributeError, msg
      (args.length >0 ? super(args) : super()).first # call ActiveRecord behavior if previous exception have been continued
    end
  end
end