Class: Cas::SectionConfig
- Inherits:
-
Object
- Object
- Cas::SectionConfig
- Defined in:
- lib/cas/section_config.rb
Instance Method Summary collapse
- #accessible_by_user?(user) ⇒ Boolean
- #form_has_field?(field) ⇒ Boolean
-
#initialize(section) ⇒ SectionConfig
constructor
A new instance of SectionConfig.
- #list_fields ⇒ Object
- #list_order_by ⇒ Object
Constructor Details
#initialize(section) ⇒ SectionConfig
Returns a new instance of SectionConfig.
3 4 5 |
# File 'lib/cas/section_config.rb', line 3 def initialize(section) @section = section end |
Instance Method Details
#accessible_by_user?(user) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cas/section_config.rb', line 17 def accessible_by_user?(user) roles = user.roles.map(&:to_s) accessible_roles = load_field["accessible_roles"] if accessible_roles.present? (accessible_roles.map(&:to_s) & roles).compact.present? else true end end |
#form_has_field?(field) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cas/section_config.rb', line 28 def form_has_field?(field) section_fields = load_section_config[1]["fields"] Array.wrap(section_fields).any? do |section_field| if section_field.is_a?(Hash) section_field.keys.map(&:to_s).include?(field.to_s) else section_field.to_s == field.to_s end end end |
#list_fields ⇒ Object
12 13 14 15 |
# File 'lib/cas/section_config.rb', line 12 def list_fields fields = load_section_config[1]["list_fields"] fields || ['title', 'created_at'] end |
#list_order_by ⇒ Object
7 8 9 10 |
# File 'lib/cas/section_config.rb', line 7 def list_order_by order_field = load_section_config[1]['list_order_by'] order_field || ['created_at'] end |