Module: NeverBounce::API::Feature::Oattrs::ClassMethods
- Defined in:
- lib/never_bounce/api/feature/oattrs.rb
Instance Attribute Summary collapse
-
#oattrs ⇒ Array
Return oattrs declared so far, recurse all superclasses.
Instance Method Summary collapse
-
#oattr(name, type) ⇒ Symbol
Declare an OTF attribute.
Instance Attribute Details
#oattrs ⇒ Array
Return oattrs declared so far, recurse all superclasses.
oattrs # => [:first_name, :last_name]
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
...
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 |