Class: SimpleAdmin::Interface

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Interface.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/simple_admin/interface.rb', line 7

def initialize(resource, options={}, &block)
  if resource.is_a?(Class)
    @constant = resource
    @symbol = resource.name.underscore.to_sym
  else
    @constant = resource.to_s.camelize.singularize.constantize rescue nil
    @symbol = resource.to_sym
  end
  @member = @symbol.to_s.singularize
  @collection = @symbol.to_s.pluralize
  @options = options
  @sections = {}
  @block = block
  @before_filters = []
  self
end

Instance Attribute Details

#before_filtersObject (readonly)

Returns the value of attribute before_filters.



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

def before_filters
  @before_filters
end

#collectionObject (readonly)

Returns the value of attribute collection.



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

def collection
  @collection
end

#constantObject (readonly)

Returns the value of attribute constant.



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

def constant
  @constant
end

#memberObject (readonly)

Returns the value of attribute member.



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

def member
  @member
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#sectionsObject (readonly)

Returns the value of attribute sections.



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

def sections
  @sections
end

Instance Method Details

#actionsObject



49
50
51
52
53
54
# File 'lib/simple_admin/interface.rb', line 49

def actions
  arr =  @options[:actions] || [:index, :show, :edit, :new, :destroy, :create, :update]
  arr -= @options[:except] if @options[:except]
  arr &= @options[:only] if @options[:only]
  arr
end

#attributes_for(sym, mode = nil) ⇒ Object



34
35
36
37
38
# File 'lib/simple_admin/interface.rb', line 34

def attributes_for(sym, mode=nil)
  @attributes ||= options_for(sym)[:attributes]
  @attributes ||= section(sym).attributes
  @attributes.attributes.select{|a| a[:mode] == mode}
end

#beforeObject



56
57
58
59
# File 'lib/simple_admin/interface.rb', line 56

def before
  @builder ||= SimpleAdmin::Builder.new(self, &@block)
  @before_filters
end

#filters_for(sym) ⇒ Object



28
29
30
31
32
# File 'lib/simple_admin/interface.rb', line 28

def filters_for(sym)
  @filters ||= options_for(sym)[:filters]
  @filters ||= section(sym).filters
  @filters.attributes
end

#options_for(sym) ⇒ Object



44
45
46
47
# File 'lib/simple_admin/interface.rb', line 44

def options_for(sym)
  sym = :form if [:new, :edit].include?(sym)
  section(sym).options || {}
end

#routeObject



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

def route
  @options[:route] || @collection
end


40
41
42
# File 'lib/simple_admin/interface.rb', line 40

def sidebars_for(sym)
  @sidebars ||= options_for(sym)[:sidebars] || []
end