Module: Bluepine::Attributes

Includes:
Assertions
Defined in:
lib/bluepine/attributes.rb,
lib/bluepine/attributes/visitor.rb,
lib/bluepine/attributes/attribute.rb,
lib/bluepine/attributes/uri_attribute.rb,
lib/bluepine/attributes/date_attribute.rb,
lib/bluepine/attributes/time_attribute.rb,
lib/bluepine/attributes/array_attribute.rb,
lib/bluepine/attributes/float_attribute.rb,
lib/bluepine/attributes/number_attribute.rb,
lib/bluepine/attributes/object_attribute.rb,
lib/bluepine/attributes/schema_attribute.rb,
lib/bluepine/attributes/string_attribute.rb,
lib/bluepine/attributes/boolean_attribute.rb,
lib/bluepine/attributes/integer_attribute.rb,
lib/bluepine/attributes/currency_attribute.rb,
lib/bluepine/attributes/ip_address_attribute.rb

Overview

Attributes registry holds the references to all attributes

See Also:

Defined Under Namespace

Classes: ArrayAttribute, Attribute, BooleanAttribute, CurrencyAttribute, DateAttribute, FloatAttribute, IPAddressAttribute, IntegerAttribute, NumberAttribute, ObjectAttribute, SchemaAttribute, StringAttribute, TimeAttribute, URIAttribute, Visitor

Constant Summary collapse

KeyError =
Bluepine::Error.create "Attribute %s already exists"
ALL =
{
  string:       StringAttribute,
  number:       NumberAttribute,
  integer:      IntegerAttribute,
  float:        FloatAttribute,
  boolean:      BooleanAttribute,
  object:       ObjectAttribute,
  array:        ArrayAttribute,
  schema:       SchemaAttribute,
  time:         TimeAttribute,
  date:         DateAttribute,
  uri:          URIAttribute,
  currency:     CurrencyAttribute,
  ip_address:   IPAddressAttribute,
}.freeze
SCALAR_TYPES =
%i[string number integer float boolean].freeze
NATIVE_TYPES =
SCALAR_TYPES + %i[array object].freeze
NON_SCALAR_TYPES =
ALL.keys - SCALAR_TYPES

Constants included from Assertions

Bluepine::Assertions::Error, Bluepine::Assertions::SubsetError

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Assertions

#assert, #assert_in, #assert_kind_of, #assert_not, #assert_subset_of, included

Class Attribute Details

.registryRegistry

Holds reference to all attribute objects

Returns:



39
40
41
# File 'lib/bluepine/attributes.rb', line 39

def registry
  @registry
end

Class Method Details

.create(type, name, options = {}, &block) ⇒ Attribute

Creates new attribute (Delegates to Registry#create).

Examples:

Creates primitive attribute

Attributes.create(:string, :username, required: true)

Creates compound attribute

Attributes.create(:object, :user) do
  string :username
end

Returns:



52
53
54
# File 'lib/bluepine/attributes.rb', line 52

def create(type, name, options = {}, &block)
  registry.create(type, name, options, &block)
end

.key?(key) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/bluepine/attributes.rb', line 64

def key?(key)
  registry.key?(key)
end

.register(type, klass, override: false) ⇒ Object

Registers new Attribute (alias for Registry#register)

Examples:

register(:custom, CustomAttribute)


60
61
62
# File 'lib/bluepine/attributes.rb', line 60

def register(type, klass, override: false)
  registry.register(type, klass, override: override)
end