Sha256: e38eec8d73e4bc4f9212c9388dcd177a403e7c66f2049724bb4b3cb7a70329d0

Contents?: true

Size: 574 Bytes

Versions: 2

Compression:

Stored size: 574 Bytes

Contents

module Arrest

  class NestedCollection < Attribute
    def initialize name, class_name, options
      super name, class_name, 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|
        self.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

2 entries across 2 versions & 1 rubygems

Version Path
arrest-0.0.91 lib/arrest/attributes/nested_collection.rb
arrest-0.0.90 lib/arrest/attributes/nested_collection.rb