Sha256: 752033e6622ca6ebf09c72a289edad0036ce9a6680f68170b370b734576d4a44

Contents?: true

Size: 560 Bytes

Versions: 7

Compression:

Stored size: 560 Bytes

Contents

module Arrest

  class NestedCollection < Attribute
    def initialize name, clazz, options
      super name, clazz, options
    end

    def from_hash(parent, value)
      return nil unless value != nil
      raise "Expected an array but got #{value.class.name}" unless value.is_a?(Array)
      value.map do |v|
        @clazz.new(parent.context, v)
      end
    end

    def to_hash value
      return nil unless value != nil
      raise "Expected an array but got #{value.class.name}" unless value.is_a?(Array)
      value.map(&:to_hash)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
arrest-0.0.89 lib/arrest/attributes/nested_collection.rb
arrest-0.0.88 lib/arrest/attributes/nested_collection.rb
arrest-0.0.87 lib/arrest/attributes/nested_collection.rb
arrest-0.0.86 lib/arrest/attributes/nested_collection.rb
arrest-0.0.85 lib/arrest/attributes/nested_collection.rb
arrest-0.0.84 lib/arrest/attributes/nested_collection.rb
arrest-0.0.83.crud lib/arrest/attributes/nested_collection.rb