protected function buildRules()
    {
        if ($this->rules) {
            return $this->rules;
        }

        if ($resource = $this->resource()) {
            $this->rules = $this->filterDetectedRules($this->detectRules($resource), $resource);
        }

        return $this->rules;
    }