Class: Rack::Scaffold::Adapters::ActiveRecord

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rack/scaffold/adapters/active_record.rb

Instance Attribute Summary

Attributes inherited from Base

#klass

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#all, #count, #create!, #destroy!, #find, inherited, #initialize, #method_missing, #timestamps?, #update!

Constructor Details

This class inherits a constructor from Rack::Scaffold::Adapters::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rack::Scaffold::Adapters::Base

Class Method Details

.===(model) ⇒ Object



11
12
13
# File 'lib/rack/scaffold/adapters/active_record.rb', line 11

def ===(model)
  ::ActiveRecord::Base === model
end

.resources(model, options = {}) ⇒ Object



15
16
17
# File 'lib/rack/scaffold/adapters/active_record.rb', line 15

def resources(model, options = {})
  model
end

.timestamps?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rack/scaffold/adapters/active_record.rb', line 19

def timestamps?
  record_timestamps?
end

Instance Method Details

#[](id) ⇒ Object



36
37
38
# File 'lib/rack/scaffold/adapters/active_record.rb', line 36

def [](id)
  self.find(id)
end

#one_to_many_associationsObject



40
41
42
# File 'lib/rack/scaffold/adapters/active_record.rb', line 40

def one_to_many_associations
  @klass.reflect_on_all_associations(:has_many).collect(&:name)
end

#paginate(limit, offset) ⇒ Object



32
33
34
# File 'lib/rack/scaffold/adapters/active_record.rb', line 32

def paginate(limit, offset)
  @klass.limit(limit).offset(offset)
end

#pluralObject



28
29
30
# File 'lib/rack/scaffold/adapters/active_record.rb', line 28

def plural
  @klass.table_name
end

#singularObject



24
25
26
# File 'lib/rack/scaffold/adapters/active_record.rb', line 24

def singular
  @klass.name.downcase
end

#update_timestamp_fieldObject



44
45
46
# File 'lib/rack/scaffold/adapters/active_record.rb', line 44

def update_timestamp_field
  self.attribute_names.include?("updated_at") ? "updated_at" : "updated_on"
end