Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion app/serializer.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
class Serializer
end
# class variables
@@attributes ||= {}
@@object ||= []

class << self
# define attribute in post and comment file
def attribute(value, &block)
@@attributes[self] ||= {}
@@attributes[self][value] = block_given? ? block : nil
end

## for date time we calling strf so object is declared here
def object
@@object
end
end

## Initializer defined
def initialize(object)
## Struct object when post or comment new call
@@object = object

## to get current class attributes
@data_hash = @@attributes[self.class]

## call json
display_result
end

## call rspec serilize method
def serialize
## call from spec method
@data_hash
end

def display_result
@data_hash.each{|key, value| @data_hash[key] = value ? value.call() : @@object.send(key)}
end
end