File: name.rb

package info (click to toggle)
ruby-bindata 2.4.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 600 kB
  • sloc: ruby: 8,566; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 889 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module BinData
  # == Parameters
  #
  # Parameters may be provided at initialisation to control the behaviour of
  # an object.  These parameters are:
  #
  # <tt>:name</tt>:: The name that this object can be referred to may be
  #                  set explicitly.  This is only useful when dynamically
  #                  generating types.
  #                  <code><pre>
  #                    BinData::Struct.new(name: :my_struct, fields: ...)
  #                    array = BinData::Array.new(type: :my_struct)
  #                  </pre></code>
  module RegisterNamePlugin

    def self.included(base) #:nodoc:
      # The registered name may be provided explicitly.
      base.optional_parameter :name
    end

    def initialize_shared_instance
      if has_parameter?(:name)
        RegisteredClasses.register(get_parameter(:name), self)
      end
      super
    end
  end
end