Module: XDR::DSL::Union

Included in:
Union
Defined in:
lib/xdr/dsl/union.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, type) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'lib/xdr/dsl/union.rb', line 17

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

  self.arms = arms.merge(name => type)
  define_attribute_methods name
end

#switch(switch, arm = nil) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
# File 'lib/xdr/dsl/union.rb', line 10

def switch(switch, arm = nil)
  raise ArgumentError, "`switch_on` not defined yet" if switch_type.nil?

  switch = normalize_switch_declaration(switch)
  self.switches = switches.merge(switch => arm)
end

#switch_on(type, name) ⇒ Object

Raises:

  • (ArgumentError)


2
3
4
5
6
7
8
# File 'lib/xdr/dsl/union.rb', line 2

def switch_on(type, name)
  raise ArgumentError if switch_type.present?
  self.switch_type = type
  self.switch_name = name

  alias_method name, :switch
end