Class: SimpleAdmin::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_admin/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interface, &block) ⇒ Builder

Returns a new instance of Builder.



5
6
7
8
# File 'lib/simple_admin/builder.rb', line 5

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

Instance Attribute Details

#interfaceObject

Returns the value of attribute interface.



3
4
5
# File 'lib/simple_admin/builder.rb', line 3

def interface
  @interface
end

Instance Method Details

#before(options = {}, &block) ⇒ Object Also known as: before_filter



28
29
30
31
32
33
34
# File 'lib/simple_admin/builder.rb', line 28

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

#form(options = {}, &block) ⇒ Object



20
21
22
# File 'lib/simple_admin/builder.rb', line 20

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

#index(options = {}, &block) ⇒ Object



16
17
18
# File 'lib/simple_admin/builder.rb', line 16

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

#section(sym, options = {}, &block) ⇒ Object



10
11
12
13
14
# File 'lib/simple_admin/builder.rb', line 10

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

#show(options = {}, &block) ⇒ Object



24
25
26
# File 'lib/simple_admin/builder.rb', line 24

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