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



13
14
15
# File 'lib/rack/scaffold/adapters/active_record.rb', line 13

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

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



17
18
19
# File 'lib/rack/scaffold/adapters/active_record.rb', line 17

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

.timestamps?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rack/scaffold/adapters/active_record.rb', line 21

def timestamps?
  record_timestamps?
end

Instance Method Details

#[](id) ⇒ Object



38
39
40
# File 'lib/rack/scaffold/adapters/active_record.rb', line 38

def [](id)
  find(id)
end

#one_to_many_associationsObject



42
43
44
# File 'lib/rack/scaffold/adapters/active_record.rb', line 42

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

#paginate(limit, offset) ⇒ Object



34
35
36
# File 'lib/rack/scaffold/adapters/active_record.rb', line 34

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

#pluralObject



30
31
32
# File 'lib/rack/scaffold/adapters/active_record.rb', line 30

def plural
  @klass.table_name
end

#singularObject



26
27
28
# File 'lib/rack/scaffold/adapters/active_record.rb', line 26

def singular
  @klass.name.downcase
end

#update_timestamp_fieldObject



46
47
48
# File 'lib/rack/scaffold/adapters/active_record.rb', line 46

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