Sha256: 5800e33961947b9697b7d68aa3bf53eeb8f87af94b607ff52a2131a62d98059a

Contents?: true

Size: 833 Bytes

Versions: 17

Compression:

Stored size: 833 Bytes

Contents

module Attributor
  class FieldSelector
    class Transformer < Parslet::Transform
      rule(field: simple(:field_token), children: subtree(:children_tree)) do
        cs = if children_tree.empty?
               true
             else
               children_tree.each_with_object({}) do |item, hash|
                 hash.merge! item
               end
             end
        { field_token.to_sym => cs }
      end

      rule(csv: subtree(:csv_tree)) do
        case csv_tree
        when ::Hash
          csv_tree
        when Array
          csv_tree.each_with_object({}) do |item, hash|
            hash.merge! item
          end
        else
          raise "Oops...didn't know this could happen! (this is not a Hash or an Array?). Got a #{csv_tree.class.name} : #{csv_tree.inspect}"
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
attributor-8.0 lib/attributor/extras/field_selector/transformer.rb
attributor-7.1 lib/attributor/extras/field_selector/transformer.rb
attributor-7.0 lib/attributor/extras/field_selector/transformer.rb
attributor-6.5 lib/attributor/extras/field_selector/transformer.rb
attributor-6.4 lib/attributor/extras/field_selector/transformer.rb
attributor-6.3 lib/attributor/extras/field_selector/transformer.rb
attributor-6.2 lib/attributor/extras/field_selector/transformer.rb
attributor-6.1 lib/attributor/extras/field_selector/transformer.rb
attributor-6.0 lib/attributor/extras/field_selector/transformer.rb
attributor-5.7 lib/attributor/extras/field_selector/transformer.rb
attributor-5.6 lib/attributor/extras/field_selector/transformer.rb
attributor-5.5 lib/attributor/extras/field_selector/transformer.rb
attributor-5.4 lib/attributor/extras/field_selector/transformer.rb
attributor-5.3 lib/attributor/extras/field_selector/transformer.rb
attributor-5.2.1 lib/attributor/extras/field_selector/transformer.rb
attributor-5.2.0 lib/attributor/extras/field_selector/transformer.rb
attributor-5.1.0 lib/attributor/extras/field_selector/transformer.rb