Class: Leafy::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/leafy/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Field

Returns a new instance of Field.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
# File 'lib/leafy/field.rb', line 8

def initialize(attributes = {})
  raise ArgumentError, "attributes is not a Hash" unless attributes.is_a?(Hash)
  attributes = Leafy::Utils.symbolize_keys(attributes)

  self.name = attributes.fetch(:name)
  self.type = attributes.fetch(:type)
  self.id = attributes.fetch(:id) { [name.downcase.strip.tr(" ", "-"), SecureRandom.uuid].join("-") }
  self. = attributes.fetch(:metadata, {})
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/leafy/field.rb', line 6

def id
  @id
end

#metadataObject

Returns the value of attribute metadata.



6
7
8
# File 'lib/leafy/field.rb', line 6

def 
  @metadata
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/leafy/field.rb', line 6

def name
  @name
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/leafy/field.rb', line 6

def type
  @type
end

Instance Method Details

#serializable_hashObject



18
19
20
21
22
23
24
25
# File 'lib/leafy/field.rb', line 18

def serializable_hash
  {
    name: name,
    type: type,
    id: id,
    metadata: 
  }
end