Class: Grape::Entity::Exposure::FormatterExposure
- Defined in:
- lib/grape_entity/exposure/formatter_exposure.rb
Instance Attribute Summary collapse
-
#format_with ⇒ Object
readonly
Returns the value of attribute format_with.
Attributes inherited from Base
#attribute, #conditions, #documentation, #for_merge, #is_safe, #override
Instance Method Summary collapse
- #==(other) ⇒ Object
- #dup_args ⇒ Object
- #setup(format_with) ⇒ Object
- #value(entity, _options) ⇒ Object
Methods inherited from Base
#attr_path, #conditional?, #conditions_met?, #deep_complex_nesting?, #dup, #initialize, #key, #nesting?, new, #override?, #serializable_value, #should_expose?, #should_return_key?, #valid?, #valid_value, #with_attr_path
Constructor Details
This class inherits a constructor from Grape::Entity::Exposure::Base
Instance Attribute Details
#format_with ⇒ Object (readonly)
Returns the value of attribute format_with.
7 8 9 |
# File 'lib/grape_entity/exposure/formatter_exposure.rb', line 7 def format_with @format_with end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/grape_entity/exposure/formatter_exposure.rb', line 17 def ==(other) super && @format_with == other.format_with end |
#dup_args ⇒ Object
13 14 15 |
# File 'lib/grape_entity/exposure/formatter_exposure.rb', line 13 def dup_args [*super, format_with] end |
#setup(format_with) ⇒ Object
9 10 11 |
# File 'lib/grape_entity/exposure/formatter_exposure.rb', line 9 def setup(format_with) @format_with = format_with end |
#value(entity, _options) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/grape_entity/exposure/formatter_exposure.rb', line 21 def value(entity, ) formatters = entity.class.formatters if formatters[@format_with] entity.exec_with_attribute(attribute, &formatters[@format_with]) else entity.send(@format_with, entity.delegate_attribute(attribute)) end end |