Sha256: aed2e26fa9b7ca1fa07f088e79558bb62787fcc8c82de8653091173a3ff81bf4

Contents?: true

Size: 679 Bytes

Versions: 13

Compression:

Stored size: 679 Bytes

Contents

require 'sequel'

class Cranium::Sequel::Hash < Hash

  def qualify(options)
    invalid_options = options.keys - [:keys_with, :values_with]
    raise ArgumentError, "Unsupported option for qualify: #{invalid_options.first}" unless invalid_options.empty?
    Hash[qualify_fields(options[:keys_with], keys).zip qualify_fields(options[:values_with], values)]
  end



  def qualified_keys(qualifier)
    qualify_fields qualifier, keys
  end



  def qualified_values(qualifier)
    qualify_fields qualifier, values
  end



  private

  def qualify_fields(qualifier, fields)
    return fields if qualifier.nil?
    fields.map { |field| Sequel.qualify qualifier, field }
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cranium-0.8.1 lib/cranium/sequel/hash.rb
cranium-0.8 lib/cranium/sequel/hash.rb
cranium-0.7 lib/cranium/sequel/hash.rb
cranium-0.6.1 lib/cranium/sequel/hash.rb
cranium-0.5 lib/cranium/sequel/hash.rb
cranium-0.4.3 lib/cranium/sequel/hash.rb
cranium-0.4.2 lib/cranium/sequel/hash.rb
cranium-0.4.1 lib/cranium/sequel/hash.rb
cranium-0.4 lib/cranium/sequel/hash.rb
cranium-0.3.1 lib/cranium/sequel/hash.rb
cranium-0.3.0 lib/cranium/sequel/hash.rb
cranium-0.2.1 lib/cranium/sequel/hash.rb
cranium-0.2.0 lib/cranium/sequel/hash.rb