Class: Userlist::Push::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/userlist/push/serializer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:) ⇒ Serializer



12
13
14
# File 'lib/userlist/push/serializer.rb', line 12

def initialize(context:)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



10
11
12
# File 'lib/userlist/push/serializer.rb', line 10

def context
  @context
end

Class Method Details

.serialize(resource, **options) ⇒ Object



6
7
8
# File 'lib/userlist/push/serializer.rb', line 6

def self.serialize(resource, **options)
  new(**options).serialize(resource)
end

Instance Method Details

#serialize(resource) ⇒ Object



16
17
18
19
# File 'lib/userlist/push/serializer.rb', line 16

def serialize(resource)
  resource = serialize_resource(resource) if resource.is_a?(Userlist::Push::Resource)
  resource
end

#serialize?(resource) ⇒ Boolean



21
22
23
24
25
26
# File 'lib/userlist/push/serializer.rb', line 21

def serialize?(resource)
  method_name = "#{context}?"

  resource.respond_to?(method_name) &&
    resource.public_send(method_name)
end