Class: Occi::Core::AttributeDefinition
- Inherits:
-
Object
- Object
- Occi::Core::AttributeDefinition
- Extended by:
- Helpers::YamlSummoner
- Includes:
- Helpers::ArgumentValidator, Yell::Loggable
- Defined in:
- lib/occi/core/attribute_definition.rb
Overview
Contains an attribute definition information. This definition does not carry the name of the attribute or its value. These should be associated with the definition by other means, e.g. in a hash ‘{ name: definition }` or by using instances of the `Occi::Core::Attribute` class.
Instance Attribute Summary collapse
-
#default ⇒ Object
default value, optional.
-
#description ⇒ String, NilClass
attribute description, optional.
-
#mutable ⇒ TrueClass, FalseClass
(also: #mutable?)
mutable flag.
-
#pattern ⇒ Regexp, NilClass
value pattern, only for type ‘String`.
-
#required ⇒ TrueClass, FalseClass
(also: #required?)
required flag.
-
#type ⇒ Class
Ruby class of the desired value.
Class Method Summary collapse
-
.allowed_yaml_classes ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#default? ⇒ TrueClass, FalseClass
Indicates the presence of a default value.
-
#immutable! ⇒ Object
Changes the value of ‘mutable` to `false`, in case `mutable` is `nil` or `true`.
-
#immutable? ⇒ TrueClass, FalseClass
Shorthand for getting the negated value of ‘mutable`.
-
#initialize(args = {}) ⇒ AttributeDefinition
constructor
Constructs an instance with sensible defaults.
-
#mutable! ⇒ Object
Changes the value of ‘mutable` to `true`, in case `mutable` is `nil` or `false`.
-
#optional! ⇒ Object
Changes the value of ‘required` to `false`, in case `required` is `nil` or `true`.
-
#optional? ⇒ TrueClass, FalseClass
Shorthand for getting the negated value of ‘required`.
-
#pattern? ⇒ TrueClass, FalseClass
Indicates the presence of a pattern for value.
-
#required! ⇒ Object
Changes the value of ‘required` to `true`, in case `required` is `nil` or `false`.
-
#valid!(value) ⇒ Object
Indicates whether the given value is an acceptable value for an attribute with this definition.
-
#valid?(value) ⇒ TrueClass, FalseClass
Indicates whether the given value is an acceptable value for an attribute with this definition.
Methods included from Helpers::YamlSummoner
from_yaml, needs_dereferencing?
Constructor Details
#initialize(args = {}) ⇒ AttributeDefinition
Constructs an instance with sensible defaults. The default definition is for a String-based optional attribute without a pattern.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/occi/core/attribute_definition.rb', line 41 def initialize(args = {}) default_args! args @type = args.fetch(:type) @required = args.fetch(:required) @mutable = args.fetch(:mutable) @default = args.fetch(:default) @description = args.fetch(:description) @pattern = args.fetch(:pattern) end |
Instance Attribute Details
#default ⇒ Object
default value, optional
18 19 20 |
# File 'lib/occi/core/attribute_definition.rb', line 18 def default @default end |
#description ⇒ String, NilClass
attribute description, optional
18 19 20 |
# File 'lib/occi/core/attribute_definition.rb', line 18 def description @description end |
#mutable ⇒ TrueClass, FalseClass Also known as: mutable?
mutable flag
18 19 20 |
# File 'lib/occi/core/attribute_definition.rb', line 18 def mutable @mutable end |
#pattern ⇒ Regexp, NilClass
value pattern, only for type ‘String`
18 19 20 |
# File 'lib/occi/core/attribute_definition.rb', line 18 def pattern @pattern end |
#required ⇒ TrueClass, FalseClass Also known as: required?
required flag
18 19 20 |
# File 'lib/occi/core/attribute_definition.rb', line 18 def required @required end |
#type ⇒ Class
Ruby class of the desired value
18 19 20 |
# File 'lib/occi/core/attribute_definition.rb', line 18 def type @type end |
Class Method Details
Instance Method Details
#default? ⇒ TrueClass, FalseClass
Indicates the presence of a default value.
129 130 131 |
# File 'lib/occi/core/attribute_definition.rb', line 129 def default? !default.nil? end |
#immutable! ⇒ Object
Changes the value of ‘mutable` to `false`, in case `mutable` is `nil` or `true`.
118 119 120 |
# File 'lib/occi/core/attribute_definition.rb', line 118 def immutable! self.mutable = false end |
#immutable? ⇒ TrueClass, FalseClass
Shorthand for getting the negated value of ‘mutable`.
107 108 109 |
# File 'lib/occi/core/attribute_definition.rb', line 107 def immutable? !mutable? end |
#mutable! ⇒ Object
Changes the value of ‘mutable` to `true`, in case `mutable` is `nil` or `false`.
96 97 98 |
# File 'lib/occi/core/attribute_definition.rb', line 96 def mutable! self.mutable = true end |
#optional! ⇒ Object
Changes the value of ‘required` to `false`, in case `required` is `nil` or `true`.
85 86 87 |
# File 'lib/occi/core/attribute_definition.rb', line 85 def optional! self.required = false end |
#optional? ⇒ TrueClass, FalseClass
Shorthand for getting the negated value of ‘required`.
74 75 76 |
# File 'lib/occi/core/attribute_definition.rb', line 74 def optional? !required? end |
#pattern? ⇒ TrueClass, FalseClass
Indicates the presence of a pattern for value.
140 141 142 |
# File 'lib/occi/core/attribute_definition.rb', line 140 def pattern? !pattern.nil? end |
#required! ⇒ Object
Changes the value of ‘required` to `true`, in case `required` is `nil` or `false`.
63 64 65 |
# File 'lib/occi/core/attribute_definition.rb', line 63 def required! self.required = true end |
#valid!(value) ⇒ Object
Indicates whether the given value is an acceptable value for an attribute with this definition. This method will raise an error if the given value is not acceptable.
174 175 176 177 |
# File 'lib/occi/core/attribute_definition.rb', line 174 def valid!(value) valid_type! valid_value! value end |
#valid?(value) ⇒ TrueClass, FalseClass
Indicates whether the given value is an acceptable value for an attribute with this definition.
153 154 155 156 157 158 159 160 161 162 |
# File 'lib/occi/core/attribute_definition.rb', line 153 def valid?(value) begin valid! value rescue Occi::Core::Errors::AttributeValidationError => ex logger.debug { "AttributeValidation: #{ex.}" } return false end true end |