Permalink
Browse files

rails model and ember-data attributes are not

always the same.  This commit adds conversion of
typical rails attribute types to ember-data types.
  • Loading branch information...
1 parent d76bd79 commit 144fd2a38102f1edb254efdad3faf49adc2a1437 @stefanpenner stefanpenner committed Aug 12, 2012
Showing with 20 additions and 2 deletions.
  1. +20 −2 lib/generators/ember/model_generator.rb
@@ -13,12 +13,30 @@ def create_model_files
end
private
+ EMBER_TYPE_LOOKUP = {
+ nil => 'string',
+
+ binary: 'string',
+ string: 'string',
+ text: 'string',
+ boolean: 'boolean',
+ date: 'date',
+ datetime: 'date',
+ time: 'date',
+ timestamp: 'date',
+ decimal: 'number',
+ float: 'number',
+ integer: 'number',
+ primary_key: 'number'
+ }
def parse_attributes!
self.attributes = (attributes || []).map do |attr|
name, type = attr.split(':')
- type = 'string' if type == 'text'
- { name: name, type: type }
+ key = type.try(:to_sym)
+ ember_type = EMBER_TYPE_LOOKUP[key] || type
+
+ { name: name, type: ember_type }
end
end
end

0 comments on commit 144fd2a

Please sign in to comment.