lib/bindata/dsl.rb in bindata-2.2.0 vs lib/bindata/dsl.rb in bindata-2.3.0
- old
+ new
@@ -133,15 +133,16 @@
#-------------
private
def parser_abilities
@abilities ||= {
- :struct => [:to_struct_params, [:multiple_fields, :optional_fieldnames, :hidden_fields]],
- :array => [:to_array_params, [:multiple_fields, :optional_fieldnames]],
- :buffer => [:to_array_params, [:multiple_fields, :optional_fieldnames, :hidden_fields]],
- :choice => [:to_choice_params, [:multiple_fields, :all_or_none_fieldnames, :fieldnames_are_values]],
- :primitive => [:to_struct_params, [:multiple_fields, :optional_fieldnames]]
+ :struct => [:to_struct_params, [:multiple_fields, :optional_fieldnames, :hidden_fields]],
+ :array => [:to_array_params, [:multiple_fields, :optional_fieldnames]],
+ :buffer => [:to_array_params, [:multiple_fields, :optional_fieldnames, :hidden_fields]],
+ :choice => [:to_choice_params, [:multiple_fields, :all_or_none_fieldnames, :fieldnames_are_values]],
+ :delayed_io => [:to_array_params, [:multiple_fields, :optional_fieldnames, :hidden_fields]],
+ :primitive => [:to_struct_params, [:multiple_fields, :optional_fieldnames]]
}
end
def option?(opt)
parser_abilities[@parser_type].at(1).include?(opt)
@@ -151,14 +152,11 @@
endian
search_prefix
end
def hints
- {
- :endian => endian,
- :search_prefix => search_prefix,
- }
+ { :endian => endian, :search_prefix => search_prefix }
end
def set_endian(endian)
if endian
if has_fields?
@@ -183,11 +181,11 @@
def parent_fields
parent_attribute(:fields)
end
def has_fields?
- @fields && @fields.length > 0
+ defined? @fields and @fields.length > 0
end
def parse_and_append_field(*args, &block)
parser = DSLFieldParser.new(hints, *args, &block)
begin
@@ -287,11 +285,11 @@
:big => class_with_endian(bnl_class, :big),
:little => class_with_endian(bnl_class, :little),
}
bnl_class.define_singleton_method(:new) do |*args|
if self == bnl_class
- value, options, parent = arg_processor.separate_args(self, args)
+ _, options, _ = arg_processor.separate_args(self, args)
delegate = endian_classes[options[:endian]]
return delegate.new(*args) if delegate
end
super(*args)
@@ -337,17 +335,12 @@
:search_prefix => class_name.dsl_parser.search_prefix,
}
RegisteredClasses.lookup(class_name, hints)
end
- def obj_attribute(obj, attr, default = nil)
- parser = obj.respond_to?(:dsl_parser) ? obj.dsl_parser : nil
- if parser and parser.respond_to?(attr)
- parser.send(attr)
- else
- default
- end
+ def obj_attribute(obj, attr)
+ obj.dsl_parser.send(attr)
end
end
end
# Extracts the details from a field declaration.
@@ -360,11 +353,11 @@
end
attr_reader :type, :name, :params
def name_from_field_declaration(args)
- name, params = args
+ name, _ = args
if name == "" or name.is_a?(Hash)
nil
else
name
end
@@ -387,13 +380,14 @@
params || {}
end
def params_from_block(&block)
bindata_classes = {
- :array => BinData::Array,
- :buffer => BinData::Buffer,
- :choice => BinData::Choice,
- :struct => BinData::Struct
+ :array => BinData::Array,
+ :buffer => BinData::Buffer,
+ :choice => BinData::Choice,
+ :delayed_io => BinData::DelayedIO,
+ :struct => BinData::Struct
}
if bindata_classes.include?(@type)
parser = DSLParser.new(bindata_classes[@type], @type)
parser.endian(@hints[:endian])