module Napa
  module GrapeHelpers
    def represent(data, with: nil, **args)
      raise ArgumentError.new(":with option is required") if with.nil?

      if data.respond_to?(:to_a)
        return { data: data.map{ |item| with.new(item).to_hash(args) } }
      else
        return { data: with.new(data).to_hash(args)}
      end
    end

    def present_error(code, message = '', reasons={})
      Napa::JsonError.new(code, message, reasons)
    end

    def permitted_params(options = {})
      options = { include_missing: false }.merge(options)
      declared(params, options)
    end

    # extend all endpoints to include this
    Grape::Endpoint.send :include, self if defined?(Grape)
    # rails 4 controller concern
    extend ActiveSupport::Concern if defined?(Rails)
  end
end

module Napa
  module GrapeHelpers
    def represent(data, with: nil, **args)
      raise ArgumentError.new(":with option is required") if with.nil?

      if data.respond_to?(:map)
        return { data: data.map{ |item| with.new(item).to_hash(args) } }
      else
        return { data: with.new(data).to_hash(args)}
      end
    end

    def present_error(code, message = '', reasons={})
      Napa::JsonError.new(code, message, reasons)
    end

    def permitted_params(options = {})
      options = { include_missing: false }.merge(options)
      declared(params, options)
    end

    # extend all endpoints to include this
    Grape::Endpoint.send :include, self if defined?(Grape)
    # rails 4 controller concern
    extend ActiveSupport::Concern if defined?(Rails)
  end
end

Update test of data to check for the method actually used rather than assume that an object that responds to :to_a can respond to :map.
Update test of data to check for the method actually used rather than assume that an object that responds to :to_a can respond to :map.

This resolves https://github.com/bellycard/napa/issues/216
