You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/ui/packages/consul-ui/app/helpers/is.js

27 lines
814 B

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Helper from 'ember-can/helpers/can';
import { get } from '@ember/object';
import { camelize } from '@ember/string';
export const is = (helper, [abilityString, model], properties) => {
let { abilityName, propertyName } = helper.abilities.parse(abilityString);
let ability = helper.abilities.abilityFor(abilityName, model, properties);
if (typeof ability.getCharacteristicProperty === 'function') {
propertyName = ability.getCharacteristicProperty(propertyName);
} else {
propertyName = camelize(`is-${propertyName}`);
}
return get(ability, propertyName);
};
export default class extends Helper {
compute([abilityString, model], properties) {
return is(this, [abilityString, model], properties);
}
}