class Hashme::Property

Attributes

array[R]
name[R]
type[R]

Public Class Methods

new(name, type, opts = {}) click to toggle source
# File lib/hashme/property.rb, line 6
def initialize(name, type, opts = {})
  @name = name.to_sym

  # Always set type to base type
  if type.is_a?(Array) && !type.first.nil?
    @array = true
    @type = type.first
  else
    @array = false
    @type = type
  end

  # Handle options
  @default = opts[:default]
end

Public Instance Methods

build(owner, value) click to toggle source

Build a new object of the type defined by the property.

# File lib/hashme/property.rb, line 36
def build(owner, value)
  if array && value.is_a?(Array)
    CastedArray.new(self, owner, value)
  else
    PropertyCasting.cast(self, owner, value)
  end
end
default() click to toggle source
# File lib/hashme/property.rb, line 30
def default
  return @default.call if @default.is_a?(Proc)
  @default
end
to_s() click to toggle source
# File lib/hashme/property.rb, line 22
def to_s
  name.to_s
end
to_sym() click to toggle source
# File lib/hashme/property.rb, line 26
def to_sym
  name
end