lib/rasn1/model.rb in rasn1-0.12.0 vs lib/rasn1/model.rb in rasn1-0.12.1

- old
+ new

@@ -64,10 +64,13 @@ # @author Sylvain Daubert # @author adfoster-r7 ModelValidationError, track source location for dynamic class methods class Model # rubocop:disable Metrics/ClassLength # @private Elem = Struct.new(:name, :proc_or_class, :content) do + # @param [String,Symbol] name + # @param [Proc,Class] proc_or_class + # @param [Hash,nil] content def initialize(name, proc_or_class, content) if content.is_a?(Array) duplicate_names = find_all_duplicate_names(content.map(&:name) + [name]) raise ModelValidationError, "Duplicate name #{duplicate_names.first} found" if duplicate_names.any? end @@ -86,15 +89,17 @@ end end # @private WrapElem = Struct.new(:element, :options) do + # @return [String] def name "#{element.name}_wrapper" end end + # Define helper methods to define models module Accel # @return [Hash] attr_reader :options # Use another model in this model @@ -143,10 +148,13 @@ super root = @root klass.class_eval { @root = root } end + # @private + # @param [String,Symbol] accel_name + # @param [Class] klass # @since 0.11.0 # @since 0.12.0 track source location on error (adfoster-r7) def define_type_accel_base(accel_name, klass) singleton_class.class_eval <<-EVAL, __FILE__, __LINE__ + 1 def #{accel_name}(name, options={}) # def sequence(name, type, options) @@ -157,10 +165,13 @@ @root = Elem.new(name, proc, options[:content]) end EVAL end + # @private + # @param [String,Symbol] accel_name + # @param [Class] klass # @since 0.11.0 # @since 0.12.0 track source location on error (adfoster-r7) def define_type_accel_of(accel_name, klass) singleton_class.class_eval <<-EVAL, __FILE__, __LINE__ + 1 def #{accel_name}_of(name, type, options={}) # def sequence_of(name, type, options) @@ -173,11 +184,12 @@ EVAL end # Define an accelarator to access a type in a model definition # @param [String] accel_name - # @param [Class] klass + # @param [Class] klass class to instanciate # @since 0.11.0 + # @since 0.12.0 track source location on error (adfoster-r7) def define_type_accel(accel_name, klass) if klass < Types::SequenceOf define_type_accel_of(accel_name, klass) else define_type_accel_base(accel_name, klass)