Class: Ember::Schema::RestPack

Inherits:
Object
  • Object
show all
Defined in:
lib/ember/schema/rest_pack.rb

Instance Method Summary collapse

Instance Method Details

#camelize(serializer, klass) ⇒ Object



20
21
22
# File 'lib/ember/schema/rest_pack.rb', line 20

def camelize(serializer, klass)
  klass.name.camelize
end

#descendants(serializer) ⇒ Object



12
13
14
# File 'lib/ember/schema/rest_pack.rb', line 12

def descendants(serializer)
  serializer.descendants.sort_by { |s| s.name }
end

#get_klass(serializer) ⇒ Object



16
17
18
# File 'lib/ember/schema/rest_pack.rb', line 16

def get_klass(serializer)
  serializer.model_class
end

#schema(serializer, klass) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ember/schema/rest_pack.rb', line 24

def schema(serializer, klass)
  columns = if klass.respond_to? :columns_hash then klass.columns_hash else {} end

  attrs = {}
  (serializer.serializable_attributes || {}).each do |id, name|
    options = serializer.serializable_attributes_options[id] || {}
    if options[:type].present?
      attrs[name] = options[:type].to_s
    else
      # If no type is given, attempt to get it from the Active Model class
      if column = columns[name.to_s]
        attrs[name] = column.type
      else
        # Other wise default to string
        attrs[name] = "string"
      end
    end
  end

  associations = {}

  serializer.can_include.each do |association_name|
    if model_association = klass.reflect_on_association(association_name)
      # Real association
      associations[association_name] = { model_association.macro => model_association.class_name.pluralize.underscore.downcase }
    end
  end

  return { :attributes => attrs, :associations => associations }
end

#serializersObject



8
9
10
# File 'lib/ember/schema/rest_pack.rb', line 8

def serializers
  ::RestPack::Serializer.class_map.sort_by { |s| s[0] }.map { |s| s[1] }
end

#superclassObject



4
5
6
# File 'lib/ember/schema/rest_pack.rb', line 4

def superclass
  ::RestPack::Serializer
end