Object
This is the abstract base class for all data objects.
The arg processor for this class.
# File lib/bindata/base.rb, line 28 def arg_processor(name = nil) if name @arg_processor = "#{name}_arg_processor".gsub(/(?:^|_)(.)/) { $1.upcase }.to_sym elsif @arg_processor.is_a? Symbol @arg_processor = BinData::const_get(@arg_processor).new elsif @arg_processor.nil? @arg_processor = superclass.arg_processor else @arg_processor end end
The name of this class as used by Records, Arrays etc.
# File lib/bindata/base.rb, line 41 def bindata_name RegisteredClasses.underscore_name(self.name) end
Creates a new data object.
Args are optional, but if present, must be in the following order.
value is a value that is +assign+ed immediately after initialization.
parameters is a hash containing symbol keys. Some parameters may reference callable objects (methods or procs).
parent is the parent data object (e.g. struct, array, choice) this object resides under.
# File lib/bindata/base.rb, line 79 def initialize(*args) value, @params, @parent = extract_args(args) initialize_shared_instance initialize_instance assign(value) if value end
Resets the internal state to that of a newly created object.
# File lib/bindata/base.rb, line 136 def clear initialize_instance end
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 109 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
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 126 def get_parameter(key) @params[key] end
Returns whether key exists in the parameters hash.
# File lib/bindata/base.rb, line 131 def has_parameter?(key) @params.has_parameter?(key) end
# File lib/bindata/warnings.rb, line 26 def initialize_instance(*args) unless args.empty? fail "#{caller[0]} remove the call to super in #initialize_instance" end end
# File lib/bindata/warnings.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
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 94 def new(value = nil, parent = nil) obj = clone obj.parent = parent if parent obj.initialize_instance obj.assign(value) if value obj end
Generated with the Darkfish Rdoc Generator 2.