Class: SimpleAdmin::Interface
- Inherits:
-
Object
- Object
- SimpleAdmin::Interface
- Defined in:
- lib/simple_admin/interface.rb
Instance Attribute Summary collapse
-
#before_filters ⇒ Object
readonly
Returns the value of attribute before_filters.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#constant ⇒ Object
readonly
Returns the value of attribute constant.
-
#member ⇒ Object
readonly
Returns the value of attribute member.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
Instance Method Summary collapse
- #actions ⇒ Object
- #attributes_for(sym, mode = nil) ⇒ Object
- #before ⇒ Object
- #filters_for(sym) ⇒ Object
-
#initialize(resource, options = {}, &block) ⇒ Interface
constructor
A new instance of Interface.
- #options_for(sym) ⇒ Object
- #route ⇒ Object
- #sidebars_for(sym) ⇒ Object
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, ={}, &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 = @sections = {} @block = block @before_filters = [] self end |
Instance Attribute Details
#before_filters ⇒ Object (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 |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
5 6 7 |
# File 'lib/simple_admin/interface.rb', line 5 def collection @collection end |
#constant ⇒ Object (readonly)
Returns the value of attribute constant.
5 6 7 |
# File 'lib/simple_admin/interface.rb', line 5 def constant @constant end |
#member ⇒ Object (readonly)
Returns the value of attribute member.
5 6 7 |
# File 'lib/simple_admin/interface.rb', line 5 def member @member end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/simple_admin/interface.rb', line 5 def @options end |
#sections ⇒ Object (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
#actions ⇒ Object
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 ||= (sym)[:attributes] @attributes ||= section(sym).attributes @attributes.attributes.select{|a| a[:mode] == mode} end |
#before ⇒ Object
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 ||= (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 (sym) sym = :form if [:new, :edit].include?(sym) section(sym). || {} end |
#route ⇒ Object
24 25 26 |
# File 'lib/simple_admin/interface.rb', line 24 def route @options[:route] || @collection end |
#sidebars_for(sym) ⇒ Object
40 41 42 |
# File 'lib/simple_admin/interface.rb', line 40 def (sym) @sidebars ||= (sym)[:sidebars] || [] end |