Module: Shippinglogic::Attributes::ClassMethods
- Defined in:
- lib/shippinglogic/attributes.rb
Instance Method Summary (collapse)
-
- (Object) attribute(name, type, options = {})
Define an attribute for a class, makes adding options / attributes to the class much cleaner.
-
- (Object) attribute_names
An array of the attribute names.
-
- (Object) attribute_options(name)
Returns the options specified when defining a specific attribute.
-
- (Object) attributes
A hash of all the attributes and their options.
Instance Method Details
- (Object) attribute(name, type, options = {})
Define an attribute for a class, makes adding options / attributes to the class much cleaner. See the Rates class for an example.
16 17 18 19 20 21 22 23 |
# File 'lib/shippinglogic/attributes.rb', line 16 def attribute(name, type, = {}) name = name.to_sym [:type] = type.to_sym attributes[name] = define_method(name) { read_attribute(name) } define_method("#{name}=") { |value| write_attribute(name, value) } end |
- (Object) attribute_names
An array of the attribute names
31 32 33 |
# File 'lib/shippinglogic/attributes.rb', line 31 def attribute_names attributes.keys end |
- (Object) attribute_options(name)
Returns the options specified when defining a specific attribute
36 37 38 |
# File 'lib/shippinglogic/attributes.rb', line 36 def (name) attributes[name.to_sym] end |
- (Object) attributes
A hash of all the attributes and their options
26 27 28 |
# File 'lib/shippinglogic/attributes.rb', line 26 def attributes @attributes ||= {} end |