Module: XDR::DSL::Struct

Included in:
Struct
Defined in:
lib/xdr/dsl/struct.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, type) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/xdr/dsl/struct.rb', line 2

def attribute(name, type)
  unless type.is_a?(XDR::Concerns::ConvertsToXDR)
    raise ArgumentError, "#{type} does not convert to xdr"
  end

  self.fields = fields.merge(name => type)

  define_method name do
    read_attribute(name)
  end

  define_method "#{name}=" do |v|
    write_attribute(name, v)
  end

  define_attribute_methods name
end