Class: Databound::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/databound/utils.rb

Class Method Summary collapse

Class Method Details

.controller_name(path) ⇒ Object



25
26
27
# File 'lib/databound/utils.rb', line 25

def self.controller_name(path)
  "#{path.camelize}Controller"
end

.create_controller_unless_exists(path, resource) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/databound/utils.rb', line 3

def self.create_controller_unless_exists(path, resource)
  return if exists?(path)

  controller = Class.new(ApplicationController)
  controller.send(:include, Databound)
  controller.send(:define_method, :model) do
    resource.to_s.classify.constantize
  end

  Object.const_set(controller_name(path), controller)
end

.exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
# File 'lib/databound/utils.rb', line 15

def self.exists?(path)
  begin
    controller_name(path).constantize
  rescue NameError
    return false
  end

  true
end