Class: Faalis::Dashboard::Models::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/faalis/dashboard/models/sidebar.rb

Direct Known Subclasses

Menu

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Item) initialize(title, options)

Returns a new instance of Item



5
6
7
8
9
# File 'lib/faalis/dashboard/models/sidebar.rb', line 5

def initialize(title, options)
  @title = title
  @model = nil
  extract_options(options)
end

Instance Attribute Details

- (Object) icon (readonly)

Returns the value of attribute icon



4
5
6
# File 'lib/faalis/dashboard/models/sidebar.rb', line 4

def icon
  @icon
end

- (Object) model (readonly)

Returns the value of attribute model



4
5
6
# File 'lib/faalis/dashboard/models/sidebar.rb', line 4

def model
  @model
end

- (Object) title (readonly)

Returns the value of attribute title



4
5
6
# File 'lib/faalis/dashboard/models/sidebar.rb', line 4

def title
  @title
end

- (Object) url (readonly)

Returns the value of attribute url



4
5
6
# File 'lib/faalis/dashboard/models/sidebar.rb', line 4

def url
  @url
end

Instance Method Details

- (Object) extract_options(options) (private)



31
32
33
34
35
# File 'lib/faalis/dashboard/models/sidebar.rb', line 31

def extract_options(options)
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

- (Boolean) visible?(user)

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/faalis/dashboard/models/sidebar.rb', line 11

def visible?(user)
  return true if @model.nil?

  if @model.respond_to? :map
    permissions = @model.map do |model|
      # Find the appropriate policy for each model
      # and authorize the user against that.
      Pundit.policy!(user, model.to_sym).index?
    end
    # If user don't have access to none of the models
    # then the menu should not be visible
    permissions.any?
  else

    # Authorize the menu visibility against user and given model
    Pundit.policy!(user, @model.to_sym).index?
  end
end