Class: Ibex::Configuration::Origin
- Inherits:
-
Object
- Object
- Ibex::Configuration::Origin
- Defined in:
- lib/ibex/configuration.rb,
sig/ibex/configuration.rbs
Overview
Where a selected configuration value came from.
Instance Attribute Summary collapse
- #kind ⇒ Symbol readonly
- #location ⇒ Location? readonly
Instance Method Summary collapse
-
#initialize(kind, location: nil) ⇒ Origin
constructor
A new instance of Origin.
- #label ⇒ String
- #stringify_location(location) ⇒ Hash[String, json_value]
- #to_h ⇒ Hash[String, json_value]
Constructor Details
#initialize(kind, location: nil) ⇒ Origin
Returns a new instance of Origin.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ibex/configuration.rb', line 119 def initialize(kind, location: nil) raise ArgumentError, "unknown configuration origin: #{kind.inspect}" unless ORIGIN_KINDS.include?(kind) unless location.nil? || location.is_a?(Location) raise ArgumentError, "configuration location must be an Ibex::Location" end if location && !%i[grammar project].include?(kind) raise ArgumentError, "#{kind} configuration cannot have a source location" end @kind = kind @location = location freeze end |
Instance Attribute Details
#kind ⇒ Symbol (readonly)
115 116 117 |
# File 'lib/ibex/configuration.rb', line 115 def kind @kind end |
#location ⇒ Location? (readonly)
116 117 118 |
# File 'lib/ibex/configuration.rb', line 116 def location @location end |
Instance Method Details
#label ⇒ String
142 143 144 145 146 147 148 |
# File 'lib/ibex/configuration.rb', line 142 def label location = @location return @kind.to_s unless location file = location.file || "(source)" "#{@kind} #{file}:#{location.line}:#{location.column}" end |
#stringify_location(location) ⇒ Hash[String, json_value]
153 154 155 |
# File 'lib/ibex/configuration.rb', line 153 def stringify_location(location) location.to_h.transform_keys(&:to_s) end |
#to_h ⇒ Hash[String, json_value]
134 135 136 137 138 139 |
# File 'lib/ibex/configuration.rb', line 134 def to_h result = { "kind" => @kind.to_s } #: Hash[String, json_value] location = @location result["location"] = stringify_location(location) if location result end |