<commit_before>package definition

import (
	"errors"
	"log"
	"os"
	"path"
	"path/filepath"
	"sort"
	"strings"
	"sync"
)

var ErrFilePathIsNotUnderConfigPath = errors.New("File path is not under config path")
var ErrMockDoesntExist = errors.New("Mock doesn't exist")

type Mapping interface {
	Set(URI string, mock Mock) error
	Delete(URI string) error
	Get(URI string) (Mock, bool)
	List() []Mock
}

//PrioritySort mock array sorted by priority
type PrioritySort []Mock

func (s PrioritySort) Len() int {
	return len(s)
}
func (s PrioritySort) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s PrioritySort) Less(i, j int) bool {
	return s[i].Control.Priority > s[j].Control.Priority
}

type ConfigMapping struct {
	mapper   *ConfigMapper
	mapping  map[string]Mock
	path     string
	fsListen bool
	fsUpdate chan struct{}
	sync.Mutex
}

func NewConfigMapping(path string, mapper *ConfigMapper, fsUpdate chan struct{}) *ConfigMapping {
	cm := &ConfigMapping{path: path, mapper: mapper, mapping: make(map[string]Mock), fsUpdate: fsUpdate}
	cm.populate()
	go cm.listenFsChanges()
	return cm
}

func (fm *ConfigMapping) listenFsChanges() {
	for {
		<-fm.fsUpdate
		if fm.fsIsBind() {
			fm.populate()
		}
<commit_msg>Bind the config to react to config changes on start (#34)<commit_after>package definition

import (
	"errors"
	"log"
	"os"
	"path"
	"path/filepath"
	"sort"
	"strings"
	"sync"
)

var ErrFilePathIsNotUnderConfigPath = errors.New("File path is not under config path")
var ErrMockDoesntExist = errors.New("Mock doesn't exist")

type Mapping interface {
	Set(URI string, mock Mock) error
	Delete(URI string) error
	Get(URI string) (Mock, bool)
	List() []Mock
}

//PrioritySort mock array sorted by priority
type PrioritySort []Mock

func (s PrioritySort) Len() int {
	return len(s)
}
func (s PrioritySort) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s PrioritySort) Less(i, j int) bool {
	return s[i].Control.Priority > s[j].Control.Priority
}

type ConfigMapping struct {
	mapper   *ConfigMapper
	mapping  map[string]Mock
	path     string
	fsListen bool
	fsUpdate chan struct{}
	sync.Mutex
}

func NewConfigMapping(path string, mapper *ConfigMapper, fsUpdate chan struct{}) *ConfigMapping {
	cm := &ConfigMapping{path: path, mapper: mapper, mapping: make(map[string]Mock), fsUpdate: fsUpdate}
	cm.populate()
	cm.fsBind()
	go cm.listenFsChanges()
	return cm
}

func (fm *ConfigMapping) listenFsChanges() {
	for {
		<-fm.fsUpdate
		if fm.fsIsBind() {
			fm.populate()
		}

{'fraction_non_alphanumeric': 0.12706071572175312, 'fraction_numerical': 0.0008041817450743868, 'mean_word_length': 4.6289592760181, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5134109', 'n_tokens_mistral': 916, 'n_tokens_neox': 882, 'n_words': 261}