Module: PayPal::ExpressCheckout::Fields::ClassMethods
- Defined in:
- lib/paypal/express_checkout/fields.rb
Instance Method Summary collapse
- #associations ⇒ Object
- #field_groups ⇒ Object
- #field_map ⇒ Object
- #has_fields(*args) ⇒ Object
- #has_many(*args) ⇒ Object
- #inheritable_attributes(*args) ⇒ Object
- #inherited(subclass) ⇒ Object
- #inverted_field_map ⇒ Object
Instance Method Details
#associations ⇒ Object
372 373 374 |
# File 'lib/paypal/express_checkout/fields.rb', line 372 def associations @associations ||= [] end |
#field_groups ⇒ Object
368 369 370 |
# File 'lib/paypal/express_checkout/fields.rb', line 368 def field_groups @field_groups ||= [] end |
#field_map ⇒ Object
376 377 378 379 380 |
# File 'lib/paypal/express_checkout/fields.rb', line 376 def field_map @field_map ||= field_groups.inject({}) do |memo, group| memo.merge(ATTRIBUTES[group]) end.merge(ASSOCIATIONS.select{ |k,v| associations.include?(k) }) end |
#has_fields(*args) ⇒ Object
386 387 388 389 390 391 392 393 |
# File 'lib/paypal/express_checkout/fields.rb', line 386 def has_fields(*args) @field_groups += (args & ATTRIBUTES.keys) @field_groups.each do |group| ATTRIBUTES[group].each_key do |field| attr_accessor field end end end |
#has_many(*args) ⇒ Object
395 396 397 398 399 400 401 402 403 |
# File 'lib/paypal/express_checkout/fields.rb', line 395 def has_many(*args) @associations += (args & ASSOCIATIONS.keys) @associations.each do |many| attr_accessor many class_eval %( def #{many}; @#{many} ||= [] end ) end end |
#inheritable_attributes(*args) ⇒ Object
405 406 407 408 409 410 411 412 413 414 |
# File 'lib/paypal/express_checkout/fields.rb', line 405 def inheritable_attributes(*args) @inheritable_attributes ||= [:inheritable_attributes] @inheritable_attributes += args args.each do |arg| class_eval %( class << self; attr_accessor :#{arg} end ) end @inheritable_attributes end |
#inherited(subclass) ⇒ Object
416 417 418 419 420 421 |
# File 'lib/paypal/express_checkout/fields.rb', line 416 def inherited(subclass) @inheritable_attributes.each do |inheritable_attribute| instance_var = "@#{inheritable_attribute}" subclass.instance_variable_set(instance_var, instance_variable_get(instance_var)) end end |
#inverted_field_map ⇒ Object
382 383 384 |
# File 'lib/paypal/express_checkout/fields.rb', line 382 def inverted_field_map @inverted_field_map ||= field_map.invert end |