Class: Kix::Serializer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Serializer

Returns a new instance of Serializer.



7
8
9
# File 'lib/kix/serializer.rb', line 7

def initialize(object)
  @_object = object
end

Instance Attribute Details

#_objectObject (readonly)

Returns the value of attribute _object.



5
6
7
# File 'lib/kix/serializer.rb', line 5

def _object
  @_object
end

Class Method Details

.attributes(*attrs) ⇒ Object Also known as: attribute



32
33
34
# File 'lib/kix/serializer.rb', line 32

def attributes(*attrs)
  attrs.each { |attr| defined_attributes.push(attr.to_s) }
end

.defined_attributesObject



37
38
39
# File 'lib/kix/serializer.rb', line 37

def defined_attributes
  @defined_attributes ||= []
end

.inherited(subclass) ⇒ Object



28
29
30
# File 'lib/kix/serializer.rb', line 28

def inherited(subclass)
  subclass.attributes(*@defined_attributes)
end

Instance Method Details

#as_json(*args) ⇒ Object



11
12
13
14
15
# File 'lib/kix/serializer.rb', line 11

def as_json(*args)
  self.class.defined_attributes.each_with_object({}) { |attr, h|
    catch(:skip) { h[attr] = value_for(attr, args).as_json }
  }
end