Class: Moblues::Generator::Base::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/moblues/generator/base/type.rb

Direct Known Subclasses

Objc::Type

Constant Summary collapse

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:          ' *'
    }
}

Instance Method Summary collapse

Constructor Details

#initialize(params = SWIFT) ⇒ Type

Returns a new instance of Type.



41
42
43
44
# File 'lib/moblues/generator/base/type.rb', line 41

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

Instance Method Details

#attribute_type(attribute) ⇒ Object



46
47
48
# File 'lib/moblues/generator/base/type.rb', line 46

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

#relationship_type(relationship) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/moblues/generator/base/type.rb', line 50

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