class Mingle::MingleSymbolMap

Constants

EMPTY

Public Class Methods

create( map = {} ) click to toggle source
# File lib/mingle.rb, line 2127
def self.create( map = {} )
    
    res = {}

    not_nil( map, "map" ).each_pair do |k, v| 
        
        mv = MingleModels.as_mingle_value( v )
        res[ MingleIdentifier::get( k ) ] = mv unless mv.is_a?( MingleNull )
    end

    new( res )
end
new( map ) click to toggle source
# File lib/mingle.rb, line 2142
def initialize( map )
    @map = map.freeze
end

Public Instance Methods

==( other ) click to toggle source
# File lib/mingle.rb, line 2196
def ==( other )
 
    other.is_a?( MingleSymbolMap ) &&
        other.instance_variable_get( :@map ) == @map
end
[]( key ) click to toggle source
# File lib/mingle.rb, line 2156
def []( key )

    case not_nil( key, :key )

        when MingleIdentifier then @map[ key ]

        when String then self[ key.to_sym ]

        when Symbol
            if res = ( @vals_by_sym ||= {} )[ key ]
                res
            else
                res = self[ MingleIdentifier.get( key ) ]
                @vals_by_sym[ key ] = res if res

                res
            end
        
        else raise TypeError, "Unexpected key type: #{key.class}"
    end
end
Also aliased as: get
expect( key ) click to toggle source
# File lib/mingle.rb, line 2181
def expect( key )

    if ( res = self[ key ] ) == nil
        raise NoSuchKeyError, "Map has no value for key: #{key}"
    else
        res
    end
end
fields() click to toggle source
# File lib/mingle.rb, line 2151
def fields
    self
end
get( key )
Alias for: []
get_map() click to toggle source
# File lib/mingle.rb, line 2146
def get_map
    {}.merge( @map )
end
values_at( *arg ) click to toggle source
# File lib/mingle.rb, line 2191
def values_at( *arg )
    not_nil( arg, :arg ).map { |k| get( k ) }
end

Private Instance Methods

expect_one_arg( args ) click to toggle source

Util function for method_missing

# File lib/mingle.rb, line 2204
def expect_one_arg( args )
        
    case sz = args.size
        when 0 then nil
        when 1 then args[ 0 ]
        else raise ArgumentError, "Wrong number of arguments (#{sz} for 1)"
    end
end
method_missing( meth, *args ) click to toggle source
Calls superclass method
# File lib/mingle.rb, line 2214
def method_missing( meth, *args )
    
    case meth.to_s

        when /^(expect|get)_(mingle_[a-z][a-z\d]*(?:_[a-z][a-z\d]*)*)$/
            
            case val = send( $1.to_sym, expect_one_arg( args ) )
                when nil then nil
                else MingleModels.as_mingle_instance( val, $2.to_sym )
            end

        when /^(expect|get)_string$/
            s = send( :"#{$1}_mingle_string", *args ) and s.to_s

        when /^(expect|get)_int$/
            s = send( :"#{$1}_mingle_int64", *args ) and s.to_i

        when /^(expect|get)_timestamp$/
            s = send( :"#{$1}_mingle_timestamp", *args )

        when /^(expect|get)_boolean$/
            s = send( :"#{$1}_mingle_boolean", *args ) and s.to_bool

        else super
    end
end