Sha256: b6fe06ec4c530ea2fcbae463ac98b24a4bab6f3ac3b8d14a6992407427f89a8c

Contents?: true

Size: 981 Bytes

Versions: 3

Compression:

Stored size: 981 Bytes

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)
      @interface.sections[sym] = SimpleAdmin::Section.new(@interface, sym, options, &block)
    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, :delete, :create, :update]
      options[:actions] -= options[:except] if options[:except]
      options[:actions] &= options[:only] if options[:only]
      @interface.before << options
    end

    # Comfort the masses
    alias_method :before_filter, :before

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
simple_admin-0.3.1 lib/simple_admin/builder.rb
simple_admin-0.3.0 lib/simple_admin/builder.rb
simple_admin-0.2.1 lib/simple_admin/builder.rb