Module: AttrHelper::Base::ClassMethods

Defined in:
lib/attr_helper/base.rb

Instance Method Summary collapse

Instance Method Details

#attr_optional(name, options = {}) ⇒ Object



27
28
29
30
# File 'lib/attr_helper/base.rb', line 27

def attr_optional(name, options = {})
  optional_attributes << BaseAttr.new(name.to_sym, options)
  attr_accessor name.to_sym
end

#attr_required(name, options = {}) ⇒ Object



36
37
38
39
# File 'lib/attr_helper/base.rb', line 36

def attr_required(name, options = {})
  required_attributes << RequiredAttr.new(name.to_sym, options)
  attr_accessor name.to_sym
end

#inherited(klass) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/attr_helper/base.rb', line 12

def inherited(klass)
  super

  # we might want to undef here so
  #  that child classes can override

  unless required_attributes.empty?
    add_required_attrs(klass)
  end

  unless optional_attributes.empty?
    add_optional_attrs(klass)
  end
end

#optional_attributesObject



32
33
34
# File 'lib/attr_helper/base.rb', line 32

def optional_attributes
  @optional_attributes ||= []
end

#required_attributesObject



41
42
43
# File 'lib/attr_helper/base.rb', line 41

def required_attributes
  @required_attributes ||= []
end