Module: Shippinglogic::FedEx::Attributes::ClassMethods
- Defined in:
- lib/shippinglogic/fedex/attributes.rb
Instance Method Summary collapse
-
#attribute(name, type, options = {}) ⇒ Object
Define an attribute for a class, makes adding options / attributes to the class much cleaner.
-
#attribute_names ⇒ Object
An array of the attribute names.
-
#attribute_options(name) ⇒ Object
Returns the options specified when defining a specific attribute.
-
#attributes ⇒ Object
A hash of all the attributes and their options.
Instance Method Details
#attribute(name, type, options = {}) ⇒ Object
Define an attribute for a class, makes adding options / attributes to the class much cleaner. See the Rates class for an example.
15 16 17 18 19 20 21 22 |
# File 'lib/shippinglogic/fedex/attributes.rb', line 15 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 |
#attribute_names ⇒ Object
An array of the attribute names
30 31 32 |
# File 'lib/shippinglogic/fedex/attributes.rb', line 30 def attribute_names attributes.keys end |
#attribute_options(name) ⇒ Object
Returns the options specified when defining a specific attribute
35 36 37 |
# File 'lib/shippinglogic/fedex/attributes.rb', line 35 def (name) attributes[name.to_sym] end |
#attributes ⇒ Object
A hash of all the attributes and their options
25 26 27 |
# File 'lib/shippinglogic/fedex/attributes.rb', line 25 def attributes @attributes ||= {} end |