Parent

Files

Class/Module Index [+]

Quicksearch

BinData::Base

This is the abstract base class for all data objects.

Attributes

parent[RW]

Public Class Methods

arg_extractor() click to toggle source

The arg extractor for this class.

# File lib/bindata/base.rb, line 56
def arg_extractor
  BaseArgExtractor
end
bindata_name() click to toggle source

The name of this class as used by Records, Arrays etc.

# File lib/bindata/base.rb, line 61
def bindata_name
  RegisteredClasses.underscore_name(self.name)
end
read(io) click to toggle source

Instantiates this class and reads from io, returning the newly created data object.

# File lib/bindata/base.rb, line 49
def read(io)
  obj = self.new
  obj.read(io)
  obj
end

Public Instance Methods

clear() click to toggle source

Resets the internal state to that of a newly created object.

# File lib/bindata/base.rb, line 158
def clear
  initialize_instance
end
eval_parameter(key, overrides = nil) click to toggle source

Returns the result of evaluating the parameter identified by key.

overrides is an optional parameters like hash that allow the parameters given at object construction to be overridden.

Returns nil if key does not refer to any parameter.

# File lib/bindata/base.rb, line 131
def eval_parameter(key, overrides = nil)
  value = get_parameter(key)
  if value.is_a?(Symbol) or value.respond_to?(:arity)
    lazy_evaluator.lazy_eval(value, overrides)
  else
    value
  end
end
get_parameter(key) click to toggle source

Returns the parameter referenced by key. Use this method if you are sure the parameter is not to be evaluated. You most likely want eval_parameter.

# File lib/bindata/base.rb, line 148
def get_parameter(key)
  @params[key]
end
has_parameter?(key) click to toggle source

Returns whether key exists in the parameters hash.

# File lib/bindata/base.rb, line 153
def has_parameter?(key)
  @params.has_parameter?(key)
end
initialize(*args) click to toggle source
Also aliased as: initialize_without_warning
initialize_instance(*args) click to toggle source
# File lib/bindata/deprecated.rb, line 26
def initialize_instance(*args)
  unless args.empty?
    fail "#{caller[0]} remove the call to super in #initialize_instance"
  end
end
initialize_with_warning(*args) click to toggle source
# File lib/bindata/deprecated.rb, line 13
def initialize_with_warning(*args)
  owner = method(:initialize).owner
  if owner != BinData::Base
    msg = "Don't override #initialize on #{owner}."
    if %(BinData::Base BinData::BasePrimitive).include? self.class.superclass.name
      msg += "\nrename #initialize to #initialize_instance."
    end
    fail msg
  end
  initialize_without_warning(*args)
end
Also aliased as: initialize
initialize_without_warning(*args) click to toggle source

Don’t override initialize. If you are defining a new kind of datatype (list, array, choice etc) then put your initialization code in initialize_instance. This is because BinData objects can be initialized as prototypes and your initialization code may not be called.

If you’re subclassing BinData::Record, you are definitely doing the wrong thing. Read the documentation on how to use BinData. bindata.rubyforge.org/manual.html#records

Alias for: initialize
new(value = nil, parent = nil) click to toggle source

Creates a new data object based on this instance.

All parameters will be be duplicated. Use this method when creating multiple objects with the same parameters.

# File lib/bindata/base.rb, line 116
def new(value = nil, parent = nil)
  obj = clone
  obj.parent = parent if parent
  obj.initialize_instance
  obj.assign(value) if value

  obj
end
read(io) click to toggle source

Reads data into this data object.

# File lib/bindata/base.rb, line 163
def read(io)
  io = BinData::IO::Read.new(io) unless BinData::IO::Read === io

  @in_read = true
  clear
  do_read(io)
  @in_read = false

  self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.