Sha256: d58b3446fea904c316b6dd25f55cc150a9760f6760c6712457b716000ef1a16a

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

module Moblues
  module Generator
    module Base
      class Type
        SWIFT = {
          attribute_types:
            {
              string:  'String',
              number:  'NSNumber',
              decimal: 'NSDecimalNumber',
              date:    'NSDate',
              data:    'NSData',
              id:      'AnyObject'
            },
          relationship_types:
            {
              to_many:         'NSSet',
              to_many_ordered: 'NSOrderedSet',
              suffix:          ''
            }
        }

        OBJC = {
          attribute_types:
            {
              string:  'NSString *',
              number:  'NSNumber *',
              decimal: 'NSDecimalNumber *',
              date:    'NSDate *',
              data:    'NSData *',
              id:      'id '
            },
          relationship_types:
            {
              to_many:         'NSSet *',
              to_many_ordered: 'NSOrderedSet *',
              suffix:          ' *'
            }
        }

        def initialize(params = SWIFT)
          @attribute_types = params.fetch(:attribute_types)
          @relationship_types = params.fetch(:relationship_types)
        end

        def attribute_type(attribute)
          attribute_types.fetch(attribute.type)
        end

        def relationship_type(relationship)
          if relationship.to_many
            relationship.ordered ? relationship_types[:to_many_ordered] : relationship_types[:to_many]
          else
            relationship.destination_entity + relationship_types[:suffix]
          end
        end

        protected
        attr_reader :attribute_types, :relationship_types
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
moblues-0.4.0 lib/moblues/generator/base/type.rb
moblues-0.3.0 lib/moblues/generator/base/type.rb
moblues-0.2.0 lib/moblues/generator/base/type.rb