Class: Algebrick::DSL::TypeDefinitionScope

Inherits:
Object
  • Object
show all
Includes:
Shortcuts, TypeCheck
Defined in:
lib/algebrick/dsl.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from TypeCheck

#Child!, #Child?, #Match!, #Match?, #Type!, #Type?, error

Methods included from Shortcuts

#atom, #type

Constructor Details

- (TypeDefinitionScope) initialize(new_type, &block)

Returns a new instance of TypeDefinitionScope



33
34
35
36
37
# File 'lib/algebrick/dsl.rb', line 33

def initialize(new_type, &block)
  @new_type = Type! new_type, ProductVariant, ParametrizedType
  instance_exec @new_type, &block
  @new_type.kind if @new_type.is_a? ProductVariant
end

Instance Attribute Details

- (Object) new_type (readonly)

Returns the value of attribute new_type



31
32
33
# File 'lib/algebrick/dsl.rb', line 31

def new_type
  @new_type
end

Instance Method Details

- (Object) all_field_readers Also known as: all_readers



66
67
68
69
# File 'lib/algebrick/dsl.rb', line 66

def all_field_readers
  @new_type.add_all_field_method_readers
  self
end

- (Object) field_readers(*names) Also known as: readers



59
60
61
62
# File 'lib/algebrick/dsl.rb', line 59

def field_readers(*names)
  @new_type.add_field_method_readers *names
  self
end

- (Object) fields(*fields)



39
40
41
42
# File 'lib/algebrick/dsl.rb', line 39

def fields(*fields)
  @new_type.set_fields fields.first.is_a?(Hash) ? fields.first : fields
  self
end

- (Object) fields!(*fields)



44
45
46
47
# File 'lib/algebrick/dsl.rb', line 44

def fields!(*fields)
  fields(*fields)
  all_readers
end

- (Object) final!



49
50
51
52
# File 'lib/algebrick/dsl.rb', line 49

def final!
  @new_type.final!
  self
end

- (Object) variants(*variants)



54
55
56
57
# File 'lib/algebrick/dsl.rb', line 54

def variants(*variants)
  @new_type.set_variants *variants
  self
end