Class: Fried::Schema::Attribute::Definition

Inherits:
Struct
  • Object
show all
Defined in:
lib/fried/schema/attribute/definition.rb

Overview

Value-type holding definition of attribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Struct

#<=>, included

Instance Attribute Details

#defaultObject

Any object. If a Proc is used, it will be evaluated during initialization



5
6
7
# File 'lib/fried/schema/attribute/definition.rb', line 5

def default
  @default
end

#nameObject

A Symbol



5
6
7
# File 'lib/fried/schema/attribute/definition.rb', line 5

def name
  @name
end

#typeObject

Any Class or Module, or Typings::Type



5
6
7
# File 'lib/fried/schema/attribute/definition.rb', line 5

def type
  @type
end

Instance Method Details

#extract_defaultObject

Extracts content of #default if it’s a Proc, otherwise just returns #default



34
35
36
37
# File 'lib/fried/schema/attribute/definition.rb', line 34

def extract_default
  return default.() if default.is_a?(::Proc)
  default
end

#instance_variableSymbol

Attribute instance variable name (@variable)

Returns:

  • (Symbol)


28
29
30
# File 'lib/fried/schema/attribute/definition.rb', line 28

def instance_variable
  :"@#{reader}"
end

#readerSymbol

Attribute reader method name

Returns:

  • (Symbol)


16
17
18
# File 'lib/fried/schema/attribute/definition.rb', line 16

def reader
  name.to_sym
end

#writerSymbol

Attribute writer method name

Returns:

  • (Symbol)


22
23
24
# File 'lib/fried/schema/attribute/definition.rb', line 22

def writer
  :"#{reader}="
end