Sha256: 7cbd126f8fd91e096dc6dd1fcc1a78226ccea06d32e392e2275e05c3e0efd2b2

Contents?: true

Size: 656 Bytes

Versions: 73

Compression:

Stored size: 656 Bytes

Contents

module SparkApi
  class PrimaryArray < Array
    
    def primary
      find_primary
    end

    private 
    
    # This is a very simplistic but reliable implementation.
    def find_primary
      self.each do |arg|
        if arg.primary?
          return arg
        end
      end
      nil
    end
  end
  
  #=== Primary: interface to implement for elements that are added to a "PrimaryArray" collection
  module Primary
    # Return true if the element is the primary resource in a collection.
    # Default implementation looks for a "Primary" attribute
    def primary?
      @attributes.key?("Primary") && self.Primary == true
    end
  end
end

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
spark_api-1.4.24 lib/spark_api/primary_array.rb
spark_api-1.4.23 lib/spark_api/primary_array.rb
spark_api-1.4.22 lib/spark_api/primary_array.rb
spark_api-1.4.21 lib/spark_api/primary_array.rb
spark_api-1.4.20 lib/spark_api/primary_array.rb
spark_api-1.4.19 lib/spark_api/primary_array.rb
spark_api-1.4.18 lib/spark_api/primary_array.rb
spark_api-1.4.17 lib/spark_api/primary_array.rb
spark_api-1.4.16 lib/spark_api/primary_array.rb
spark_api-1.4.15 lib/spark_api/primary_array.rb
spark_api-1.4.14 lib/spark_api/primary_array.rb
spark_api-1.4.13 lib/spark_api/primary_array.rb
spark_api-1.4.12 lib/spark_api/primary_array.rb
spark_api-1.4.11 lib/spark_api/primary_array.rb
spark_api-1.4.10 lib/spark_api/primary_array.rb
spark_api-1.4.9 lib/spark_api/primary_array.rb
spark_api-1.4.8 lib/spark_api/primary_array.rb
spark_api-1.4.6 lib/spark_api/primary_array.rb
spark_api-1.4.5 lib/spark_api/primary_array.rb
spark_api-1.4.4 lib/spark_api/primary_array.rb