UNPKG

fliphub-monorepo

Version:
59 lines (49 loc) 1.23 kB
const ChainedMap = require('./ChainedMap') const Rule = require('./Rule') // const log = require('fliplog') module.exports = class extends ChainedMap { constructor(parent) { super(parent) this.rules = new ChainedMap(this) } rule(name) { if (!this.rules.has(name)) { this.rules.set(name, new Rule(this)) } return this.rules.get(name) } toConfig() { // const o = Object.assign(this.entries() || {}, { // rules: this.rules.values().map(r => r.toConfig()) // }) // const oc = this.clean(o) // log.quick(o, oc) return this.clean(Object.assign(this.entries() || {}, { rules: this.rules.values().map(r => r.toConfig()) })) } merge(obj) { // console.log('meeerrrrggggeee') // log.quick(obj) // console.log('hm') Object .keys(obj) .forEach(key => { const value = obj[key] switch (key) { case 'rules': case 'rule': { return Object .keys(value) .forEach(name => { this.rule(name).merge(value[name]) }) } default: { this.set(key, value) } } }) return this } }