Class: ApiMaker::Deserializer
- Inherits:
-
ApplicationService
- Object
- ServicePattern::Service
- ApplicationService
- ApiMaker::Deserializer
- Defined in:
- app/services/api_maker/deserializer.rb
Instance Attribute Summary collapse
-
#arg ⇒ Object
readonly
Returns the value of attribute arg.
Instance Method Summary collapse
- #deserialize ⇒ Object
-
#initialize(arg:) ⇒ Deserializer
constructor
A new instance of Deserializer.
- #perform ⇒ Object
Methods inherited from ApplicationService
Constructor Details
#initialize(arg:) ⇒ Deserializer
Returns a new instance of Deserializer.
4 5 6 |
# File 'app/services/api_maker/deserializer.rb', line 4 def initialize(arg:) @arg = arg end |
Instance Attribute Details
#arg ⇒ Object (readonly)
Returns the value of attribute arg.
2 3 4 |
# File 'app/services/api_maker/deserializer.rb', line 2 def arg @arg end |
Instance Method Details
#deserialize ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/services/api_maker/deserializer.rb', line 12 def deserialize if arg.is_a?(Array) arg.map { |value| ApiMaker::Deserializer.execute!(arg: value) } elsif arg.is_a?(Hash) || arg.is_a?(ActionController::Parameters) if arg["api_maker_type"] == "resource" "Resources::#{arg.fetch("name")}Resource".safe_constantize elsif arg["api_maker_type"] == "datetime" Time.zone.parse(arg.fetch("value")) else new_hash = arg.class.new arg.each do |key, value| deserialized_key = ApiMaker::Deserializer.execute!(arg: key) deserialized_value = ApiMaker::Deserializer.execute!(arg: value) new_hash[deserialized_key] = deserialized_value end new_hash end else arg end end |
#perform ⇒ Object
8 9 10 |
# File 'app/services/api_maker/deserializer.rb', line 8 def perform succeed! deserialize end |