module DaisybillApi::Ext::Associations::ClassMethods

Public Instance Methods

foreign_key() click to toggle source
# File lib/daisybill_api/ext/associations.rb, line 10
def foreign_key
  @foreign_key
end
foreign_key=(value) click to toggle source
# File lib/daisybill_api/ext/associations.rb, line 6
def foreign_key=(value)
  @foreign_key = value
end
has_many(name, options = {}) click to toggle source
# File lib/daisybill_api/ext/associations.rb, line 14
def has_many(name, options = {})
  clazz = modulize options[:class]
  define_method name do |params = {}|
    params.merge!(:"#{self.class.singular_key}_id" => self.id)
    params.merge!(path: "#{show_path}/#{name}") if options[:set_path]
    params.merge!(path: clazz.constantize.index_path(id)) if options[:set_path] && options[:use_path_prefix]
    params.merge!(collection_key: options[:collection_key]) if options[:collection_key]
    clazz.constantize.all(params)
  end
end

Private Instance Methods

modulize(name) click to toggle source
# File lib/daisybill_api/ext/associations.rb, line 27
def modulize(name)
  "DaisybillApi::Models::#{name}"
end