Module: ActiveAdmin::Resource::Scopes
- Included in:
- ActiveAdmin::Resource
- Defined in:
- lib/active_admin/resource/scopes.rb
Instance Method Summary collapse
- #default_scope(context = nil) ⇒ Object
-
#get_scope_by_id(id) ⇒ Object
Returns a scope for this object by its identifier.
-
#scope(*args, &block) ⇒ Object
Create a new scope object for this resource.
-
#scopes ⇒ Object
Return an array of scopes for this resource.
Instance Method Details
#default_scope(context = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/active_admin/resource/scopes.rb', line 17 def default_scope(context = nil) scopes.detect do |scope| if scope.default_block.is_a?(Proc) render_in_context(context, scope.default_block) else scope.default_block end end end |
#get_scope_by_id(id) ⇒ Object
Returns a scope for this object by its identifier
12 13 14 15 |
# File 'lib/active_admin/resource/scopes.rb', line 12 def get_scope_by_id(id) id = id.to_s scopes.find { |s| s.id == id } end |
#scope(*args, &block) ⇒ Object
Create a new scope object for this resource. If you want to internationalize the scope name, you can add to your i18n files a key like “active_admin.scopes.scope_method”.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_admin/resource/scopes.rb', line 30 def scope(*args, &block) = { show_count: namespace.scopes_show_count } = .merge(args.) title = args[0] rescue nil method = args[1] rescue nil [:localizer] ||= ActiveAdmin::Localizers.resource(self) scope = ActiveAdmin::Scope.new(title, method, , &block) # Finds and replaces a scope by the same name if it already exists existing_scope_index = scopes.index { |existing_scope| existing_scope.id == scope.id } if existing_scope_index scopes.delete_at(existing_scope_index) scopes.insert(existing_scope_index, scope) else self.scopes << scope end scope end |
#scopes ⇒ Object
Return an array of scopes for this resource
7 8 9 |
# File 'lib/active_admin/resource/scopes.rb', line 7 def scopes @scopes ||= [] end |