Class: Shark::Permissions::Changes

Inherits:
Object
  • Object
show all
Defined in:
lib/shark/permissions/changes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChanges

Returns a new instance of Changes.



9
10
11
12
# File 'lib/shark/permissions/changes.rb', line 9

def initialize
  @privileges = {}
  @effect = {}
end

Instance Attribute Details

#effectObject (readonly)

Returns the value of attribute effect.



6
7
8
# File 'lib/shark/permissions/changes.rb', line 6

def effect
  @effect
end

#privilegesObject (readonly)

Returns the value of attribute privileges.



7
8
9
# File 'lib/shark/permissions/changes.rb', line 7

def privileges
  @privileges
end

Instance Method Details

#add(field, old_value, new_value) ⇒ Object



14
15
16
17
18
# File 'lib/shark/permissions/changes.rb', line 14

def add(field, old_value, new_value)
  return if old_value == new_value

  instance_variable_set("@#{field}", { old: old_value, new: old_value })
end

#add_privilege(key, old_value, new_value) ⇒ Object



20
21
22
23
24
25
# File 'lib/shark/permissions/changes.rb', line 20

def add_privilege(key, old_value, new_value)
  @privileges[:old] ||= {}
  @privileges[:new] ||= {}
  @privileges[:old][key] = old_value
  @privileges[:new][key] = new_value
end

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/shark/permissions/changes.rb', line 29

def empty?
  effect.empty? && privileges.empty?
end

#present?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/shark/permissions/changes.rb', line 35

def present?
  !empty?
end