Class: Dhall::TypeChecker::RecordSelection::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/dhall/typecheck.rb

Direct Known Subclasses

TypeSelector

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Selector

Returns a new instance of Selector.



600
601
602
# File 'lib/dhall/typecheck.rb', line 600

def initialize(type)
	@fetch_from = type.record
end

Class Method Details

.for(annotated_record) ⇒ Object



589
590
591
592
593
594
595
596
597
598
# File 'lib/dhall/typecheck.rb', line 589

def self.for(annotated_record)
	typ = annotated_record.type.normalize
	if KINDS.include?(typ)
		TypeSelector.new(annotated_record.value)
	elsif typ.class == Dhall::RecordType
		new(typ)
	else
		raise TypeError, "RecordSelection on #{typ}"
	end
end

Instance Method Details

#select(selector) ⇒ Object



604
605
606
607
608
# File 'lib/dhall/typecheck.rb', line 604

def select(selector)
	@fetch_from.fetch(selector) do
		raise TypeError, "#{@fetch_from} has no field #{@selector}"
	end
end