Module: MotionMigrate::MotionGenerate::Property::ClassMethods
- Defined in:
- lib/motion_migrate/motion_generate/property.rb
Instance Method Summary collapse
- #core_data_property_attributes(type, options) ⇒ Object
- #properties ⇒ Object
- #property(name, type, options = {}) ⇒ Object
- #property_option_allowed?(type, option) ⇒ Boolean
- #property_type_allowed?(type) ⇒ Boolean
- #raise_if_property_option_not_allowed(type, option) ⇒ Object
- #raise_if_property_type_not_allowed(type) ⇒ Object
Instance Method Details
#core_data_property_attributes(type, options) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/motion_migrate/motion_generate/property.rb', line 131 def core_data_property_attributes(type, ) attributes = {} .each do |key, value| case key when :required attributes[:optional] = core_data_boolean(value != true) when :transient attributes[:transient] = core_data_boolean(value) when :indexed attributes[:indexed] = core_data_boolean(value) when :spotlight attributes[:spotlightIndexingEnabled] = core_data_boolean(value) when :truth_file attributes[:storedInTruthFile] = core_data_boolean(value) when :min if type == :date attributes[:minDateTimeInterval] = core_data_date(value) else attributes[:minValueString] = value end when :max if type == :date attributes[:maxDateTimeInterval] = core_data_date(value) else attributes[:maxValueString] = value end when :default if type == :date attributes[:defaultDateTimeInterval] = core_data_date(value) elsif type == :boolean attributes[:defaultValueString] = core_data_boolean(value) else attributes[:defaultValueString] = value end when :regex attributes[:regularExpressionString] = value when :external_storage attributes[:allowsExternalBinaryDataStorage] = core_data_boolean(value) when :transformer_name attributes[:valueTransformerName] = value end end attributes end |
#properties ⇒ Object
28 29 30 |
# File 'lib/motion_migrate/motion_generate/property.rb', line 28 def properties @@properties ||= {} end |
#property(name, type, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/motion_migrate/motion_generate/property.rb', line 9 def property(name, type, ={}) type = type.to_sym raise_if_property_type_not_allowed(type) .each { |key, value| raise_if_property_option_not_allowed(type, key) } attribute_type = type == :binary_data ? "Binary" : core_data_string(type) attributes = { name: name, attributeType: attribute_type, optional: core_data_boolean(true), syncable: core_data_boolean(true) } attributes.merge!(core_data_property_attributes(type, )) properties[self.entity_name] = {} if properties[self.entity_name].nil? properties[self.entity_name][name] = attributes attributes end |
#property_option_allowed?(type, option) ⇒ Boolean
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/motion_migrate/motion_generate/property.rb', line 102 def property_option_allowed?(type, option) type = :number if [ :integer_16, :integer_32, :integer_64, :decimal, :double, :float, :date ].include?(type) = { number: [:min, :max, :default], string: [:min, :max, :default, :regex], boolean: [:default], binary_data: [:external_storage], transformable: [:transformer_name] }[type] += [ :required, :transient, :indexed, :spotlight, :truth_file ] .include?(option) end |
#property_type_allowed?(type) ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/motion_migrate/motion_generate/property.rb', line 51 def property_type_allowed?(type) [ :string, :integer_16, :integer_32, :integer_64, :decimal, :double, :float, :boolean, :date, :binary_data, :transformable ].include?(type) end |
#raise_if_property_option_not_allowed(type, option) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/motion_migrate/motion_generate/property.rb', line 67 def raise_if_property_option_not_allowed(type, option) unless property_option_allowed?(type, option) raise <<-ERROR ! The option must be one of the following: ! ! For type :string: ! :min ! :max ! :default ! :regex ! ! For type :boolean: ! :default ! ! For type :date, :integer_16, :integer_32, :integer_64, :decimal, :double or :float: ! :min ! :max ! :default ! ! For type :binary_data: ! :external_storage ! ! For type :transformable: ! :transformer_name ! ! Options allowed for all types: ! :required ! :transient ! :indexed ! :spotlight ! :truth_file ERROR end end |
#raise_if_property_type_not_allowed(type) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/motion_migrate/motion_generate/property.rb', line 32 def raise_if_property_type_not_allowed(type) unless property_type_allowed?(type) raise <<-ERROR ! The type must be one of the following: ! :string ! :integer_16 ! :integer_32 ! :integer_64 ! :decimal ! :double ! :float ! :boolean ! :date ! :binary_data ! :transformable ERROR end end |