Sha256: 70e446da8f32b4ed4fafbee0507fa897ae72163bc7130e51a4ac348794ff40c5

Contents?: true

Size: 632 Bytes

Versions: 4

Compression:

Stored size: 632 Bytes

Contents

module Databound
  class Utils
    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

    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

4 entries across 4 versions & 1 rubygems

Version Path
databound-1.1.0 lib/databound/utils.rb
databound-1.0.2 lib/databound/utils.rb
databound-1.0.1 lib/databound/utils.rb
databound-1.0.0 lib/databound/utils.rb