Class: Smooth::Backends::ActiveRecord
- Inherits:
-
Base
- Object
- Base
- Smooth::Backends::ActiveRecord
show all
- Defined in:
- lib/smooth/backends/active_record.rb
Defined Under Namespace
Modules: QueryAdapter
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#maximum_updated_at, #records
Constructor Details
#initialize(options = {}) ⇒ ActiveRecord
Returns a new instance of ActiveRecord.
7
8
9
10
11
12
|
# File 'lib/smooth/backends/active_record.rb', line 7
def initialize options={}
super
if @model = options[:model]
model.send(:include, Smooth::Backends::ActiveRecord::QueryAdapter)
end
end
|
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
5
6
7
|
# File 'lib/smooth/backends/active_record.rb', line 5
def model
@model
end
|
Instance Method Details
#create(attributes) ⇒ Object
36
37
38
|
# File 'lib/smooth/backends/active_record.rb', line 36
def create attributes
record = model.create(attributes)
end
|
#destroy(id) ⇒ Object
32
33
34
|
# File 'lib/smooth/backends/active_record.rb', line 32
def destroy id
!!(model = model.find(id) && model.destroy)
end
|
#index ⇒ Object
18
19
20
|
# File 'lib/smooth/backends/active_record.rb', line 18
def index
model.scoped
end
|
#query(params = {}) ⇒ Object
14
15
16
|
# File 'lib/smooth/backends/active_record.rb', line 14
def query params={}
model.respond_to?(:query) ? model.query(params) : model.smooth_query(params)
end
|
#show(id) ⇒ Object
22
23
24
|
# File 'lib/smooth/backends/active_record.rb', line 22
def show id
model.find(id)
end
|
#update(attributes) ⇒ Object
26
27
28
29
30
|
# File 'lib/smooth/backends/active_record.rb', line 26
def update attributes
record = model.find(attributes[:id])
record.update_attributes(attributes)
record
end
|