Sha256: 8eaff712c0611240f7b1a16b5dd95b36abf792e46d09a9aa98fe00d0295f0e55

Contents?: true

Size: 564 Bytes

Versions: 25

Compression:

Stored size: 564 Bytes

Contents

module Arrest

  class NestedCollection < Attribute
    def initialize name, read_only, clazz
      super name, read_only, clazz
    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

25 entries across 25 versions & 1 rubygems

Version Path
arrest-0.0.83.1 lib/arrest/attributes/nested_collection.rb
arrest-0.0.83 lib/arrest/attributes/nested_collection.rb
arrest-0.0.82 lib/arrest/attributes/nested_collection.rb
arrest-0.0.80 lib/arrest/attributes/nested_collection.rb
arrest-0.0.79 lib/arrest/attributes/nested_collection.rb
arrest-0.0.78 lib/arrest/attributes/nested_collection.rb
arrest-0.0.77 lib/arrest/attributes/nested_collection.rb
arrest-0.0.76 lib/arrest/attributes/nested_collection.rb
arrest-0.0.75 lib/arrest/attributes/nested_collection.rb
arrest-0.0.74 lib/arrest/attributes/nested_collection.rb
arrest-0.0.73 lib/arrest/attributes/nested_collection.rb
arrest-0.0.72 lib/arrest/attributes/nested_collection.rb
arrest-0.0.71 lib/arrest/attributes/nested_collection.rb
arrest-0.0.70 lib/arrest/attributes/nested_collection.rb
arrest-0.0.69 lib/arrest/attributes/nested_collection.rb
arrest-0.0.68 lib/arrest/attributes/nested_collection.rb
arrest-0.0.67 lib/arrest/attributes/nested_collection.rb
arrest-0.0.66 lib/arrest/attributes/nested_collection.rb
arrest-0.0.65 lib/arrest/attributes/nested_collection.rb
arrest-0.0.64 lib/arrest/attributes/nested_collection.rb