Class: Para::Acl::ComponentRolesCollection
- Inherits:
-
Object
- Object
- Para::Acl::ComponentRolesCollection
- Includes:
- ActiveModel::Model, ActiveRecord::AttributeAssignment
- Defined in:
- lib/para/acl/component_roles_collection.rb
Instance Method Summary collapse
- #persisted? ⇒ Boolean
- #resources ⇒ Object
- #resources_attributes=(ary) ⇒ Object
- #roles ⇒ Object
- #save ⇒ Object
- #update(attributes) ⇒ Object
- #valid? ⇒ Boolean
Instance Method Details
#persisted? ⇒ Boolean
12 13 14 |
# File 'lib/para/acl/component_roles_collection.rb', line 12 def persisted? true end |
#resources ⇒ Object
39 40 41 42 43 44 45 46 47 |
# 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) ⇒ Object
32 33 34 35 36 37 |
# 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 ⇒ Object
26 27 28 29 30 |
# 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 ⇒ Object
16 17 18 19 20 |
# 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) ⇒ Object
7 8 9 10 |
# File 'lib/para/acl/component_roles_collection.rb', line 7 def update(attributes) assign_attributes(attributes) save end |
#valid? ⇒ Boolean
22 23 24 |
# File 'lib/para/acl/component_roles_collection.rb', line 22 def valid? role_components.values.all?(&:valid?) end |