Skip to content

Commit

Permalink
Revive the project [v1.0] (#74)
Browse files Browse the repository at this point in the history
* Fix cannot helper

* Improve code

* Upgrade to ember 3.0

* Migrate tests to new Qunit API

* Migrate to new api modules

* Remove packaging

* Simplify resolver

* Refactor code
  • Loading branch information
Exelord authored and Ben Limmer committed Mar 31, 2018
1 parent 2a26bea commit c8827fd
Show file tree
Hide file tree
Showing 56 changed files with 13,846 additions and 812 deletions.
4 changes: 0 additions & 4 deletions .bowerrc

This file was deleted.

48 changes: 48 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
},
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
env: {
browser: true
},
rules: {
},
overrides: [
// node files
{
files: [
'index.js',
'testem.js',
'ember-cli-build.js',
'config/**/*.js',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'app/**',
'addon/**',
'tests/dummy/app/**'
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
},
env: {
browser: false,
node: true
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
}
]
};
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
/coverage/*
/libpeerconnection.log
npm-debug.log*
yarn-error.log
testem.log

# ember-try
.node_modules.ember-try/
bower.json.ember-try
package.json.ember-try
32 changes: 0 additions & 32 deletions .jshintrc

This file was deleted.

7 changes: 6 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
.bowerrc
.editorconfig
.ember-cli
.eslintrc.js
.gitignore
.jshintrc
.watchmanconfig
.travis.yml
bower.json
ember-cli-build.js
testem.js

# ember-try
.node_modules.ember-try/
bower.json.ember-try
package.json.ember-try
41 changes: 30 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
---
language: node_js
node_js:
- "0.12"
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- "4"

sudo: false
dist: trusty

addons:
chrome: stable

cache:
directories:
- node_modules
- $HOME/.npm

env:
global:
# See https://git.io/vdao3 for details.
- JOBS=1
matrix:
# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- EMBER_TRY_SCENARIO=ember-lts-2.12
- EMBER_TRY_SCENARIO=ember-lts-2.16
- EMBER_TRY_SCENARIO=ember-lts-2.18
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=ember-default

matrix:
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary

before_install:
- export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH
- "npm config set spin false"
- "npm install -g npm@^2"

install:
- npm install -g bower
- npm install
- bower install
- npm config set spin false
- npm install -g npm@4
- npm --version

script:
- ember try:each
- npm run lint:js
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO --skip-cleanup
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2017
Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,39 +278,41 @@ test resolver how to resolve abilities from the file structure.

An ability unit test will be created each time you generate a new ability via
`ember g ability <name>`. The package currently supports generating QUnit and
Mocha style tests.
Mocha style tests.

### Unit testing in your app

To unit test modules that use the `can` helper, you'll need to explicitly add `needs` for the
ability and helper file like this:
ability and helper file like this:
``` needs: ['helper:can', 'ability:foo'] ```

### Integration testing in your app

For integration testing components, you should not need to specify anything explicitly. The
helper and your abilities should be available to your components automatically.

## Development
## Contributing

### Installation

* `git clone` this repository
* `git clone <repository-url>`
* `cd my-addon`
* `npm install`
* `bower install`

### Running
### Linting

* `ember server`
* Visit your app at http://localhost:4200.
* `npm run lint:js`
* `npm run lint:js -- --fix`

### Running Tests
### Running tests

* `ember test`
* `ember test --server`
* `ember test` – Runs the test suite on the current Ember version
* `ember test --server` – Runs the test suite in "watch mode"
* `npm test` – Runs `ember try:each` to test your addon against multiple Ember versions

### Building
### Running the dummy application

* `ember build`
* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).

For more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/).
For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
4 changes: 2 additions & 2 deletions addon/ability.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ember from 'ember';
import EmberObject from '@ember/object';

export default Ember.Object.extend({
export default EmberObject.extend({
model: null
});
13 changes: 0 additions & 13 deletions addon/can-mixin.js

This file was deleted.

15 changes: 8 additions & 7 deletions addon/computed.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import Ember from 'ember';

const { get, set, getOwner } = Ember;
import { assert } from '@ember/debug';
import { set, get, computed } from '@ember/object';
import { getOwner } from '@ember/application';

export default {
ability: function(type, resourceName) {
if (arguments.length === 1) {
resourceName = type;
}

return Ember.computed(resourceName, function() {
const ability = getOwner(this).lookup(`ability:${type}`);
return computed(resourceName, function() {
let ability = getOwner(this).lookup(`ability:${type}`);

Ember.assert(`No ability class found for ${type}`, ability);
assert(`No ability class found for ${type}`, ability);

const resource = get(this, resourceName);
let resource = get(this, resourceName);
set(ability, 'model', resource);

return ability;
});
}
Expand Down
40 changes: 23 additions & 17 deletions addon/helpers/can.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import Ember from 'ember';
import Helper from '@ember/component/helper';

export default Ember.Helper.extend({
can: Ember.inject.service(),
import { inject as service } from '@ember/service';

compute([name, resource], hash) {
const service = this.get('can');
const ability = service.build(name, resource, hash);
const { propertyName } = service.parse(name);
export default Helper.extend({
can: service(),

if (this._ability) {
this._ability.removeObserver(this._abilityProp, this, 'recompute');
}
ability: null,
propertyName: null,

this._ability = ability;
this._abilityProp = propertyName;
compute([name, resource], properties) {
let service = this.get('can');
let { abilityName, propertyName } = service.parse(name);
let ability = service.build(abilityName, resource, properties);

ability.addObserver(propertyName, this, 'recompute');
this._removeAbilityObserver();
this._addAbilityObserver(ability, propertyName);

return ability.get(propertyName);
},

destroy() {
if (this._ability) {
this._ability.removeObserver(this._abilityProp, this, 'recompute');
}
return this._super();
this._removeAbilityObserver();
return this._super(...arguments);
},

_addAbilityObserver(ability, propertyName) {
this.setProperties({ ability, propertyName });
this.addObserver(`ability.${propertyName}`, this, 'recompute');
},

_removeAbilityObserver() {
this.removeObserver(`ability.${this.get('propertyName')}`, this, 'recompute');
}
});
16 changes: 4 additions & 12 deletions addon/helpers/cannot.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import Ember from 'ember';
import CanHelper from 'ember-can/helpers/can';

const { getOwner, typeOf } = Ember;

export default Ember.Helper.extend({
helper: Ember.computed(function() {
var helper = getOwner(this).lookup('helper:can');

return typeOf(helper) === 'instance' ? helper : helper.create();
}),

compute(params, hash) {
return !this.get('helper').compute(params, hash);
export default CanHelper.extend({
compute() {
return !this._super(...arguments);
}
});
15 changes: 5 additions & 10 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import Ability from './ability';
import CanMixin from './can-mixin';
import computed from './computed';
import CanService from './services/can';
import Ability from 'ember-can/ability';
import CanMixin from 'ember-can/mixins/can';
import computed from 'ember-can/computed';
import CanService from 'ember-can/services/can';

export {
Ability,
CanMixin,
CanService,
computed
};
export { Ability, CanMixin, CanService, computed };
11 changes: 11 additions & 0 deletions addon/initializers/setup-ember-can.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Resolver from 'ember-resolver';

Resolver.reopen({
// eslint-disable-next-line ember/avoid-leaking-state-in-ember-objects
pluralizedTypes: {
ability: 'abilities'
}
});

export function initialize(/* application */) {}
export default { initialize };
Loading

0 comments on commit c8827fd

Please sign in to comment.