Module: API::Entities::EntityHelpers

Included in:
Package
Defined in:
lib/api/entities/entity_helpers.rb

Instance Method Summary collapse

Instance Method Details

#can_destroy(attr, &block) ⇒ Object



10
11
12
# File 'lib/api/entities/entity_helpers.rb', line 10

def can_destroy(attr, &block)
  ->(obj, opts) { Ability.allowed?(opts[:user], "destroy_#{attr}".to_sym, yield(obj)) }
end

#can_read(attr, &block) ⇒ Object



6
7
8
# File 'lib/api/entities/entity_helpers.rb', line 6

def can_read(attr, &block)
  ->(obj, opts) { Ability.allowed?(opts[:user], "read_#{attr}".to_sym, yield(obj)) }
end

#expose_restricted(attr, documentation: {}, &block) ⇒ Object



14
15
16
# File 'lib/api/entities/entity_helpers.rb', line 14

def expose_restricted(attr, documentation: {}, &block)
  expose attr, documentation: documentation, if: can_read(attr, &block)
end