class Databound::Controller

Public Class Methods

as_constant_string(name) click to toggle source
# File lib/databound/controller.rb, line 48
def as_constant_string(name)
  "#{name.camelize}Controller"
end
create(name, resource, opts) click to toggle source
# File lib/databound/controller.rb, line 8
def create(name, resource, opts)
  opts ||= {}
  Object.const_set(as_constant_string(name), new(resource, opts))
end
exists?(path) click to toggle source
# File lib/databound/controller.rb, line 32
def exists?(path)
  name_error = false

  begin
    as_constant_string(path).constantize
  rescue NameError
    name_error = true
  end

  !name_error
end
fallback_model(resource) click to toggle source
# File lib/databound/controller.rb, line 28
def fallback_model(resource)
  resource.to_s.classify.underscore.to_sym
end
find(path) click to toggle source
# File lib/databound/controller.rb, line 44
def find(path)
  as_constant_string(path).constantize if exists?(path)
end
find_or_create(name, resource, opts) click to toggle source
# File lib/databound/controller.rb, line 4
def find_or_create(name, resource, opts)
  find(name) || create(name, resource, opts)
end
new(resource, opts) click to toggle source
# File lib/databound/controller.rb, line 13
def new(resource, opts)
  model_name = opts.delete(:model) || fallback_model(resource)

  result = Class.new(ApplicationController)
  result.send(:databound) do
    model model_name

    opts.each do |key, value|
      send(key, *value)
    end
  end

  result
end