Module: CloudFormer::HasPropertiesAndAttributes::ClassMethods
- Defined in:
- lib/cloud_former/has_properties_and_attributes.rb
Instance Method Summary collapse
- #aws_attribute(name, options = {}) ⇒ Object
- #aws_attributes ⇒ Object
- #aws_properties ⇒ Object
- #aws_property(name, options = {}) ⇒ Object
- #check_type_of_aws_value(val, options) ⇒ Object
- #make_aws_accessor(name, options) ⇒ Object
Instance Method Details
#aws_attribute(name, options = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/cloud_former/has_properties_and_attributes.rb', line 16 def aws_attribute(name, ={}) @aws_attributes ||= [] @aws_attributes << PropertyOrAttribute.new(name, ) make_aws_accessor(name, ) end |
#aws_attributes ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cloud_former/has_properties_and_attributes.rb', line 92 def aws_attributes answer = [] if defined?(@aws_attributes) answer = @aws_attributes end if superclass && superclass.respond_to?(:aws_attributes) answer += superclass.aws_attributes end answer end |
#aws_properties ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cloud_former/has_properties_and_attributes.rb', line 81 def aws_properties answer = [] if defined?(@aws_properties) answer = @aws_properties end if superclass && superclass.respond_to?(:aws_properties) answer += superclass.aws_properties end answer end |
#aws_property(name, options = {}) ⇒ Object
10 11 12 13 14 |
# File 'lib/cloud_former/has_properties_and_attributes.rb', line 10 def aws_property(name, ={}) @aws_properties ||= [] @aws_properties << PropertyOrAttribute.new(name, ) make_aws_accessor(name, ) end |
#check_type_of_aws_value(val, options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cloud_former/has_properties_and_attributes.rb', line 22 def check_type_of_aws_value(val, ) if !val.is_a?([:type]) failed = true if [:type] == String if val.is_a?(Fixnum) failed = false elsif val.respond_to?(:acts_as_string?) && val.acts_as_string? failed = false end end if val.is_a?(Parameter) || val.is_a?(Resource) failed = false end if [:type] == Boolean && val == true || val == false failed = false end if failed raise ArgumentError.new( "A #{options[:type].name} is required for #{name} in #{self.name}, but a #{val.class.name} was given." ) end end end |
#make_aws_accessor(name, options) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cloud_former/has_properties_and_attributes.rb', line 49 def make_aws_accessor(name, ) define_method(name) do |val=nil| if val if [:list] && !val.respond_to?(:each) unless val.respond_to?(:acts_as_list?) && val.acts_as_list? raise ArgumentError.new( "A list is required for #{name} in #{self.class.name}, but a #{val.class.name} was given." ) end end if [:list] unless val.respond_to?(:acts_as_list?) && val.acts_as_list? val.each do |item| self.class.check_type_of_aws_value(item, ) end end else self.class.check_type_of_aws_value(val, ) end instance_variable_set("@#{name}", val) end if instance_variable_defined?("@#{name}") instance_variable_get("@#{name}") else nil end end end |