Sha256: f07fbae88257a77fc2469ea0469d75487b32c68b68ef9a0311a055c5c88ad3a5

Contents?: true

Size: 1015 Bytes

Versions: 32

Compression:

Stored size: 1015 Bytes

Contents

require "fiona7/json/obj_decorator"

module Fiona7
  module JSON
    class ReverseObjDecorator < ObjDecorator
      def as_json(*args)
        with_types = super()
        reverse_types = {}

        with_types.each do |attr, (value, type)|
          if type.nil?
            reverse_types[attr] = value
          else
            reverse_types[attr] = [type, value]
          end
        end

        if reverse_types[:_widget_pool] && !reverse_types[:_widget_pool].empty?
          widgets_reverse_types = reverse_types[:_widget_pool].map do |id, values|
            reversed_values = {}
            values.each do |attr, (value, type)|
              if type.nil?
                reversed_values[attr] = value
              else
                reversed_values[attr] = [type, value]
              end
            end
            [id, reversed_values]
          end

          reverse_types[:_widget_pool] = Hash[widgets_reverse_types]
        end

        reverse_types.as_json(*args)
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
infopark_fiona7-1.2.0.0.0 lib/fiona7/json/reverse_obj_decorator.rb
infopark_fiona7-1.1.0.0.9 lib/fiona7/json/reverse_obj_decorator.rb
infopark_fiona7-1.1.0.0.8 lib/fiona7/json/reverse_obj_decorator.rb
infopark_fiona7-1.1.0.0.7 lib/fiona7/json/reverse_obj_decorator.rb
infopark_fiona7-1.1.0.0.6 lib/fiona7/json/reverse_obj_decorator.rb
infopark_fiona7-1.1.0.0.5 lib/fiona7/json/reverse_obj_decorator.rb
infopark_fiona7-1.1.0.0.4 lib/fiona7/json/reverse_obj_decorator.rb
infopark_fiona7-1.1.0.0.3 lib/fiona7/json/reverse_obj_decorator.rb
infopark_fiona7-1.1.0.0.2 lib/fiona7/json/reverse_obj_decorator.rb
infopark_fiona7-1.1.0.0.10 lib/fiona7/json/reverse_obj_decorator.rb
infopark_fiona7-1.1.0.0.1 lib/fiona7/json/reverse_obj_decorator.rb
infopark_fiona7-1.1.0.0.0 lib/fiona7/json/reverse_obj_decorator.rb