Class: AbAdmin::Config::BaseBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ab_admin/config/base.rb

Direct Known Subclasses

Export, FieldGroup, Form, Search, Show, Table

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ BaseBuilder


9
10
11
12
13
14
# File 'lib/ab_admin/config/base.rb', line 9

def initialize(options={}, &block)
  @fields = []
  @options = options
  @partial = options[:partial]
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields


4
5
6
# File 'lib/ab_admin/config/base.rb', line 4

def fields
  @fields
end

#optionsObject (readonly)

Returns the value of attribute options


4
5
6
# File 'lib/ab_admin/config/base.rb', line 4

def options
  @options
end

#partialObject

Returns the value of attribute partial


5
6
7
# File 'lib/ab_admin/config/base.rb', line 5

def partial
  @partial
end

Class Method Details

.default_for_model(model, options = {}) ⇒ Object


20
21
22
23
24
25
26
27
28
29
# File 'lib/ab_admin/config/base.rb', line 20

def self.default_for_model(model, options={})
  new.tap do |builder|
    builder.field(:id) unless options[:skip].try(:include?, :id)
    model.content_columns.each do |column|
      column_name = column.name.to_sym
      next if options[:skip].try(:include?, column_name)
      builder.field(column_name)
    end
  end
end

Instance Method Details

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


16
17
18
# File 'lib/ab_admin/config/base.rb', line 16

def field(name, options={}, &block)
  @fields << Field.new(name, options.reverse_merge!(field_defaults), &block)
end