Class: Zodra::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/zodra/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, optional: false, nullable: false, format: nil, default: nil, min: nil, max: nil, enum: nil, of: nil, reference_name: nil) ⇒ Attribute

Returns a new instance of Attribute.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/zodra/attribute.rb', line 7

def initialize(name:, type:, optional: false, nullable: false, format: nil,
               default: nil, min: nil, max: nil, enum: nil, of: nil, reference_name: nil)
  @name = name.to_sym
  @type = type.to_sym
  @optional = optional
  @nullable = nullable
  @format = format
  @default = default
  @min = min
  @max = max
  @enum = enum
  @of = of
  @reference_name = reference_name
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



5
6
7
# File 'lib/zodra/attribute.rb', line 5

def default
  @default
end

#enumObject (readonly)

Returns the value of attribute enum.



5
6
7
# File 'lib/zodra/attribute.rb', line 5

def enum
  @enum
end

#formatObject (readonly)

Returns the value of attribute format.



5
6
7
# File 'lib/zodra/attribute.rb', line 5

def format
  @format
end

#maxObject (readonly)

Returns the value of attribute max.



5
6
7
# File 'lib/zodra/attribute.rb', line 5

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



5
6
7
# File 'lib/zodra/attribute.rb', line 5

def min
  @min
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/zodra/attribute.rb', line 5

def name
  @name
end

#ofObject (readonly)

Returns the value of attribute of.



5
6
7
# File 'lib/zodra/attribute.rb', line 5

def of
  @of
end

#reference_nameObject (readonly)

Returns the value of attribute reference_name.



5
6
7
# File 'lib/zodra/attribute.rb', line 5

def reference_name
  @reference_name
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/zodra/attribute.rb', line 5

def type
  @type
end

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/zodra/attribute.rb', line 34

def array?
  type == :array
end

#dependency_nameObject



38
39
40
41
42
43
44
# File 'lib/zodra/attribute.rb', line 38

def dependency_name
  if reference?
    reference_name.to_sym
  elsif array? && of
    of.to_sym
  end
end

#nullable?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/zodra/attribute.rb', line 26

def nullable?
  @nullable
end

#optional?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/zodra/attribute.rb', line 22

def optional?
  @optional
end

#reference?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/zodra/attribute.rb', line 30

def reference?
  type == :reference
end