Module: DaisybillApi::Ext::CRUD::Index::ClassMethods

Defined in:
lib/daisybill_api/ext/crud/index.rb

Instance Method Summary collapse

Instance Method Details

#all(options = {}) ⇒ Object

Retrieves a list of records

@patients = DaisybillApi::Models::Patient.all(billing_provider_id: 2)
# => #<DaisybillApi::Ext::PageableCollection>

Parameters:

  • options (Hash) (defaults to: {})

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/daisybill_api/ext/crud/index.rb', line 13

def all(options = {})
  id = options[@prefix_property]

  if options[:path]
    c = client(:get, options.delete(:path), options)
  else
    c = client(:get, index_path(id), options)
  end

  if c.success?
    collection_key = options[:collection_key] || plural_key.to_s
    DaisybillApi::Ext::PageableCollection.new(
      c.response[collection_key].map { |attributes|
        instance = new(attributes)
        instance.send("#{prefix_property}=", id) if path_prefix?
        instance
      },
      {
        headers: c.headers,
        params: options,
        resource_class: self
      }
    )
  else
    DaisybillApi::Ext::PageableCollection.new([])
  end
end