Sha256: 7a4b4beb500d899d6e37e477bec7bdbf67f5528ebba8d3ad2555baff30e636e9

Contents?: true

Size: 1.13 KB

Versions: 18

Compression:

Stored size: 1.13 KB

Contents

module Frodo
  module Properties
    # Defines the Collection Frodo type.
    class Collection < Frodo::Property
      # Overriding default constructor to avoid converting
      # value to string.
      # TODO: Make this the default for all property types?
      def initialize(name, value, options = {})
        super(name, value, options)
        self.value = value
      end

      def value
        if @value.nil?
          nil
        else
          @value.map(&:value)
        end
      end

      def value=(value)
        if value.nil? && allows_nil?
          @value = nil
        elsif value.respond_to?(:map)
          @value = value.map.with_index do |element, index|
            type_class.new("#{name}[#{index}]", element)
          end
        else
          validation_error 'Value must be an array'
        end
      end

      def url_value
        '[' + @value.map(&:url_value).join(',') + ']'
      end

      def type
        "Collection(#{value_type})"
      end

      def value_type
        options[:value_type] || 'Edm.String'
      end

      def type_class
        Frodo::PropertyRegistry[value_type]
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
frodo-0.12.8 lib/frodo/properties/collection.rb
frodo-0.12.7 lib/frodo/properties/collection.rb
frodo-0.12.6 lib/frodo/properties/collection.rb
frodo-0.12.5 lib/frodo/properties/collection.rb
frodo-0.12.4 lib/frodo/properties/collection.rb
frodo-0.12.2 lib/frodo/properties/collection.rb
frodo-0.12.1 lib/frodo/properties/collection.rb
frodo-0.12.0 lib/frodo/properties/collection.rb
frodo-0.11.0 lib/frodo/properties/collection.rb
frodo-0.10.8 lib/frodo/properties/collection.rb
frodo-0.10.7 lib/frodo/properties/collection.rb
frodo-0.10.6 lib/frodo/properties/collection.rb
frodo-0.10.5 lib/frodo/properties/collection.rb
frodo-0.10.4 lib/frodo/properties/collection.rb
frodo-0.10.3 lib/frodo/properties/collection.rb
frodo-0.10.2 lib/frodo/properties/collection.rb
frodo-0.10.1 lib/frodo/properties/collection.rb
frodo-0.10.0 lib/frodo/properties/collection.rb