From 6464223ce1413f9ab1262b9a86360ef64e5e4972 Mon Sep 17 00:00:00 2001 From: Idrees Ibrahim Date: Thu, 22 Sep 2022 00:44:14 +0500 Subject: [PATCH 1/2] post and comment serialize successfully run. attribute initilize in serilize class --- app/serializer.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/serializer.rb b/app/serializer.rb index 258be50..c17db95 100644 --- a/app/serializer.rb +++ b/app/serializer.rb @@ -1,2 +1,18 @@ 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 +end \ No newline at end of file From 3859a3d7ed5e12c884e851f4a4be17e4b1f5ccc8 Mon Sep 17 00:00:00 2001 From: Idrees Ibrahim Date: Thu, 22 Sep 2022 00:53:22 +0500 Subject: [PATCH 2/2] successfully dry run result --- app/serializer.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/serializer.rb b/app/serializer.rb index c17db95..84a562f 100644 --- a/app/serializer.rb +++ b/app/serializer.rb @@ -2,7 +2,7 @@ class Serializer # class variables @@attributes ||= {} @@object ||= [] - + class << self # define attribute in post and comment file def attribute(value, &block) @@ -15,4 +15,26 @@ 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 \ No newline at end of file