https://github.com/softlayer/sl-ember-modelize
An Ember CLI Addon that takes a nested Plain Old Javascript Object (POJO) and returns an Ember Object, resolving any keys to "models" by using the Ember resolver and creating new objects of that model type.
https://github.com/softlayer/sl-ember-modelize
Last synced: 6 months ago
JSON representation
An Ember CLI Addon that takes a nested Plain Old Javascript Object (POJO) and returns an Ember Object, resolving any keys to "models" by using the Ember resolver and creating new objects of that model type.
- Host: GitHub
- URL: https://github.com/softlayer/sl-ember-modelize
- Owner: softlayer
- License: mit
- Created: 2014-11-19T16:07:30.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-03-01T16:18:29.000Z (almost 10 years ago)
- Last Synced: 2024-11-17T11:20:16.442Z (about 1 year ago)
- Language: JavaScript
- Homepage: http://softlayer.github.io/sl-ember-modelize
- Size: 1.61 MB
- Stars: 9
- Watchers: 13
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://github.com/softlayer/sl-ember-modelize/releases)  [](LICENSE.md) [](https://www.npmjs.com/package/sl-ember-modelize)
[](https://david-dm.org/softlayer/sl-ember-modelize) [](https://david-dm.org/softlayer/sl-ember-modelize#info=devDependencies)
[](https://travis-ci.org/softlayer/sl-ember-modelize) [](https://codeclimate.com/github/softlayer/sl-ember-modelize)
To see which issues are currently being worked on or are scheduled to be worked on next, visit [https://huboard.com/softlayer/sl-ember-modelize/#/](https://huboard.com/softlayer/sl-ember-modelize/#/)
---
# What sl-ember-modelize is
A mixin that will take a Plain Old Javascript Object (POJO) and turn it into a series of nested model objects, based on the models registered in your application's container. This works for objects stored on keys and on arrays of objects stored on keys too. This mixin will:
* Recursively resolve keys (via the container) on an object and check to see if a model exists that matches that key
* Create models for keys and store the key's contents in those models
---
# Demo
## Live
[http://softlayer.github.io/sl-ember-modelize/#/demo](http://softlayer.github.io/sl-ember-modelize/#/demo)
## Development Environment
### Installation
* `git clone` this repository
* `npm install`
* `bower install`
### Running
* `ember server`
* View the demo at http://localhost:4200
For more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/).
---
# How to use this addon in your application
## Install this addon as a Node module
```
ember install:addon sl-ember-modelize
```
## Use the mixin
Include it in your objects like so:
```javascript
import ModelizeMixin from 'sl-ember-modelize/mixins/modelize';
Ember.Object.extend( ModelizeMixin, {} );
```
You can now call `modelize` from within that object like so:
```javascript
modelizedObj = this.modelize( POJO );
```
---
# How it works
Consider this fixture:
```
fixture: {
foo: {
bar: {
car: [
{
name: 'car1',
color: 'blue'
},
{
name: 'car2',
color: 'red'
},
{
name: 'car3',
color: 'black'
}
],
test: 'this is a bar model'
},
text: 'this is a foo model'
}
}
```
Passing this POJO through the *modelize* function will cause the object stored in the values for *foo*, *bar*, and
the array stored on *car* to be replaced with the models defined for those key names in the app. *Modelize* looks up
models via Ember's container and if a model is found then it is instantiated with the values from the fixture.
---
# Versioning
Employs [Semantic Versioning 2.0.0](http://semver.org/)
---
# Contribution
[See CONTRIBUTING.md](CONTRIBUTING.md)
---
# Copyright and License
sl-ember-modelize and its source files are Copyright © 2014 [SoftLayer Technologies, Inc.](http://www.softlayer.com/) The
software is [MIT Licensed](LICENSE.md)
---
# Warranty
This software is provided “as is” and without any express or implied warranties, including, without limitation, the
implied warranties of merchantability and fitness for a particular purpose.