Sha256: e8687b90bec1dd2c6a6d68a789847fde1deaeb54880433f85cf21188b42ffe2a

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module SimpleAdmin
  class Builder
    attr_accessor :interface

    def initialize(interface, &block)
      @interface = interface
      instance_eval(&block) if block_given?
    end

    def section(sym, options={}, &block)
      start = Time.now
      @interface.sections[sym] = SimpleAdmin::Section.new(@interface, sym, options, &block)
      Rails.logger.info("[#{Time.now}] *** Built section #{sym} for #{interface.collection} (elapsed #{Time.now - start})")
    end

    def index(options={}, &block)
      section(:index, options, &block)
    end

    def form(options={}, &block)
      section(:form, options, &block)
    end

    def show(options={}, &block)
      section(:show, options, &block)
    end

    def before(options={}, &block)
      options[:data] = block
      options[:actions] = options[:actions] || [:index, :show, :edit, :new, :destroy, :create, :update]
      options[:actions] -= options[:except] if options[:except]
      options[:actions] &= options[:only] if options[:only]
      @interface.before_filters << options
    end

    # Comfort the masses
    alias_method :before_filter, :before

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_admin-0.7.1 lib/simple_admin/builder.rb