| Total Complexity | 1 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | # frozen_string_literal: true |
||
| 10 | class Remote |
||
| 11 | include Mixin::Entity |
||
| 12 | |||
| 13 | attribute :id, Symbol |
||
| 14 | attribute :options, [Hash, K: String, V: [String, Integer]] |
||
| 15 | |||
| 16 | denormalizer_block do |input, type, context, &block| |
||
| 17 | input = {} if input.nil? |
||
| 18 | if input.is_a?(String) || input.is_a?(Symbol) |
||
| 19 | input = { User: input } |
||
| 20 | end |
||
| 21 | raise "Expected Hash, got #{input.class}" unless input.is_a?(Hash) |
||
| 22 | target = { |
||
| 23 | options: input[:options] || input['options'] || {}, |
||
| 24 | id: context.path.current.name |
||
| 25 | } |
||
| 26 | ['id', :id].each do |key| |
||
| 27 | target[:id] = input[key] if input[key] |
||
| 28 | end |
||
| 29 | input.each do |key, value| |
||
| 30 | next if %i[id options].include?(key.to_sym) |
||
| 31 | target[:options][key] = value |
||
| 32 | end |
||
| 33 | block.call(target, type, context) |
||
| 34 | end |
||
| 35 | |||
| 36 | def initialize(id = nil) |
||
| 37 | @id = id |
||
| 38 | @options = {} |
||
| 39 | end |
||
| 40 | end |
||
| 41 | end |
||
| 46 |