Class: Requisite::BoundaryObject

Inherits:
Object
  • Object
show all
Defined in:
lib/requisite/boundary_object.rb

Direct Known Subclasses

ApiModel

Class Method Summary collapse

Class Method Details

.attribute(name, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/requisite/boundary_object.rb', line 4

def attribute(name, options={})
  attribute_keys << name
  define_method(name) do
    resolved_name = options[:rename] || name
    result = self.send(:convert, resolved_name)
    result = self.send(:parse_typed_hash, resolved_name, options[:typed_hash]) if options[:typed_hash]
    result = self.send(:parse_scalar_hash, resolved_name) if options[:scalar_hash]
    result = self.send(:parse_typed_array, resolved_name, options[:typed_array]) if options[:typed_array]
    result = options[:default] if (options.key?(:default) && empty_result?(result))
    raise_bad_type_if_type_mismatch(result, options[:type]) if options[:type] && result
    result = result.to_s if options[:stringify]
    result
  end
end

.attribute!(name, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/requisite/boundary_object.rb', line 19

def attribute!(name, options={})
  attribute_keys << name
  define_method(name) do
    resolved_name = options[:rename] || name
    result = self.send(:convert!, resolved_name)
    result = self.send(:parse_typed_hash, resolved_name, options[:typed_hash]) if options[:typed_hash]
    result = self.send(:parse_scalar_hash, resolved_name) if options[:scalar_hash]
    result = self.send(:parse_typed_array, resolved_name, options[:typed_array]) if options[:typed_array]
    result = result.to_s if options[:stringify]
    raise_bad_type_if_type_mismatch(result, options[:type]) if options[:type]
    result
  end
end

.attribute_keysObject



38
39
40
# File 'lib/requisite/boundary_object.rb', line 38

def attribute_keys
  @attribute_keys || []
end

.attribute_keys_with_inheritanceObject



42
43
44
# File 'lib/requisite/boundary_object.rb', line 42

def attribute_keys_with_inheritance
  superclass.respond_to?(:attribute_keys_with_inheritance) ? superclass.attribute_keys_with_inheritance.concat(attribute_keys) : attribute_keys || []
end

.serialized_attributes(&block) ⇒ Object



33
34
35
36
# File 'lib/requisite/boundary_object.rb', line 33

def serialized_attributes(&block)
  @attribute_keys = []
  instance_eval(&block)
end