Class: Convection::Model::Template::Resource::Property
- Inherits:
-
Object
- Object
- Convection::Model::Template::Resource::Property
- Defined in:
- lib/convection/model/template/resource.rb
Overview
Validation and intraspection for resource properties
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#equal_to ⇒ Object
readonly
Returns the value of attribute equal_to.
-
#immutable ⇒ Object
(also: #immutable?)
readonly
Returns the value of attribute immutable.
-
#kind_of ⇒ Object
readonly
Returns the value of attribute kind_of.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#property_name ⇒ Object
readonly
Returns the value of attribute property_name.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#transform ⇒ Object
readonly
Returns the value of attribute transform.
Class Method Summary collapse
-
.create(name, property_name, options = {}) ⇒ Object
Switch between Scalar and List.
Instance Method Summary collapse
-
#initialize(name, property_name, options = {}) ⇒ Property
constructor
A new instance of Property.
Constructor Details
#initialize(name, property_name, options = {}) ⇒ Property
Returns a new instance of Property
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/convection/model/template/resource.rb', line 73 def initialize(name, property_name, = {}) @name = name @property_name = property_name @default = [:default] @transform = .fetch(:transform, []).is_a?(Array) ? .fetch(:transform, []) : [[:transform]] @immutable = [:immutable].is_a?(TrueClass) @required = .fetch(:required, false) @equal_to = .fetch(:equal_to, []).is_a?(Array) ? .fetch(:equal_to, []) : [[:equal_to]] @kind_of = .fetch(:kind_of, []).is_a?(Array) ? .fetch(:kind_of, []) : [[:kind_of]] @regex = .fetch(:regex, false) end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default
51 52 53 |
# File 'lib/convection/model/template/resource.rb', line 51 def default @default end |
#equal_to ⇒ Object (readonly)
Returns the value of attribute equal_to
57 58 59 |
# File 'lib/convection/model/template/resource.rb', line 57 def equal_to @equal_to end |
#immutable ⇒ Object (readonly) Also known as: immutable?
Returns the value of attribute immutable
54 55 56 |
# File 'lib/convection/model/template/resource.rb', line 54 def immutable @immutable end |
#kind_of ⇒ Object (readonly)
Returns the value of attribute kind_of
58 59 60 |
# File 'lib/convection/model/template/resource.rb', line 58 def kind_of @kind_of end |
#name ⇒ Object (readonly)
Returns the value of attribute name
49 50 51 |
# File 'lib/convection/model/template/resource.rb', line 49 def name @name end |
#property_name ⇒ Object (readonly)
Returns the value of attribute property_name
50 51 52 |
# File 'lib/convection/model/template/resource.rb', line 50 def property_name @property_name end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex
59 60 61 |
# File 'lib/convection/model/template/resource.rb', line 59 def regex @regex end |
#required ⇒ Object (readonly)
Returns the value of attribute required
56 57 58 |
# File 'lib/convection/model/template/resource.rb', line 56 def required @required end |
#transform ⇒ Object (readonly)
Returns the value of attribute transform
52 53 54 |
# File 'lib/convection/model/template/resource.rb', line 52 def transform @transform end |
Class Method Details
.create(name, property_name, options = {}) ⇒ Object
Switch between Scalar and List
63 64 65 66 67 68 69 70 |
# File 'lib/convection/model/template/resource.rb', line 63 def create(name, property_name, = {}) case [:type] when :string, :scalar, nil then ScalarProperty.new(name, property_name, ) when :array, :list then ListProperty.new(name, property_name, ) when :hash then HashProperty.new(name, property_name, ) else fail TypeError, "Property must be defined with type `string` or `array`, not #{ [:type] }" end end |