class Convection::Model::Template::Resource::Property

Validation and intraspection for resource properties

Attributes

default[R]
equal_to[R]
immutable[R]
immutable?[R]
kind_of[R]
name[R]
property_name[R]
regex[R]
required[R]
transform[R]

Public Class Methods

create(name, property_name, options = {}) click to toggle source

Switch between Scalar and List

# File lib/convection/model/template/resource.rb, line 63
def create(name, property_name, options = {})
  case options[:type]
  when :string, :scalar, nil then ScalarProperty.new(name, property_name, options)
  when :array, :list then ListProperty.new(name, property_name, options)
  when :hash then HashProperty.new(name, property_name, options)
  else fail TypeError, "Property must be defined with type `string` or `array`, not #{ options[:type] }"
  end
end
new(name, property_name, options = {}) click to toggle source
# File lib/convection/model/template/resource.rb, line 73
def initialize(name, property_name, options = {})
  @name = name
  @property_name = property_name
  @default = options[:default]
  @transform = options.fetch(:transform, []).is_a?(Array) ? options.fetch(:transform, []) : [options[:transform]]

  @immutable = options[:immutable].is_a?(TrueClass)
  @required = options.fetch(:required, false)
  @equal_to = options.fetch(:equal_to, []).is_a?(Array) ? options.fetch(:equal_to, []) : [options[:equal_to]]
  @kind_of = options.fetch(:kind_of, []).is_a?(Array) ? options.fetch(:kind_of, []) : [options[:kind_of]]
  @regex = options.fetch(:regex, false)
end