Sha256: 68b14e0106554e0456b5c3a760dc028091c5ca8fa1dfa1214b30c0215c153556

Contents?: true

Size: 772 Bytes

Versions: 2

Compression:

Stored size: 772 Bytes

Contents

module PrettyApi
  module Helpers
    extend ActiveSupport::Concern

    included do
      def pretty_nested_attributes(record, params, attrs = nil)
        params = params.to_h.with_indifferent_access

        attrs ||= PrettyApi::ActiveRecord::Associations.nested_attributes_tree(record.class)

        PrettyApi::Parameters::NestedAttributes.new(nested_tree: attrs).parse(record, params)
      end

      def pretty_nested_errors(record, attrs = nil)
        attrs ||= PrettyApi::ActiveRecord::Associations.nested_attributes_tree(record.class)

        PrettyApi::Errors::NestedErrors.new(nested_tree: attrs).parse(record)
      end

      alias_method :pretty_attrs, :pretty_nested_attributes
      alias_method :pretty_errors, :pretty_nested_errors
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pretty-api-0.5.1 lib/pretty_api/helpers.rb
pretty-api-0.5.0 lib/pretty_api/helpers.rb