Class: Listings::Sources::DataSource

Inherits:
Object
  • Object
show all
Defined in:
lib/listings/sources/data_source.rb,
lib/listings/sources/object_data_source.rb,
lib/listings/sources/active_record_data_source.rb

Direct Known Subclasses

ActiveRecordDataSource, ObjectDataSource

Constant Summary collapse

DESC =
'desc'
ASC =
'asc'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(model) ⇒ Object



51
52
53
# File 'lib/listings/sources/data_source.rb', line 51

def self.for(model)
  raise "Unable to create datasource for #{model}"
end

.for_without_active_recordObject



83
84
85
# File 'lib/listings/sources/active_record_data_source.rb', line 83

def self.for(model)
  raise "Unable to create datasource for #{model}"
end

.for_without_objectObject



61
62
63
# File 'lib/listings/sources/object_data_source.rb', line 61

def self.for(model)
  raise "Unable to create datasource for #{model}"
end

.sanitaize_path(path) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/listings/sources/data_source.rb', line 55

def self.sanitaize_path(path)
  if path.is_a?(Array)
    path
  elsif path.is_a?(Hash) && path.size == 1
    path.to_a.first
  else
    path
  end
end

Instance Method Details

#build_field(path) ⇒ Object

returns a Field for the specified options



48
49
# File 'lib/listings/sources/data_source.rb', line 48

def build_field(path)
end

#filter(field, value) ⇒ Object

applies exact match filtering among specified field



26
27
# File 'lib/listings/sources/data_source.rb', line 26

def filter(field, value)
end

#itemsObject

returns items for the data source if paginate is called, items will return just the current page



8
9
# File 'lib/listings/sources/data_source.rb', line 8

def items
end

#paginate(page, page_size) ⇒ Object

apply pagination filter to items items of the selected page can be obtained through items



44
45
# File 'lib/listings/sources/data_source.rb', line 44

def paginate(page, page_size)
end

#scopeObject

applies filter to the items scope will be called with a block with the ongoing items the result of the block is used as the narrowed items



18
19
# File 'lib/listings/sources/data_source.rb', line 18

def scope
end

#search(fields, value) ⇒ Object

applies a human friendly search to items among multiple fields



22
23
# File 'lib/listings/sources/data_source.rb', line 22

def search(fields, value)
end

#sort(field, direction = ASC) ⇒ Object

applies sorting with specified direction to items subclasses should implement sort_with_direction in order to leave default direction logic in DataSource



32
33
34
# File 'lib/listings/sources/data_source.rb', line 32

def sort(field, direction = ASC)
  sort_with_direction(field, direction)
end

#transform_itemsObject

free transform items. used usually to filter the result with logic given by a block



12
13
# File 'lib/listings/sources/data_source.rb', line 12

def transform_items
end

#values_for_filter(field) ⇒ Object

returns all values of field usually calling search/filter/sort/paginate should not affect the results. calling scope should affect the results.



39
40
# File 'lib/listings/sources/data_source.rb', line 39

def values_for_filter(field)
end