module ActiveZuora::Fields::ClassMethods
Public Instance Methods
add_field(name, field)
click to toggle source
# File lib/active_zuora/fields.rb, line 85 def add_field(name, field) fields_by_name[name.to_sym] = field # Define the setters, getters, and changed helpers. field.define_instance_methods(self) end
default_attributes()
click to toggle source
# File lib/active_zuora/fields.rb, line 121 def default_attributes default_attributes = {} fields.each { |field| default_attributes[field.name] = field.default } default_attributes end
field(name, type, options={})
click to toggle source
# File lib/active_zuora/fields.rb, line 99 def field(name, type, options={}) # Check if this field should be an array, don't pass # this option down to the field. field_is_array = options.delete(:array) || false # Create and register the field. field = case type when :string then StringField.new(name, namespace, options) when :boolean then BooleanField.new(name, namespace, options) when :integer then IntegerField.new(name, namespace, options) when :decimal then DecimalField.new(name, namespace, options) when :date then DateField.new(name, namespace, options) when :datetime then DateTimeField.new(name, namespace, options) when :object class_name = options[:class_name] || nested_class_name(name.to_s.camelize) ObjectField.new(name, namespace, class_name, options) else ArgumentError.new "Unknown field type: #{type}" end field = ArrayFieldDecorator.new(field) if field_is_array add_field(name, field) end
field?(name)
click to toggle source
# File lib/active_zuora/fields.rb, line 81 def field?(name) fields_by_name.key?(name.to_sym) end
field_names()
click to toggle source
# File lib/active_zuora/fields.rb, line 77 def field_names fields_by_name.keys end
fields()
click to toggle source
# File lib/active_zuora/fields.rb, line 73 def fields fields_by_name.values end
fields_by_name()
click to toggle source
# File lib/active_zuora/fields.rb, line 68 def fields_by_name # { :field_name_symbol => field_object } @fields ||= {} end
get_field(name)
click to toggle source
# File lib/active_zuora/fields.rb, line 91 def get_field(name) fields_by_name[name.to_sym] end
get_field!(name)
click to toggle source
# File lib/active_zuora/fields.rb, line 95 def get_field!(name) get_field(name) || raise(ArgumentError.new("No field in #{self} named #{name}")) end