Sha256: 809db151552740393d1e384f3f1a1fe680536fd57ed9b1adbf3884510628726c

Contents?: true

Size: 742 Bytes

Versions: 1

Compression:

Stored size: 742 Bytes

Contents

module Databound
  class Utils
    def self.create_controller_unless_exists(path, resource, opts)
      return if exists?(path)

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

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

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

      true
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
databound-2.0.0 lib/databound/utils.rb