class Rstruct::StructBuilder

Attributes

__fields[R]
__registry[R]

Public Class Methods

new(registry=nil, &block) click to toggle source
# File lib/rstruct/struct_builder.rb, line 10
def initialize(registry=nil, &block)
  @__fields = []
  @__registry = registry || Registry::DEFAULT_REGISTRY
  instance_eval &block
end

Public Instance Methods

array(name, typ, count, opts={}, &block) click to toggle source
# File lib/rstruct/struct_builder.rb, line 20
def array(name, typ, count, opts={}, &block)
  @__fields << ArrayType.new(name, typ, count, opts, &block)
end
field(name, typ, typ_name, *args, &block) click to toggle source
# File lib/rstruct/struct_builder.rb, line 16
def field(name, typ, typ_name, *args, &block)
  @__fields << Field.new(name,typ,args,block)
end
method_missing(typ_arg, *args, &block) click to toggle source
# File lib/rstruct/struct_builder.rb, line 24
def method_missing(typ_arg, *args, &block)
  name = args.shift
  unless typ = @__registry.get(typ_arg)
    raise(InvalidTypeError, "invalid field type: #{typ_arg}")
  end

  field(name, typ, typ_arg, *args, &block)
end