Class: Xhive::Mapper
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Xhive::Mapper
- Defined in:
- app/models/xhive/mapper.rb
Overview
Maps resources to pages.
Defined Under Namespace
Classes: InvalidPolicyError
Class Method Summary collapse
-
.all_by_resource(site, resource) ⇒ Object
Public: returns all the mappers for a specific resource.
-
.map_resource(site, page, resource, action, key = nil, policy = nil) ⇒ Object
Public: creates a mapper for a specific resource and page.
-
.page_for(site, resource, action, key = nil, opts = {}) ⇒ Object
Public: looks for a page mapper and returns the associated page.
-
.unmap_resource(site, resource, action, key = nil, policy = nil) ⇒ Object
Public: deletes a mapper for a specific resource.
Class Method Details
.all_by_resource(site, resource) ⇒ Object
Public: returns all the mappers for a specific resource.
site - The Site owner of the mappers. resource - The String containing the resource to filter by.
Returns: an ActiveRecord::Relation filtered by resource.
77 78 79 |
# File 'app/models/xhive/mapper.rb', line 77 def self.all_by_resource(site, resource) where(:site_id => site.id).where(:resource => resource) end |
.map_resource(site, page, resource, action, key = nil, policy = nil) ⇒ Object
Public: creates a mapper for a specific resource and page.
site - The Site to associate the mapper to. page - The Page object to map. resource - The String containing the associated resource name. action - The String containing the associated action name. key - The String containing the associated key. policy - The String containing the policy class.
Returns: true if created. False otherwise.
41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/xhive/mapper.rb', line 41 def self.map_resource(site, page, resource, action, key = nil, policy = nil) check_policy_class(policy) if policy.present? mapper = find_exact_map(site, resource, action, key, policy) mapper = new(:site_id => site.id, :resource => resource, :action => action, :policy => policy.present? ? policy : nil, :key => key.present? ? key : nil) unless mapper.present? mapper.page = page mapper.save end |
.page_for(site, resource, action, key = nil, opts = {}) ⇒ Object
Public: looks for a page mapper and returns the associated page.
site - The Site to look into. resource - The String containing the resource name filter. action - The String containing the action name filter. key - The String containing the key filter. opts - The Hash containing extra values for policy-based filters.
Returns: the mapped page or nil if not found.
25 26 27 28 |
# File 'app/models/xhive/mapper.rb', line 25 def self.page_for(site, resource, action, key = nil, opts = {}) mapper = find_map(site, resource, action, key, opts) page = mapper.try(:page) end |
.unmap_resource(site, resource, action, key = nil, policy = nil) ⇒ Object
Public: deletes a mapper for a specific resource.
site - The Site to associate the mapper to. resource - The String containing the associated resource name. action - The String containing the associated action name. key - The String containing the associated key. policy - The String containing the policy class.
Returns: true if created. False otherwise.
62 63 64 65 66 67 68 |
# File 'app/models/xhive/mapper.rb', line 62 def self.unmap_resource(site, resource, action, key = nil, policy = nil) check_policy_class(policy) if policy.present? mapper = find_exact_map(site, resource, action, key, policy) mapper.delete if mapper.present? end |