class Leafy::Field

Attributes

id[RW]
metadata[RW]
name[RW]
type[RW]

Public Class Methods

new(attributes = {}) click to toggle source
# 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.metadata = attributes.fetch(:metadata, {})
end

Public Instance Methods

serializable_hash() click to toggle source
# File lib/leafy/field.rb, line 18
def serializable_hash
  {
    name: name,
    type: type,
    id: id,
    metadata: metadata
  }
end