class Para::Acl::ComponentRolesCollection
Public Instance Methods
persisted?()
click to toggle source
# File lib/para/acl/component_roles_collection.rb, line 12 def persisted? true end
resources()
click to toggle source
# File lib/para/acl/component_roles_collection.rb, line 39 def resources @resources ||= Para::Component::Base.order('para_components.name ASC').each_with_object({}) do |component, hash| hash[component] = {} roles.each do |role| hash[component][role] = role_component_or_create_for(role, component) end end end
resources_attributes=(ary)
click to toggle source
# File lib/para/acl/component_roles_collection.rb, line 32 def resources_attributes=(ary) ary.each do |_, attributes| role_component = role_component_for(attributes.delete(:id)) role_component.assign_attributes(attributes) end end
roles()
click to toggle source
# File lib/para/acl/component_roles_collection.rb, line 26 def roles @roles ||= Para::Acl::Role.includes( role_components: :component ).order('para_acl_roles.name ASC') end
save()
click to toggle source
# File lib/para/acl/component_roles_collection.rb, line 16 def save ActiveRecord::Base.transaction do role_components.values.each(&:save!) end if valid? end
update(attributes)
click to toggle source
# File lib/para/acl/component_roles_collection.rb, line 7 def update(attributes) assign_attributes(attributes) save end
valid?()
click to toggle source
# File lib/para/acl/component_roles_collection.rb, line 22 def valid? role_components.values.all?(&:valid?) end
Private Instance Methods
role_component_for(id)
click to toggle source
# File lib/para/acl/component_roles_collection.rb, line 51 def role_component_for(id) role_components[id.to_i] end
role_component_or_create_for(role, component)
click to toggle source
# File lib/para/acl/component_roles_collection.rb, line 55 def role_component_or_create_for(role, component) role.role_component_for(component).tap do |role_component| if role_component.new_record? role_component.allow = role.authorize_new_components role_component.save! end end end
role_components()
click to toggle source
# File lib/para/acl/component_roles_collection.rb, line 64 def role_components @role_components ||= roles.each_with_object({}) do |role, hash| role.role_components.each do |role_component| hash[role_component.id] = role_component end end end