lib/decanter/parser/core.rb in decanter-2.1.2 vs lib/decanter/parser/core.rb in decanter-3.0.0

- old
+ new

@@ -1,23 +1,21 @@ -# frozen_string_literal: true - module Decanter module Parser module Core + def self.included(base) base.extend(ClassMethods) end module ClassMethods + # Check if allowed, parse if not - def parse(values, options = {}) - if empty_values?(values) - nil - elsif allowed?(values) - values + def parse(name, value, options={}) + if allowed?(value) + { name => value } else - _parse(values, options) + _parse(name, value, options) end end # Define parser def parser(&block) @@ -38,17 +36,11 @@ def preparsers @pre || [] end # Check for allowed classes - def allowed?(values) - @allowed && Array.wrap(values).all? do |value| - @allowed.any? { |allowed| value.is_a? allowed } - end - end - - def empty_values?(values) - return true if Array.wrap(values).all? { |value| value.nil? || value == '' } + def allowed?(value) + @allowed && @allowed.any? { |allowed| value.is_a? allowed } end end end end end