Sha256: 2b6194ec9b26d82824c5686170511a858a765d0b4bfb755630f5d2ee2d1b03cf

Contents?: true

Size: 1021 Bytes

Versions: 2

Compression:

Stored size: 1021 Bytes

Contents

module Immutabler
  class TypeMapper
    TYPE_MAPPING = {
      'int' => {
        type: 'NSInteger',
        is_ref: false
      },
      'float' => {
        type: 'CGFloat',
        is_ref: false
      },
      'double' => {
        type: 'double',
        is_ref: false
      },      
      'bool' => {
        type: 'BOOL',
        is_ref: false
      },
      'array' => {
        type: 'NSArray',
        is_ref: true
      },
      'string' => {
        type: 'NSString',
        is_ref: true
      },
      'dict' => {
        type: 'NSDictionary',
        is_ref: true
      },
      'id' => {
        type: 'id',
        is_ref: true,
        ref_type: 'strong',
        is_id: true
      }
    }

    def self.map(type, options)
      default_mapping(type).merge(TYPE_MAPPING.fetch(type, default_mapping(type))).merge(options)
    end

    private

    def self.default_mapping(type)
      {
        type: type,
        is_ref: true,
        ref_type: 'strong',
        is_id: false
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
immutabler-0.2.1 lib/immutabler/type_mapper.rb
immutabler-0.2.0 lib/immutabler/type_mapper.rb