Class: Netzke::Basepack::DataAdapters::AbstractAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/netzke/basepack/data_adapters/abstract_adapter.rb

Overview

A concrete adapter should implement all the public instance methods of this adapter in order to support all the functionality of Basepack components.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class) ⇒ AbstractAdapter

Returns a new instance of AbstractAdapter.



159
160
161
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 159

def initialize(model_class)
  @model_class = model_class
end

Class Method Details

.adapter_class(model_class) ⇒ Object



155
156
157
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 155

def self.adapter_class(model_class)
  @subclasses.detect { |subclass| subclass.for_class?(model_class) } || AbstractAdapter
end

.for_class?(member_class) ⇒ Boolean

Used to determine if the given adapter should be used for the passed in class.

Returns:

  • (Boolean)


146
147
148
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 146

def self.for_class?(member_class)
  false # override in subclass
end

.inherited(subclass) ⇒ Object



150
151
152
153
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 150

def self.inherited(subclass)
  @subclasses ||= []
  @subclasses << subclass
end

Instance Method Details

#class_for(assoc_name) ⇒ Object

Returns the model class for association columns

Raises:

  • (NotImplementedError)


94
95
96
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 94

def class_for assoc_name
  raise NotImplementedError
end

#column_virtual?(c) ⇒ Boolean

should return true if column is virtual

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 79

def column_virtual? c
  raise NotImplementedError
end

#combobox_options_for_column(column, method_options = {}) ⇒ Object

Returns options for comboboxes in grids/forms

Raises:

  • (NotImplementedError)


84
85
86
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 84

def combobox_options_for_column(column, method_options = {})
  raise NotImplementedError
end

#count_records(params, columns) ⇒ Object

Returns record count based on passed params. Implements:

  • filtering

  • scopes

‘params` is a hash that contains the following keys:

  • :scope - the scope as described in Netzke::Basepack::GridPanel

  • :filter - Ext filters

The ‘columns` parameter may be used to use joins to address the n+1 query problem, and receives an array of column configurations



40
41
42
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 40

def count_records(params, columns)
  0
end

#destroy(ids) ⇒ Object

Destroys records with the provided ids



99
100
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 99

def destroy(ids)
end

#errors_array(record) ⇒ Object

give the data adapter the opporunity to process error messages must return an raay of the form [“Title can’t be blank”, “Foo can’t be blank”]



124
125
126
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 124

def errors_array(record)
  record.errors.to_a
end

#find_record(id) ⇒ Object

Finds a record by id, return nil if not found



129
130
131
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 129

def find_record(id)
  @model_class.find(id)
end

#firstObject

gets the first record



26
27
28
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 26

def first
  @model_class.first
end

#foreign_key_for(assoc_name) ⇒ Object

Returns the foreign key name for an association

Raises:

  • (NotImplementedError)


89
90
91
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 89

def foreign_key_for assoc_name
  raise NotImplementedError
end

#get_assoc_property_type(assoc_name, prop_name) ⇒ Object

gets the type of a model attribute for xtype mapping i.e. get_assoc_property_type :author,:first_name should return :string Possible types to return :integer :boolean :date :datetime :time :text :string

Raises:

  • (NotImplementedError)


69
70
71
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 69

def get_assoc_property_type assoc_name, prop_name
  raise NotImplementedError
end

#get_property_type(column) ⇒ Object

like get_assoc_property_type but for non-association columns



74
75
76
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 74

def get_property_type column
  column.type
end

#get_records(params, columns) ⇒ Object

Returns records based on passed params. Implements:

  • pagination

  • filtering

  • scopes

‘params` is a hash that contains the following keys:

  • :sort - sorting params, which is an array of hashes that contain the following keys in their turn:

    • :property - the field that is being sorted on

    • :direction - “asc” or “desc”

  • :limit - rows per page in pagination

  • :start - page number in pagination

  • :scope - the scope as described in Netzke::Basepack::GridPanel

  • :filter - Ext filters

The ‘columns` parameter may be used to use joins to address the n+1 query problem, and receives an array of column configurations



21
22
23
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 21

def get_records(params, columns)
  []
end

#hash_fk_modelObject

Build a hash of foreign keys and the associated model

Raises:

  • (NotImplementedError)


134
135
136
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 134

def hash_fk_model
  raise NotImplementedError
end

#map_type(type) ⇒ Object

Map a ORM type to a type symbol Possible types to return :integer :boolean :date :datetime :time :text :string

Default implementation works for ActiveRecord



55
56
57
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 55

def map_type type
  type
end

#move_records(params) ⇒ Object

Changes records position (e.g. when acts_as_list is used in ActiveRecord).

‘params` is a hash with the following keys:

  • :ids - ids of records to move

  • :new_index - new starting position for the records to move



108
109
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 108

def move_records(params)
end

#new_record(params = {}) ⇒ Object

Returns a new record.



112
113
114
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 112

def new_record(params = {})
  @model_class.new(params)
end

#save_record(record) ⇒ Object

give the data adapter the opportunity the set special options for saving, must return true on success



118
119
120
# File 'lib/netzke/basepack/data_adapters/abstract_adapter.rb', line 118

def save_record(record)
  record.save
end