Class: Datagrid::Drivers::AbstractDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/datagrid/drivers/abstract_driver.rb

Overview

:nodoc:

Direct Known Subclasses

ActiveRecord, Array, MongoMapper, Mongoid, Sequel

Constant Summary collapse

TIMESTAMP_CLASSES =
[DateTime, Time, ActiveSupport::TimeWithZone]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.guess_driver(scope) ⇒ Object


15
16
17
18
19
# File 'lib/datagrid/drivers/abstract_driver.rb', line 15

def self.guess_driver(scope)
  self.subclasses.find do |driver_class|
    driver_class.match?(scope)
  end || raise(Datagrid::ConfigurationError, "ORM Driver not found for scope: #{scope.inspect}.")
end

.inherited(base) ⇒ Object


9
10
11
12
13
# File 'lib/datagrid/drivers/abstract_driver.rb', line 9

def self.inherited(base)
  super(base)
  self.subclasses ||= []
  self.subclasses << base
end

.match?(scope) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)

21
22
23
# File 'lib/datagrid/drivers/abstract_driver.rb', line 21

def self.match?(scope)
  raise NotImplementedError
end

Instance Method Details

#append_column_queries(assets, columns) ⇒ Object


85
86
87
88
89
90
91
# File 'lib/datagrid/drivers/abstract_driver.rb', line 85

def append_column_queries(assets, columns)
  if columns.present?
    raise NotImplementedError
  else
    assets
  end
end

#asc(scope, order) ⇒ Object

Raises:

  • (NotImplementedError)

37
38
39
# File 'lib/datagrid/drivers/abstract_driver.rb', line 37

def asc(scope, order)
  raise NotImplementedError
end

#batch_each(scope, batch_size, &block) ⇒ Object

Raises:

  • (NotImplementedError)

81
82
83
# File 'lib/datagrid/drivers/abstract_driver.rb', line 81

def batch_each(scope, batch_size, &block)
  raise NotImplementedError
end

#can_preload?(scope, association) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)

112
113
114
# File 'lib/datagrid/drivers/abstract_driver.rb', line 112

def can_preload?(scope, association)
  raise NotImplementedError
end

#column_names(scope) ⇒ Object

Raises:

  • (NotImplementedError)

73
74
75
# File 'lib/datagrid/drivers/abstract_driver.rb', line 73

def column_names(scope)
  raise NotImplementedError
end

#contains(scope, field, value) ⇒ Object

Raises:

  • (NotImplementedError)

69
70
71
# File 'lib/datagrid/drivers/abstract_driver.rb', line 69

def contains(scope, field, value)
  raise NotImplementedError
end

#default_cache_key(asset) ⇒ Object

Raises:

  • (NotImplementedError)

93
94
95
# File 'lib/datagrid/drivers/abstract_driver.rb', line 93

def default_cache_key(asset)
  raise NotImplementedError
end

#default_order(scope, column_name) ⇒ Object

Raises:

  • (NotImplementedError)

45
46
47
# File 'lib/datagrid/drivers/abstract_driver.rb', line 45

def default_order(scope, column_name)
  raise NotImplementedError
end

#default_preload(scope, value) ⇒ Object

Raises:

  • (NotImplementedError)

108
109
110
# File 'lib/datagrid/drivers/abstract_driver.rb', line 108

def default_preload(scope, value)
  raise NotImplementedError
end

#desc(scope, order) ⇒ Object

Raises:

  • (NotImplementedError)

41
42
43
# File 'lib/datagrid/drivers/abstract_driver.rb', line 41

def desc(scope, order)
  raise NotImplementedError
end

#greater_equal(scope, field, value) ⇒ Object

Raises:

  • (NotImplementedError)

49
50
51
# File 'lib/datagrid/drivers/abstract_driver.rb', line 49

def greater_equal(scope, field, value)
  raise NotImplementedError
end

#has_column?(scope, column_name) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)

57
58
59
# File 'lib/datagrid/drivers/abstract_driver.rb', line 57

def has_column?(scope, column_name)
  raise NotImplementedError
end

#is_timestamp?(scope, field) ⇒ Boolean

Returns:

  • (Boolean)

65
66
67
# File 'lib/datagrid/drivers/abstract_driver.rb', line 65

def is_timestamp?(scope, field)
  normalized_column_type(scope, field) == :timestamp
end

#less_equal(scope, field, value) ⇒ Object

Raises:

  • (NotImplementedError)

53
54
55
# File 'lib/datagrid/drivers/abstract_driver.rb', line 53

def less_equal(scope, field, value)
  raise NotImplementedError
end

#match?(scope) ⇒ Boolean

Returns:

  • (Boolean)

25
26
27
# File 'lib/datagrid/drivers/abstract_driver.rb', line 25

def match?(scope)
  self.class.match?(scope)
end

#normalized_column_type(scope, field) ⇒ Object

Raises:

  • (NotImplementedError)

77
78
79
# File 'lib/datagrid/drivers/abstract_driver.rb', line 77

def normalized_column_type(scope, field)
  raise NotImplementedError
end

#reverse_order(scope) ⇒ Object

Raises:

  • (NotImplementedError)

61
62
63
# File 'lib/datagrid/drivers/abstract_driver.rb', line 61

def reverse_order(scope)
  raise NotImplementedError
end

#to_scope(scope) ⇒ Object

Raises:

  • (NotImplementedError)

29
30
31
# File 'lib/datagrid/drivers/abstract_driver.rb', line 29

def to_scope(scope)
  raise NotImplementedError
end

#where(scope, attribute, value) ⇒ Object

Raises:

  • (NotImplementedError)

33
34
35
# File 'lib/datagrid/drivers/abstract_driver.rb', line 33

def where(scope, attribute, value)
  raise NotImplementedError
end

#where_by_timestamp_gotcha(scope, name, value) ⇒ Object


97
98
99
100
101
102
103
104
105
106
# File 'lib/datagrid/drivers/abstract_driver.rb', line 97

def where_by_timestamp_gotcha(scope, name, value)
  value = Datagrid::Utils.format_date_as_timestamp(value)
  if value.first
    scope = greater_equal(scope, name, value.first)
  end
  if value.last
    scope = less_equal(scope, name, value.last)
  end
  scope
end