Method: Attrify::Parser.parse_operation

Defined in:
lib/attrify/parser.rb

.parse_operation(operation) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/attrify/parser.rb', line 162

def parse_operation(operation)
  case operation
  when Hash
    if !is_simple_operation?(operation)
      raise ArgumentError, "Invalid operation: got #{operation}"
    end
    operation.transform_values { |v|
      if v.is_a?(Array)
        v.map { |x| x.is_a?(Proc) ? x : x.to_s }
      else
        [v.is_a?(Proc) ? v : v.to_s]
      end
    }
  when Array
    {set: operation.map { |v| v.is_a?(Proc) ? v : v.to_s }}
  when Proc
    {set: [operation]}
  else
    {set: Array(operation.to_s)}
  end
end