Module: EasySerializer::Helpers

Included in:
Attribute, AttributeSerializer, Base, Cacher::Template, Field, RootCacher
Defined in:
lib/easy_serializer/helpers.rb

Instance Method Summary collapse

Instance Method Details

#cache_key(input_object = nil) ⇒ Object



17
18
19
20
21
# File 'lib/easy_serializer/helpers.rb', line 17

def cache_key(input_object = nil)
  _object = input_object || subject
  return _object.cache_key if _object.respond_to?(:cache_key)
  _object
end

#option_to_value(option, value, instance = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/easy_serializer/helpers.rb', line 3

def option_to_value(option, value, instance = nil)
  inst = instance || self
  case option
  when Proc
    inst.instance_exec value, &option
    # TODO
    # Will be nice to be able to add classes in the options responding to call
    # for complex algorithms.
    # when ->(opt) { opt.respond_to?(:call) }
  else
    option
  end
end