Class: Convection::Model::Template::Resource::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/convection/model/template/resource.rb

Overview

Validation and intraspection for resource properties

Direct Known Subclasses

HashProperty, ListProperty, ScalarProperty

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, 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

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default



51
52
53
# File 'lib/convection/model/template/resource.rb', line 51

def default
  @default
end

#equal_toObject (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

#immutableObject (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_ofObject (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

#nameObject (readonly)

Returns the value of attribute name



49
50
51
# File 'lib/convection/model/template/resource.rb', line 49

def name
  @name
end

#property_nameObject (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

#regexObject (readonly)

Returns the value of attribute regex



59
60
61
# File 'lib/convection/model/template/resource.rb', line 59

def regex
  @regex
end

#requiredObject (readonly)

Returns the value of attribute required



56
57
58
# File 'lib/convection/model/template/resource.rb', line 56

def required
  @required
end

#transformObject (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, 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