Module: Textus::Role
- Defined in:
- lib/textus/role.rb
Constant Summary collapse
- PATTERN =
/\A[a-z][a-z0-9_-]*\z/- DEFAULT =
"human".freeze
Class Method Summary collapse
Class Method Details
.read_file(root) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/textus/role.rb', line 13 def self.read_file(root) path = File.join(root, "role") return nil unless File.exist?(path) File.read(path).strip.then { |s| s.empty? ? nil : s } end |
.resolve(root:, flag: nil, env: ENV) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/textus/role.rb', line 6 def self.resolve(root:, flag: nil, env: ENV) candidate = flag || env["TEXTUS_ROLE"] || read_file(root) || DEFAULT raise InvalidRole.new(candidate) unless candidate.match?(PATTERN) candidate end |