Module: Vk::Schema::Definition::HasAttributes

Included in:
Method, Object, Response
Defined in:
lib/vk/schema/definition/has_attributes.rb

Instance Method Summary collapse

Instance Method Details

#attributes<Attribute>

Returns:


9
10
11
12
13
# File 'lib/vk/schema/definition/has_attributes.rb', line 9

def attributes
  @attributes ||= properties.map do |name, definition|
    Attribute.new(name, definition, schema, self)
  end
end

#propertiesHash{String => Hash}

Returns:

  • (Hash{String => Hash})

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vk/schema/definition/has_attributes.rb', line 16

def properties
  if definition['properties']
    definition['properties']
  elsif definition['allOf'].is_a?(Array)
    definition['allOf'].each_with_object({}) do |definition, memo|
      memo.merge!(definition['properties'] || {})
    end
  elsif definition['parameters'].is_a?(Array)
    definition['parameters'].each_with_object({}) do |parameter, memo|
      memo[parameter['name']] = parameter
    end
  else
    {}
  end
end

#required_attribute?(attribute) ⇒ Boolean

Parameters:

  • attribute (String)

Returns:

  • (Boolean)

34
35
36
37
# File 'lib/vk/schema/definition/has_attributes.rb', line 34

def required_attribute?(attribute)
  return false unless definition.key?('required')
  definition['required'].include?(attribute.to_s)
end