Class: Grape::Entity::Exposure::RepresentExposure

Inherits:
Base
  • Object
show all
Defined in:
lib/grape_entity/exposure/represent_exposure.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#attribute, #conditions, #documentation, #for_merge, #is_safe, #key

Instance Method Summary collapse

Methods inherited from Base

#attr_path, #conditional?, #conditions_met?, #deep_complex_nesting?, #dup, #initialize, #nesting?, new, #serializable_value, #should_expose?, #should_return_key?, #valid_value, #with_attr_path

Constructor Details

This class inherits a constructor from Grape::Entity::Exposure::Base

Instance Attribute Details

#subexposureObject (readonly)

Returns the value of attribute subexposure.



5
6
7
# File 'lib/grape_entity/exposure/represent_exposure.rb', line 5

def subexposure
  @subexposure
end

#using_class_nameObject (readonly)

Returns the value of attribute using_class_name.



5
6
7
# File 'lib/grape_entity/exposure/represent_exposure.rb', line 5

def using_class_name
  @using_class_name
end

Instance Method Details

#==(other) ⇒ Object



17
18
19
20
21
# File 'lib/grape_entity/exposure/represent_exposure.rb', line 17

def ==(other)
  super &&
    @using_class_name == other.using_class_name &&
    @subexposure == other.subexposure
end

#dup_argsObject



13
14
15
# File 'lib/grape_entity/exposure/represent_exposure.rb', line 13

def dup_args
  [*super, using_class_name, subexposure]
end

#setup(using_class_name, subexposure) ⇒ Object



7
8
9
10
11
# File 'lib/grape_entity/exposure/represent_exposure.rb', line 7

def setup(using_class_name, subexposure)
  @using_class = nil
  @using_class_name = using_class_name
  @subexposure = subexposure
end

#using_classObject



32
33
34
35
36
37
38
# File 'lib/grape_entity/exposure/represent_exposure.rb', line 32

def using_class
  @using_class ||= if @using_class_name.respond_to? :constantize
                     @using_class_name.constantize
                   else
                     @using_class_name
                   end
end

#valid?(entity) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/grape_entity/exposure/represent_exposure.rb', line 28

def valid?(entity)
  @subexposure.valid? entity
end

#value(entity, options) ⇒ Object



23
24
25
26
# File 'lib/grape_entity/exposure/represent_exposure.rb', line 23

def value(entity, options)
  new_options = options.for_nesting(key)
  using_class.represent(@subexposure.value(entity, options), new_options)
end