Class: Rumbly::Model::Attribute

Inherits:
Object
  • Object
show all
Extended by:
Abstract
Defined in:
lib/rumbly/model/attribute.rb

Overview

This is an abstract class that represents a single attribute of one class within an MVC application. Object mapper-specific implementations should subclass this class and implement the following methods: name, type, visibility, multiplicity, default, properties, constraints, derived, and static.

Direct Known Subclasses

Rumbly::Model::ActiveRecord::Attribute

Constant Summary collapse

ATTRIBUTES =

Attributes and default values of an Attribute

{
  name: '', type: '', visibility: '', multiplicity: '', default: '',
  properties: [], constraints: [], derived: false, static: false
}

Instance Method Summary collapse

Methods included from Abstract

stub_required_methods

Instance Method Details

#<=>(other) ⇒ Object

Compares Attribute objects using the name attribute.



33
34
35
# File 'lib/rumbly/model/attribute.rb', line 33

def <=> (other)
  name <=> other.name
end

#derived?Boolean

Simple question mark-style wrapper for the Attribute#derived attribute.

Returns:

  • (Boolean)


23
24
25
# File 'lib/rumbly/model/attribute.rb', line 23

def derived?
  derived
end

#labelObject

Returns a string that fully describes this Attribute, including its visibility, name, type, multiplicity, default value, and any properties and/or constraints.



39
40
41
42
43
44
45
46
47
48
# File 'lib/rumbly/model/attribute.rb', line 39

def label
  label  = "#{symbol_for_visibility} "
  label += "/" if derived?
  label += "#{name}"
  label += " : #{type}" unless type.nil?
  label += "[#{multiplicity}]" unless multiplicity.nil?
  label += " = #{default}" unless default.nil?
  label += " {#{props_and_constraints}}" unless props_and_constraints.empty?
  label
end

#static?Boolean

Simple question mark-style wrapper for the Attribute#static attribute.

Returns:

  • (Boolean)


28
29
30
# File 'lib/rumbly/model/attribute.rb', line 28

def static?
  static
end