Module: NeverBounce::API::Feature::Oattrs::ClassMethods

Defined in:
lib/never_bounce/api/feature/oattrs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#oattrsArray

Return oattrs declared so far, recurse all superclasses.

oattrs    # => [:first_name, :last_name]

Returns:

  • (Array)


22
23
24
25
26
27
28
# File 'lib/never_bounce/api/feature/oattrs.rb', line 22

def oattrs
  @attrs ||= if superclass.respond_to?(m = :oattrs)
    superclass.send(m).dup
  else
    []
  end
end

Instance Method Details

#oattr(name, type) ⇒ Symbol

Declare an OTF attribute.

class Klass
  oattr :first_name, :writer
  oattr :goods, :custom

  def first_name
    @first_name ||= ENV["FIRST_NAME"]
  end

  def goods
    @goods ||= ...

  def goods=(ar)
    @goods = ar
  ...

Returns:

  • (Symbol)

    name.

See Also:



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/never_bounce/api/feature/oattrs.rb', line 53

def oattr(name, type)
  case type
  when :custom
    # Do nothing, just register attr below.
  when :writer
    attr_writer name
  else
    raise ArgumentError, "Unknown type: #{type.inspect}"
  end

  # Register and return.
  name.tap { oattrs << name}
end