Class: Cas::SectionConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/cas/section_config.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
# File 'lib/cas/section_config.rb', line 31

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

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cas/section_config.rb', line 42

def form_has_field?(field)
  config = YAML.load_file(filename)
  sites = config["sites"]
  site = sites[@section.site.slug]
  section = site["sections"]
  section_fields = section.find { |key, value|
    key == @section.slug
  }[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_fieldsObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/cas/section_config.rb', line 20

def list_fields
  config = YAML.load_file(filename)
  sites = config["sites"]
  site = sites[@section.site.slug]
  section = site["sections"]
  fields = section.find { |key, value|
    key == @section.slug
  }[1]["list_fields"]
  fields || ['title', 'created_at']
end

#list_order_byObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cas/section_config.rb', line 7

def list_order_by
  config = YAML.load_file(filename)
  sites = config["sites"]
  site = sites[@section.site.slug]
  section = site["sections"]

  order_field = section.find { |key, value|
    key == @section.slug
  }[1]['list_order_by']

  order_field || ['created_at']
end