# http://emberjs.com/guides/models/defining-a-store/

DS.CloudsdaleSerializer = DS.RESTSerializer.extend
  normalize: (type, prop, hash) ->
    normalized = {}
    for key of hash
      normalized[Ember.String.camelize(key)] = hash[key] if key

    return @_super(type, prop, normalized)

  serialize: (record, options) ->
    json = @_super(record, options)
    for key of json
      if decamelized = name.decamelize() isnt key
          json[decamelized] = json[name]
          delete json[name]
    return json

  extractMeta: (store, type, payload) ->
    if (payload && payload.collection)
      store.metaForType(type, payload.collection)
      delete payload.collection

    @_super(store, type, payload)

DS.CloudsdaleAdapter = DS.RESTAdapter.extend

  namespace: "v2"
  host: "<%= $settings[:api][:v2][:host] %>"
  serializer: DS.CloudsdaleSerializer.create()

  buildURL: (type, id) ->
    return this._super(type, id) + ".json"

  ajax: (url, type, hash) ->
    hash ||= {}
    hash.xhrFields =
      withCredentials: true

    this._super(url, type, hash)

  extractMeta: (loader, type, json) ->
    meta = json[@configOption(type, 'collection')]
    return if not meta
    Ember.set('App.metaDataForLastRequest', meta)
    this._super(loader, type, json)

Cloudsdale.Store = DS.Store.extend
  adapter: DS.CloudsdaleAdapter



# http://emberjs.com/guides/models/defining-a-store/

DS.CloudsdaleSerializer = DS.RESTSerializer.extend
  normalize: (type, hash, prop) ->
    normalized = {}
    for key of hash
      normalized[Ember.String.camelize(key)] = hash[key]

    return @_super(type, normalized, prop)

  serialize: (record, options) ->
    json = @_super(record, options)
    for key of json
      if decamelized = name.decamelize() isnt key
          json[decamelized] = json[name]
          delete json[name]
    return json

  extractMeta: (store, type, payload) ->
    if (payload && payload.collection)
      store.metaForType(type, payload.collection)
      delete payload.collection

    @_super(store, type, payload)


DS.CloudsdaleAdapter = DS.RESTAdapter.extend

  namespace: "v2"
  host: "<%= $settings[:api][:v2][:host] %>"
  defaultSerializer: "DS/cloudsdale"

  buildURL: (type, id) ->
    return this._super(type, id) + ".json"

  ajax: (url, type, hash) ->
    hash ||= {}
    hash.xhrFields =
      withCredentials: true

    this._super(url, type, hash)

  extractMeta: (loader, type, json) ->
    meta = json[@configOption(type, 'collection')]
    return if not meta
    Ember.set('App.metaDataForLastRequest', meta)
    this._super(loader, type, json)

Cloudsdale.Store = DS.Store.extend
  adapter: DS.CloudsdaleAdapter



Change in ember-data made me change for compliance.
Change in ember-data made me change for compliance.
