Class: Ibex::Configuration::Origin
- Inherits:
-
Object
- Object
- Ibex::Configuration::Origin
- Defined in:
- lib/ibex/configuration.rb
Overview
Where a selected configuration value came from.
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
: Symbol.
-
#location ⇒ Object
readonly
: Location?.
Instance Method Summary collapse
-
#initialize(kind, location: nil) ⇒ Origin
constructor
A new instance of Origin.
- #label ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(kind, location: nil) ⇒ Origin
Returns a new instance of Origin.
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ibex/configuration.rb', line 128 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 ⇒ Object (readonly)
: Symbol
124 125 126 |
# File 'lib/ibex/configuration.rb', line 124 def kind @kind end |
#location ⇒ Object (readonly)
: Location?
125 126 127 |
# File 'lib/ibex/configuration.rb', line 125 def location @location end |
Instance Method Details
#label ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/ibex/configuration.rb', line 151 def label location = @location return @kind.to_s unless location file = location.file || "(source)" "#{@kind} #{file}:#{location.line}:#{location.column}" end |
#to_h ⇒ Object
143 144 145 146 147 148 |
# File 'lib/ibex/configuration.rb', line 143 def to_h result = { "kind" => @kind.to_s } #: Hash[String, json_value] location = @location result["location"] = stringify_location(location) if location result end |