Module: LazyRecord::Attributes

Defined in:
lib/lazy_record/attributes.rb

Overview

Add special attr_accessors that automatically add initialization options to your initialize method. Using lr_attr_accessor, you automatically get an #initialize method that takes setter options for each attribute and yields self to a block. If you want to add custom functionality to #initialize just call super.

Instance Method Summary collapse

Instance Method Details

#add_to_attr_readers(*names) ⇒ Object



30
31
32
33
34
# File 'lib/lazy_record/attributes.rb', line 30

def add_to_attr_readers(*names)
  names.each do |name|
    attr_readers << name.to_sym
  end
end

#attr_accessor(*names) ⇒ Object



20
21
22
23
# File 'lib/lazy_record/attributes.rb', line 20

def attr_accessor(*names)
  super(*names)
  add_to_attr_readers(*names)
end

#attr_reader(*names) ⇒ Object



25
26
27
28
# File 'lib/lazy_record/attributes.rb', line 25

def attr_reader(*names)
  super(*names)
  add_to_attr_readers(*names)
end

#lr_attr_accessor(*names) ⇒ Object

Will be removed in version 1.0.0



10
11
12
13
14
15
16
# File 'lib/lazy_record/attributes.rb', line 10

def lr_attr_accessor(*names) # Will be removed in version 1.0.0
  puts 'Using `.lr_attr_accessor` is deprecated. Use the standard '\
  '`.attr_*` methods instead. You will get the same results, plus '\
  'the methods will be recognized by rdoc. `.lr_attr_accessor` will'\
  ' be removed in version 1.0.0'
  attr_accessor(*names)
end