magic_addresses 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. checksums.yaml +5 -13
  2. data/README.md +58 -4
  3. data/app/views/magic_addresses/addresses/_address_fields.html.erb +1 -1
  4. data/app/views/magic_addresses/addresses/_addresses_fields.html.erb +1 -1
  5. data/lib/app/models/magic_addresses/address.rb +116 -41
  6. data/lib/app/models/magic_addresses/addressible.rb +21 -0
  7. data/lib/app/models/magic_addresses/association.rb +51 -15
  8. data/lib/app/models/magic_addresses/owner_proxy.rb +14 -0
  9. data/lib/generators/magic_addresses/add_earthdistance_generator.rb +25 -0
  10. data/lib/generators/magic_addresses/templates/earthdistance_migration.rb +32 -0
  11. data/lib/generators/magic_addresses/templates/geocoder_initializer.rb +4 -2
  12. data/lib/generators/magic_addresses/templates/magic_addresses_migration.rb +5 -0
  13. data/lib/generators/magic_addresses/templates/magic_initializer.rb +15 -9
  14. data/lib/generators/magic_addresses/templates/update_address_migration.rb +45 -0
  15. data/lib/generators/magic_addresses/update_generator.rb +25 -0
  16. data/lib/magic_addresses/configuration.rb +18 -6
  17. data/lib/magic_addresses/version.rb +1 -1
  18. data/lib/magic_addresses.rb +6 -0
  19. data/spec/dummy/app/models/company.rb +5 -0
  20. data/spec/dummy/app/views/users/index.html.erb +2 -2
  21. data/spec/dummy/config/environments/test.rb +5 -0
  22. data/spec/dummy/config/initializers/magic_addresses.rb +11 -3
  23. data/spec/dummy/db/development.sqlite3 +0 -0
  24. data/spec/dummy/db/migrate/20151111133333_create_companies.rb +10 -0
  25. data/spec/dummy/db/migrate/20151118102658_update_magic_addresses.rb +45 -0
  26. data/spec/dummy/db/schema.rb +23 -7
  27. data/spec/dummy/db/test.sqlite3 +0 -0
  28. data/spec/dummy/log/development.log +18969 -70324
  29. data/spec/dummy/log/test.log +42010 -94562
  30. data/spec/dummy/tmp/pids/server.pid +1 -0
  31. data/spec/models/company_spec.rb +17 -0
  32. data/spec/models/magic_addresses/address_spec.rb +52 -27
  33. data/spec/models/user_spec.rb +23 -0
  34. data/spec/rails_helper.rb +3 -0
  35. metadata +35 -399
  36. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_aside_nav.scssc +0 -0
  37. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_banner.scssc +0 -0
  38. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_box.scssc +0 -0
  39. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_buttons.scssc +0 -0
  40. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_buttons_nice.scssc +0 -0
  41. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_forms.scssc +0 -0
  42. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_helper.scssc +0 -0
  43. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_icons.scssc +0 -0
  44. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_inputs.scssc +0 -0
  45. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_labels.scssc +0 -0
  46. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_navbar.scssc +0 -0
  47. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_notice.scssc +0 -0
  48. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_panel.scssc +0 -0
  49. data/spec/dummy/tmp/cache/assets/development/sass/19b60152c4654e1688273867e38ff5e0b6236ab2/_pix.scssc +0 -0
  50. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_alerts.scssc +0 -0
  51. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_background-variant.scssc +0 -0
  52. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_border-radius.scssc +0 -0
  53. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_buttons.scssc +0 -0
  54. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_center-block.scssc +0 -0
  55. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_clearfix.scssc +0 -0
  56. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_forms.scssc +0 -0
  57. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_gradients.scssc +0 -0
  58. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_grid-framework.scssc +0 -0
  59. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_grid.scssc +0 -0
  60. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_hide-text.scssc +0 -0
  61. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_image.scssc +0 -0
  62. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_labels.scssc +0 -0
  63. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_list-group.scssc +0 -0
  64. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_nav-divider.scssc +0 -0
  65. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_nav-vertical-align.scssc +0 -0
  66. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_opacity.scssc +0 -0
  67. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_pagination.scssc +0 -0
  68. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_panels.scssc +0 -0
  69. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_progress-bar.scssc +0 -0
  70. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_reset-filter.scssc +0 -0
  71. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_resize.scssc +0 -0
  72. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_responsive-visibility.scssc +0 -0
  73. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_size.scssc +0 -0
  74. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_tab-focus.scssc +0 -0
  75. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_table-row.scssc +0 -0
  76. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_text-emphasis.scssc +0 -0
  77. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_text-overflow.scssc +0 -0
  78. data/spec/dummy/tmp/cache/assets/development/sass/24c51698ad01336e4b987229e799c2cc59a52365/_vendor-prefixes.scssc +0 -0
  79. data/spec/dummy/tmp/cache/assets/development/sass/2557903008e29020a1e41f44af8141d40a1e1147/_corset.scssc +0 -0
  80. data/spec/dummy/tmp/cache/assets/development/sass/2557903008e29020a1e41f44af8141d40a1e1147/_fullpage_table.scssc +0 -0
  81. data/spec/dummy/tmp/cache/assets/development/sass/2557903008e29020a1e41f44af8141d40a1e1147/_section.scssc +0 -0
  82. data/spec/dummy/tmp/cache/assets/development/sass/4a366ea161250132a268ef32a1b08cac8de6b5ae/_asset-pipeline.scssc +0 -0
  83. data/spec/dummy/tmp/cache/assets/development/sass/4a366ea161250132a268ef32a1b08cac8de6b5ae/_prefixer.scssc +0 -0
  84. data/spec/dummy/tmp/cache/assets/development/sass/4a366ea161250132a268ef32a1b08cac8de6b5ae/_px-to-em.scssc +0 -0
  85. data/spec/dummy/tmp/cache/assets/development/sass/51b770beda224b19a22a5fcca280d5fcfa460146/_colors.scssc +0 -0
  86. data/spec/dummy/tmp/cache/assets/development/sass/51b770beda224b19a22a5fcca280d5fcfa460146/_fonts.scssc +0 -0
  87. data/spec/dummy/tmp/cache/assets/development/sass/51b770beda224b19a22a5fcca280d5fcfa460146/_variables.scssc +0 -0
  88. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_animation.scssc +0 -0
  89. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_appearance.scssc +0 -0
  90. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_backface-visibility.scssc +0 -0
  91. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_background-image.scssc +0 -0
  92. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_background.scssc +0 -0
  93. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_border-image.scssc +0 -0
  94. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_border-radius.scssc +0 -0
  95. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_box-sizing.scssc +0 -0
  96. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_calc.scssc +0 -0
  97. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_columns.scssc +0 -0
  98. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_filter.scssc +0 -0
  99. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_flex-box.scssc +0 -0
  100. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_font-face.scssc +0 -0
  101. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_font-feature-settings.scssc +0 -0
  102. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_hidpi-media-query.scssc +0 -0
  103. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_hyphens.scssc +0 -0
  104. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_image-rendering.scssc +0 -0
  105. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_keyframes.scssc +0 -0
  106. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_linear-gradient.scssc +0 -0
  107. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_perspective.scssc +0 -0
  108. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_placeholder.scssc +0 -0
  109. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_radial-gradient.scssc +0 -0
  110. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_selection.scssc +0 -0
  111. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_text-decoration.scssc +0 -0
  112. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_transform.scssc +0 -0
  113. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_transition.scssc +0 -0
  114. data/spec/dummy/tmp/cache/assets/development/sass/54164dda167544c9a2234eb3643bf0895da180fd/_user-select.scssc +0 -0
  115. data/spec/dummy/tmp/cache/assets/development/sass/5dac14e9bcf503fc8fa7c4f4440118fabc865d43/autocomplete.cssc +0 -0
  116. data/spec/dummy/tmp/cache/assets/development/sass/65afb1d40636d95636e95a91bc4e33776a5f48ba/magic-stylez.scssc +0 -0
  117. data/spec/dummy/tmp/cache/assets/development/sass/67eeb42d1b5d8b7a99a388bcbdece61f954c9cb0/icomoon.scssc +0 -0
  118. data/spec/dummy/tmp/cache/assets/development/sass/67eeb42d1b5d8b7a99a388bcbdece61f954c9cb0/magicons.scssc +0 -0
  119. data/spec/dummy/tmp/cache/assets/development/sass/67eeb42d1b5d8b7a99a388bcbdece61f954c9cb0/orderlifticons.scssc +0 -0
  120. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_assign.scssc +0 -0
  121. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_color-lightness.scssc +0 -0
  122. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_contains.scssc +0 -0
  123. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_is-length.scssc +0 -0
  124. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_is-size.scssc +0 -0
  125. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_modular-scale.scssc +0 -0
  126. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_px-to-em.scssc +0 -0
  127. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_px-to-rem.scssc +0 -0
  128. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_strip-units.scssc +0 -0
  129. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_tint-shade.scssc +0 -0
  130. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_transition-property-name.scssc +0 -0
  131. data/spec/dummy/tmp/cache/assets/development/sass/6b16abfb17fe2503733e43257f3ae1774c687e5f/_unpack.scssc +0 -0
  132. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_convert-units.scssc +0 -0
  133. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_font-source-declaration.scssc +0 -0
  134. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_gradient-positions-parser.scssc +0 -0
  135. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_is-num.scssc +0 -0
  136. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_linear-angle-parser.scssc +0 -0
  137. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_linear-gradient-parser.scssc +0 -0
  138. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_linear-positions-parser.scssc +0 -0
  139. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_linear-side-corner-parser.scssc +0 -0
  140. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_radial-arg-parser.scssc +0 -0
  141. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_radial-gradient-parser.scssc +0 -0
  142. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_radial-positions-parser.scssc +0 -0
  143. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_render-gradients.scssc +0 -0
  144. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_shape-size-stripper.scssc +0 -0
  145. data/spec/dummy/tmp/cache/assets/development/sass/75433b62dd2cb96bb75c34d9a3e28f92ab357b7f/_str-to-num.scssc +0 -0
  146. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_alerts.scssc +0 -0
  147. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_badges.scssc +0 -0
  148. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_breadcrumbs.scssc +0 -0
  149. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_button-groups.scssc +0 -0
  150. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_buttons.scssc +0 -0
  151. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_carousel.scssc +0 -0
  152. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_close.scssc +0 -0
  153. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_code.scssc +0 -0
  154. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_component-animations.scssc +0 -0
  155. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_dropdowns.scssc +0 -0
  156. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_forms.scssc +0 -0
  157. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_glyphicons.scssc +0 -0
  158. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_grid.scssc +0 -0
  159. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_input-groups.scssc +0 -0
  160. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_jumbotron.scssc +0 -0
  161. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_labels.scssc +0 -0
  162. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_list-group.scssc +0 -0
  163. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_media.scssc +0 -0
  164. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_mixins.scssc +0 -0
  165. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_modals.scssc +0 -0
  166. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_navbar.scssc +0 -0
  167. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_navs.scssc +0 -0
  168. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_normalize.scssc +0 -0
  169. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_pager.scssc +0 -0
  170. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_pagination.scssc +0 -0
  171. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_panels.scssc +0 -0
  172. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_popovers.scssc +0 -0
  173. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_print.scssc +0 -0
  174. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_progress-bars.scssc +0 -0
  175. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_responsive-embed.scssc +0 -0
  176. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_responsive-utilities.scssc +0 -0
  177. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_scaffolding.scssc +0 -0
  178. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_tables.scssc +0 -0
  179. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_thumbnails.scssc +0 -0
  180. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_tooltip.scssc +0 -0
  181. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_type.scssc +0 -0
  182. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_utilities.scssc +0 -0
  183. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_variables.scssc +0 -0
  184. data/spec/dummy/tmp/cache/assets/development/sass/92cf243fa656f5697aab51e7d90e01c1822b2659/_wells.scssc +0 -0
  185. data/spec/dummy/tmp/cache/assets/development/sass/ba4757a1a53e47b8d77e8b3e570956e2688fcda4/_bourbon-deprecated-upcoming.scssc +0 -0
  186. data/spec/dummy/tmp/cache/assets/development/sass/ba4757a1a53e47b8d77e8b3e570956e2688fcda4/_bourbon.scssc +0 -0
  187. data/spec/dummy/tmp/cache/assets/development/sass/bbf3f90fe22893a2ce61a9eb12fae3a9f2defd14/_animation.scssc +0 -0
  188. data/spec/dummy/tmp/cache/assets/development/sass/bbf3f90fe22893a2ce61a9eb12fae3a9f2defd14/_cross_browser.scssc +0 -0
  189. data/spec/dummy/tmp/cache/assets/development/sass/bbf3f90fe22893a2ce61a9eb12fae3a9f2defd14/_filter.scssc +0 -0
  190. data/spec/dummy/tmp/cache/assets/development/sass/bbf3f90fe22893a2ce61a9eb12fae3a9f2defd14/_forms.scssc +0 -0
  191. data/spec/dummy/tmp/cache/assets/development/sass/bbf3f90fe22893a2ce61a9eb12fae3a9f2defd14/_helper.scssc +0 -0
  192. data/spec/dummy/tmp/cache/assets/development/sass/bbf3f90fe22893a2ce61a9eb12fae3a9f2defd14/_media_querries.scssc +0 -0
  193. data/spec/dummy/tmp/cache/assets/development/sass/bbf3f90fe22893a2ce61a9eb12fae3a9f2defd14/_text.scssc +0 -0
  194. data/spec/dummy/tmp/cache/assets/development/sass/bbf3f90fe22893a2ce61a9eb12fae3a9f2defd14/_twbs.scssc +0 -0
  195. data/spec/dummy/tmp/cache/assets/development/sass/d11e29c08f9a4c5de5e232de8e0405a1753a5793/application.css.scssc +0 -0
  196. data/spec/dummy/tmp/cache/assets/development/sass/d6dffb77922b7d3b25f0a1059d1311e3279ff693/_circle_diagram.scssc +0 -0
  197. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_clearfix.scssc +0 -0
  198. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_directional-values.scssc +0 -0
  199. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_ellipsis.scssc +0 -0
  200. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_font-family.scssc +0 -0
  201. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_hide-text.scssc +0 -0
  202. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_html5-input-types.scssc +0 -0
  203. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_position.scssc +0 -0
  204. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_prefixer.scssc +0 -0
  205. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_retina-image.scssc +0 -0
  206. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_size.scssc +0 -0
  207. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_timing-functions.scssc +0 -0
  208. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_triangle.scssc +0 -392
  209. data/spec/dummy/tmp/cache/assets/development/sass/de5c39bfb8e330e076983d775f6d2e28dbe78636/_word-wrap.scssc +0 -42
  210. data/spec/dummy/tmp/cache/assets/development/sass/e0bbbca13012c1d2a33d6ed35ab7224d7120f071/_all.scssc +0 -0
  211. data/spec/dummy/tmp/cache/assets/development/sass/e0bbbca13012c1d2a33d6ed35ab7224d7120f071/_arrow_hints.scssc +0 -0
  212. data/spec/dummy/tmp/cache/assets/development/sass/e0bbbca13012c1d2a33d6ed35ab7224d7120f071/_crossed.scssc +0 -0
  213. data/spec/dummy/tmp/cache/assets/development/sass/e0bbbca13012c1d2a33d6ed35ab7224d7120f071/_divider.scssc +0 -0
  214. data/spec/dummy/tmp/cache/assets/development/sass/e0bbbca13012c1d2a33d6ed35ab7224d7120f071/_dots.scssc +0 -0
  215. data/spec/dummy/tmp/cache/assets/development/sass/e0bbbca13012c1d2a33d6ed35ab7224d7120f071/_text.scssc +0 -0
  216. data/spec/dummy/tmp/cache/assets/development/sass/e0bbbca13012c1d2a33d6ed35ab7224d7120f071/_three_previews.scssc +0 -0
  217. data/spec/dummy/tmp/cache/assets/development/sass/e68899ee835edcf02d7ab60e48d61fa544850864/_nav.scssc +0 -0
  218. data/spec/dummy/tmp/cache/assets/development/sass/ec54c41325c4a582d617d517b74a3bd29b054c6a/_reflections.scssc +0 -0
  219. data/spec/dummy/tmp/cache/assets/development/sass/ec54c41325c4a582d617d517b74a3bd29b054c6a/_shadows.scssc +0 -0
  220. data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  221. data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  222. data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  223. data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  224. data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  225. data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTE5ZTVlZjI1ZmUyODQ0YWE0Zjg0Y2ZjYjhiNTZlNjhhZGRkNmFhNA==
5
- data.tar.gz: !binary |-
6
- OTkzYTVhZmQyZmJiZjJjYjdlMmE5MzVlZWVlODBhNmVjZGM3MTU3MQ==
2
+ SHA1:
3
+ metadata.gz: 04b5e9909e1b2e874ca012a22f9ec278cb2a6c4f
4
+ data.tar.gz: dfa7e10310297100ff901bf1abf04dacce29eeee
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MjQ3Nzg0NzRkYWNmM2ExMzQwMDBhMjVjZDM0YjM0NWU3NTY4MzhhMWE3Yjk1
10
- NjE2NmExNjg3NWRjOWZmOWRjMTEwNTIzYjEyMDAzNzk5MzcwOWVlOGQ5OTdi
11
- NGNlNTEzN2NlMGE0NTkxMzMwZGQzOWI5ZTk5OThiYjY3ZDk4NWE=
12
- data.tar.gz: !binary |-
13
- ZmM2ZDY1N2Q0ZjUyNGRiYzMwYTA1MTMzYzczNjA1YjhhNjI4MjRlOWI3MjIy
14
- YWU5Y2MyNDJhMzQyNzEzYTE2ZmUzNTRiYjFmMzkzOGI0OTUyYWVkZTQzN2Vm
15
- ODVlNGYwZTkwNjZkZjg0NzVhNzIyMWIxYTJjMTRhMzc0NGFkNmY=
6
+ metadata.gz: 0d3f5fb35f5dab3de3f50699581e82c117bc591dd5a14f63fa2f1e23115593146a11d374b8c270721801d3112fb31d3ebddd5a974ab1b4b620ee49af8cb4e4a1
7
+ data.tar.gz: 3e73a954d8c9e3bd148ba8cb876c0ade5a35f5764f2c75c88bad454120b2c3efe65d04f92d20edf42c0d71c79de4394ba17f08974989d997b3b268d5915916e8
data/README.md CHANGED
@@ -15,7 +15,38 @@ rails g magic_addresses:install
15
15
  - 4. **add to your models**
16
16
 
17
17
 
18
- #### Model methods
18
+ ## Features
19
+
20
+ - full tranlated addresses
21
+ - allways correct addresses (query to google/verbatim service)
22
+ - addresses, cities, countries, and so one, are uniq (i.e. only one "New-York" with lots of addresses, districts, ..)
23
+ - perfect order ( city has X addresses )
24
+ - postgresql earthdistance included (for distance checks)
25
+ - tested
26
+
27
+
28
+
29
+
30
+ ## New
31
+ since version `0.0.13` addresses are uniq, so the same address never will be saved twice, instead owners share one address
32
+
33
+ run:
34
+ ```ruby
35
+ rails g magic_addresses:update
36
+ ```
37
+ to update old addresses and add the new structure
38
+
39
+
40
+ ##### You can add Earthdistance plugin later!
41
+ run:
42
+ ```ruby
43
+ rails g magic_addresses:add_earthdistance
44
+ ```
45
+ be sure to activate it in initializer before migrate!
46
+
47
+
48
+
49
+ ### Model methods
19
50
 
20
51
  ```ruby
21
52
  has_one_address # => This model has one address associated with it. (ie: User)
@@ -29,7 +60,7 @@ rails g magic_addresses:install
29
60
 
30
61
  ```
31
62
 
32
- #### View Mehtods
63
+ ### View Mehtods
33
64
 
34
65
  ```ruby
35
66
 
@@ -41,7 +72,7 @@ rails g magic_addresses:install
41
72
 
42
73
  ```
43
74
 
44
- #### in your Controllers:
75
+ ### in your Controllers:
45
76
 
46
77
  ```ruby
47
78
 
@@ -66,6 +97,29 @@ rails g magic_addresses:install
66
97
  ```
67
98
 
68
99
 
100
+ ## Configuration
101
+ ```ruby
102
+
103
+ MagicAddresses.configure do |config|
104
+ # in which locales addresses should be saved
105
+ config.active_locales = [:en, :de]
106
+ # what is the default language (should be :en, except you don't need english at all)
107
+ config.default_locale = :en
108
+ # what is the default country for query
109
+ config.default_country = "Germany"
110
+ # add default country in each query ?
111
+ config.query_defaults = true
112
+ # only save tranlations when differs from default-locale?
113
+ config.uniq_translations = true
114
+ # use a background-process for the lookups ( :none | :sidekiq )
115
+ config.job_backend = :none
116
+ # use a postgres earthdistance for distance calculation
117
+ config.earthdistance = false
118
+ end
119
+
120
+ ```
121
+
122
+
69
123
 
70
124
  #### Structure
71
125
 
@@ -105,7 +159,7 @@ Address:
105
159
  ```
106
160
 
107
161
 
108
- .. will more info, sometimes ...
162
+ .. will add more info, sometimes ...
109
163
 
110
164
 
111
165
  This project rocks and uses MIT-LICENSE.
@@ -3,7 +3,7 @@
3
3
  <% idkey = "locations_attributes_#{rand(999999)}_" %>
4
4
  <div class="map_form">
5
5
 
6
- <input type="text" id="<%= idkey %>map_data" class="mgca_map_data <%= style %>" placeholder="<%= placeholder %>" value="<%= f.object.presentation %>" />
6
+ <input type="text" id="<%= idkey %>map_data" class="mgca_map_data <%= style %>" placeholder="<%= placeholder %>" value="<%= f.object ? f.object.presentation : "" %>" autocomplete="false" role="presentation" />
7
7
 
8
8
  <div class="hidden_mgca_form">
9
9
  <div class="row">
@@ -8,7 +8,7 @@
8
8
  </div>
9
9
 
10
10
  <div class="fields">
11
- <input type="text" id="<%= idkey %>map_data" class="mgca_short_data <%= style %>" placeholder="<%= placeholder %>" value="<%= f.object.presentation %>"/>
11
+ <input type="text" id="<%= idkey %>map_data" class="mgca_short_data <%= style %>" placeholder="<%= placeholder %>" value="<%= f.object ? f.object.presentation : "" %>" autocomplete="false" role="presentation" />
12
12
  <%= f.hidden_field :street, class: "mgca_txt street", id: "#{idkey}street" %>
13
13
  <%= f.hidden_field :street_number, class: "mgca_txt street_number", id: "#{idkey}street_number" %>
14
14
  <%= f.hidden_field :latitude, id: "#{idkey}latitude", class: "mgca_latitude" %>
@@ -10,7 +10,14 @@ class MagicAddresses::Address < ActiveRecord::Base
10
10
 
11
11
 
12
12
  # =====> A S S O Z I A T I O N S <========================================================= #
13
- belongs_to :owner, polymorphic: true
13
+ has_many :addressibles, class_name: "MagicAddresses::Addressible", foreign_key: :address_id
14
+
15
+
16
+ ## add associations (set in configuration)
17
+ MagicAddresses.configuration.address_owners.each do |key,type|
18
+ has_many key.to_sym, through: :addressibles, source: :owner, source_type: type
19
+ end
20
+
14
21
 
15
22
  belongs_to :magic_country, class_name: "MagicAddresses::Country", foreign_key: :country_id
16
23
  belongs_to :magic_state, class_name: "MagicAddresses::State", foreign_key: :state_id
@@ -23,13 +30,14 @@ class MagicAddresses::Address < ActiveRecord::Base
23
30
  # address.street_name # => street in I18n.locale
24
31
  # address.read_attribute(:street_name, locale: :de) # => street in german (:de), no fallback
25
32
  #
26
- # translates :street_name, fallbacks_for_empty_translations: true #, table_name: "mgca_addresses"
27
33
  mgca_translate :street_name
28
34
 
29
35
  acts_as_geolocated lat: 'latitude', lng: 'longitude' if MagicAddresses.configuration.earthdistance
30
36
 
31
37
 
32
38
  # =====> A T T R I B U T E S <============================================================= #
39
+ # accepts_nested_attributes_for :translations
40
+
33
41
  serialize :fetch_address, Hash
34
42
 
35
43
  %w[fetch_street fetch_number fetch_city fetch_zipcode fetch_country fetch_country_code].each do |key|
@@ -81,16 +89,16 @@ class MagicAddresses::Address < ActiveRecord::Base
81
89
  self.fetch_address = (fetch_address || {}).merge("fetch_country_code" => value)
82
90
  end
83
91
 
92
+ def owner=(this)
93
+ self.addressibles.where( owner_type: this.class.to_s, owner_id: this.id ).first_or_create!
94
+ end
84
95
 
85
- # accepts_nested_attributes_for :translations
86
-
87
-
88
- # =====> V A L I D A T I O N <============================================================= #
89
- # => validates :owner, :presence => true
90
96
 
91
97
 
92
98
  # =====> C A L L B A C K S <=============================================================== #
93
- after_save :build_address_associations_if_needed
99
+ ## now in addressible or doesnt work nested ..
100
+ # => after_save :build_address_associations_if_needed
101
+ # => after_create :build_address_associations_if_needed
94
102
 
95
103
  # =====> S C O P E S <===================================================================== #
96
104
 
@@ -114,11 +122,25 @@ class MagicAddresses::Address < ActiveRecord::Base
114
122
  end
115
123
  end
116
124
 
125
+ def owners
126
+ addressibles.map { |that| ::MagicAddresses::OwnerProxy.new( that ) }
127
+ end
128
+
129
+ def trigger_build_address_associations
130
+ build_address_associations()
131
+ end
132
+
133
+ def trigger_complete_translated_attributes
134
+ complete_translated_attributes()
135
+ end
136
+
137
+
117
138
  # =====> P R I V A T E ! <======================================================== # # # # # # # #
118
139
  private
119
140
 
120
141
  def build_address_associations_if_needed
121
- if self.new_record? || self.fetch_street.present? || self.fetch_city.present? || self.fetch_zipcode.present? || self.fetch_number.present?
142
+ #if self.new_record? || self.fetch_street.present? || self.fetch_city.present? || self.fetch_zipcode.present? || self.fetch_number.present?
143
+ if self.new_record? || !["fetched", "translated"].include?( self.status )
122
144
  build_address_associations
123
145
  else
124
146
  true
@@ -128,52 +150,94 @@ private
128
150
  def build_address_associations
129
151
  dev_log "triggered A D D R E S S - B U I L D E R ! - - #{self.street} #{self.number} #{self.city} #{self.zipcode}"
130
152
 
131
- addr = []
132
153
  if self.fetch_city.present? || self.fetch_zipcode.present?
154
+ self.fetch_address["addr"] = []
133
155
  # MagicAddresses::GeoCoder
134
- addr << "#{self.fetch_street} #{self.fetch_number}".strip if self.fetch_street
135
- addr << "#{self.fetch_zipcode} #{self.fetch_city}".strip if self.fetch_city || self.fetch_zipcode
136
- addr << "#{self.fetch_country || self.fetch_country_code || MagicAddresses.configuration.default_country}".strip
156
+ self.fetch_address["addr"] << "#{self.fetch_street} #{self.fetch_number}".strip if self.fetch_street
157
+ self.fetch_address["addr"] << "#{self.fetch_zipcode} #{self.fetch_city}".strip if self.fetch_city || self.fetch_zipcode
158
+ if MagicAddresses.configuration.query_defaults
159
+ self.fetch_address["addr"] << "#{self.fetch_country || self.fetch_country_code || MagicAddresses.configuration.default_country}".strip
160
+ else
161
+ self.fetch_address["addr"] << "#{self.fetch_country || self.fetch_country_code}".strip if self.fetch_country || self.fetch_country
162
+ end
137
163
  end
138
164
 
139
- self.fetch_address = {}
140
165
 
141
- geo_data = {}
142
- if addr.any?
143
- # => gd = Geocoder.search( self.fetch_address, params: { language: "en" })
144
- gd = MagicAddresses::GeoCoder.search( addr.join(", "), default_locale )
145
- geo_data[default_locale] = gd.first if gd.first
146
- MagicAddresses.configuration.active_locales.each do |lcl|
147
- unless lcl.to_s == default_locale
148
- sleep 0.3
149
- gd = MagicAddresses::GeoCoder.search( addr.join(", "), lcl.to_s )
150
- geo_data[lcl.to_s] = gd.first if gd.first
166
+ if self.fetch_address["addr"] && self.fetch_address["addr"].any?
167
+ self.fetch_address["geo_data"] = {}
168
+ gd = MagicAddresses::GeoCoder.search(self.fetch_address["addr"].join(", "), default_locale)
169
+ self.fetch_address["geo_data"][default_locale] = gd.first if gd.first
170
+ self.fetch_address["fetched"] = true
171
+ self.status = "fetched"
172
+ end
173
+
174
+
175
+ if self.fetch_address["geo_data"] && self.fetch_address["geo_data"].any?
176
+ geo_data = self.fetch_address["geo_data"][default_locale]
177
+ sames = MagicAddresses::Address.where( latitude: geo_data.latitude,
178
+ longitude: geo_data.longitude,
179
+ zipcode: geo_data.postal_code,
180
+ street_number: geo_data.street_number )
181
+ dev_log "Address.count: #{ MagicAddresses::Address.all.count } .. . .. SAMES.count: #{ sames.count }"
182
+ if sames.any? && sames.first != self
183
+ dev_log " found similar address .. will use that !!!"
184
+ dev_log "addressibles #{self.addressibles.count}"
185
+ that = sames.first
186
+ dev_log "owners - #{self.owners.inspect}"
187
+ self.addressibles.each do |x|
188
+ dev_log "kill - #{x.address_id}"
189
+ x.address_id = that.id
190
+ x.save
191
+ # x.owner.touch
192
+ dev_log "kill - #{x.address_id}"
193
+ end
194
+ self.destroy
195
+ else
196
+ dev_log " geo_data is present !!!"
197
+ self.street_default = geo_data.street if geo_data && geo_data.street
198
+ self.zipcode = geo_data.postal_code if geo_data && geo_data.postal_code
199
+ self.street_number = geo_data.street_number if geo_data && geo_data.street_number
200
+ # set geo-position
201
+ self.latitude = geo_data.latitude if geo_data && geo_data.latitude
202
+ self.longitude = geo_data.longitude if geo_data && geo_data.longitude
203
+ # translate other languages
204
+
205
+ if MagicAddresses.configuration.job_backend == :sidekiq
206
+ AddressWorker.perform_async( self.id )
207
+ else
208
+ complete_translated_attributes()
151
209
  end
210
+
211
+ self.save
152
212
  end
213
+
153
214
  end
154
- if geo_data.any?
155
- dev_log " geo_data is present !!!"
156
- # set default values
157
- self.street_default = geo_data[default_locale].street if geo_data[default_locale] && geo_data[default_locale].street
158
- self.zipcode = geo_data[default_locale].postal_code if geo_data[default_locale] && geo_data[default_locale].postal_code
159
- self.street_number = geo_data[default_locale].street_number if geo_data[default_locale] && geo_data[default_locale].street_number
160
- # set geo-position
161
- self.latitude = geo_data[default_locale].latitude if geo_data[default_locale] && geo_data[default_locale].latitude
162
- self.longitude = geo_data[default_locale].longitude if geo_data[default_locale] && geo_data[default_locale].longitude
163
- end
164
- complete_translated_attributes( geo_data )
165
215
 
166
- self.fetch_address = {}
167
- self.save
168
216
  end
169
217
 
170
218
 
171
- def complete_translated_attributes( geo_data = {} )
219
+ def complete_translated_attributes
220
+
221
+ MagicAddresses.configuration.active_locales.each do |lcl|
222
+ unless lcl.to_s == default_locale
223
+ sleep 0.3
224
+ gd = MagicAddresses::GeoCoder.search( self.fetch_address["addr"].join(", "), lcl.to_s )
225
+ self.fetch_address["geo_data"][lcl.to_s] = gd.first if gd.first
226
+ end
227
+ end
228
+
229
+ geo_data = self.fetch_address["geo_data"]
230
+
172
231
  if geo_data.any?
173
232
  # build street parameters
174
233
  street_params = []
175
234
  geo_data.each do |key, stuff|
176
- street_params << { locale: key.to_s, street_name: stuff.street } if stuff.street # && ((stuff.street != geo_data[default_locale].street) || (default_locale == key.to_s))
235
+ if MagicAddresses.configuration.uniq_translations
236
+ # => only save locale if different from default-locale:
237
+ street_params << { locale: key.to_s, street_name: stuff.street } if stuff.street && ((stuff.street != geo_data[default_locale].street) || (default_locale == key.to_s))
238
+ else
239
+ street_params << { locale: key.to_s, street_name: stuff.street } if stuff.street
240
+ end
177
241
  end
178
242
  # set street parameters if present
179
243
  if street_params.any?
@@ -209,6 +273,10 @@ private
209
273
  connet_address_association( :subdistrict, geo_data )
210
274
  end
211
275
 
276
+ self.fetch_address = {}
277
+ self.status = "translated"
278
+ self.save
279
+
212
280
  end
213
281
  end
214
282
 
@@ -229,7 +297,8 @@ private
229
297
 
230
298
  dev_log "#{that} .. #{this}"
231
299
 
232
- self.send(this).translations = []
300
+ # self.send(this).translations = []
301
+ self.send(this).translations.delete_all
233
302
  self.send(this).translations_attributes = lng_params( that, geo_data )
234
303
  self.send(this).save
235
304
  end
@@ -240,7 +309,13 @@ private
240
309
  lng_params = []
241
310
  geo_data.each do |key, stuff|
242
311
  dev_log "#{that.to_s.titleize}-Params (#{key}) ... #{stuff.send(that)}"
243
- lng_params << { locale: key.to_s, name: stuff.send(that) } if stuff.send(that) # && ((stuff.send(that) != geo_data[default_locale].send(that)) || (key.to_s == default_locale))
312
+
313
+ if MagicAddresses.configuration.uniq_translations
314
+ # => only save locale if different from default-locale:
315
+ lng_params << { locale: key.to_s, name: stuff.send(that) } if stuff.send(that) && ((stuff.send(that) != geo_data[default_locale].send(that)) || (key.to_s == default_locale))
316
+ else
317
+ lng_params << { locale: key.to_s, name: stuff.send(that) } if stuff.send(that)
318
+ end
244
319
  end
245
320
  lng_params
246
321
  end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ class MagicAddresses::Addressible < ActiveRecord::Base
3
+
4
+ belongs_to :owner, polymorphic: true
5
+ belongs_to :address, class_name: "MagicAddresses::Address", foreign_key: :address_id
6
+
7
+ after_create :log_some_stuff
8
+
9
+ private
10
+
11
+ def log_some_stuff
12
+ Rails.logger.info "==="
13
+ Rails.logger.info "=== #{self.inspect}"
14
+ Rails.logger.info "==="
15
+ self.address ? self.address.trigger_build_address_associations : true
16
+ Rails.logger.info "==="
17
+ Rails.logger.info "=== #{self.inspect}"
18
+ Rails.logger.info "==="
19
+ end
20
+
21
+ end
@@ -11,31 +11,58 @@ module MagicAddresses
11
11
 
12
12
 
13
13
  def has_addresses
14
- has_many :addresses,
14
+ # has_many :addresses,
15
+ # as: :owner,
16
+ # class_name: "MagicAddresses::Address",
17
+ # dependent: :destroy
18
+
19
+ has_many :addressibles,
15
20
  as: :owner,
16
- class_name: "MagicAddresses::Address",
21
+ class_name: "MagicAddresses::Addressible",
17
22
  dependent: :destroy
23
+
24
+ has_many :addresses,
25
+ through: :addressibles,
26
+ source: :address
27
+
18
28
  accepts_nested_attributes_for :addresses, allow_destroy: true, reject_if: :all_blank
19
29
  end
20
30
 
21
31
 
22
32
  def has_one_address
23
- has_one :address, -> { where(default: true) },
24
- as: :owner,
25
- class_name: "MagicAddresses::Address",
26
- autosave: true,
33
+ send :include, OneInstanceMethods
34
+ # has_one :address, -> { where(default: true) },
35
+ # as: :owner,
36
+ # class_name: "MagicAddresses::Address",
37
+ # autosave: true,
38
+ # dependent: :destroy
39
+
40
+ has_one :addressible,
41
+ -> { where(default: true) },
42
+ as: :owner,
43
+ class_name: "MagicAddresses::Addressible",
27
44
  dependent: :destroy
28
- accepts_nested_attributes_for :address, allow_destroy: true, reject_if: :all_blank
45
+
46
+ has_one :address,
47
+ through: :addressible,
48
+ source: :address
49
+
50
+ accepts_nested_attributes_for :addressible, :address, allow_destroy: true, reject_if: :all_blank
29
51
  end
30
52
 
31
53
 
32
54
  def has_nested_address
33
- send :include, InstanceMethods
34
- has_one :address,
35
- as: :owner,
36
- class_name: "MagicAddresses::Address",
37
- autosave: true,
38
- dependent: :destroy
55
+ send :include, NestedInstanceMethods
56
+ # has_one :address,
57
+ # as: :owner,
58
+ # class_name: "MagicAddresses::Address",
59
+ # autosave: true,
60
+ # dependent: :destroy
61
+
62
+ has_one :addressible, -> { where(default: true) },
63
+ as: :owner, class_name: "MagicAddresses::Addressible", dependent: :destroy
64
+ has_one :address, through: :addressibles, source: :address
65
+
39
66
  delegate :street, :number, :postalcode, :city, :district, :subdistrict, :state, :country,
40
67
  :street=, :number=, :postalcode=, :city=, :country=,
41
68
  to: :address, allow_nil: true
@@ -46,8 +73,17 @@ module MagicAddresses
46
73
 
47
74
  end #> ClassMethods
48
75
 
49
- ## I N S T A N C E - M E T H O D S # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
50
- module InstanceMethods
76
+ ## I N S T A N C E - M E T H O D S # # # # # # # # # # # # # # # # # # # # # # #
77
+ module OneInstanceMethods
78
+
79
+ # => http://stackoverflow.com/a/6989403/1470996
80
+ def build_address(params)
81
+ self.address = MagicAddresses::Address.new(params)
82
+ end
83
+
84
+ end #> InstanceMethods
85
+
86
+ module NestedInstanceMethods
51
87
 
52
88
  # http://stackoverflow.com/a/4033761
53
89
  def address_with_build
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ class MagicAddresses::OwnerProxy
3
+
4
+ attr_accessor :this, :addressible_id, :owner_id, :owner_type, :name
5
+
6
+ def initialize( addressible )
7
+ self.this = addressible.owner
8
+ self.addressible_id = addressible.id
9
+ self.owner_id = addressible.owner_id
10
+ self.owner_type = addressible.owner_type
11
+ self.name = addressible.owner && addressible.owner.respond_to?(:name) ? addressible.owner.name : nil
12
+ end
13
+
14
+ end
@@ -0,0 +1,25 @@
1
+ require 'rails/generators/migration'
2
+
3
+ module MagicAddresses
4
+ module Generators
5
+ class AddEarthdistanceGenerator < ::Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ desc "add magic_addresses earthdistance migrations"
9
+
10
+ def self.next_migration_number(path)
11
+ unless @prev_migration_nr
12
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
13
+ else
14
+ @prev_migration_nr += 1
15
+ end
16
+ @prev_migration_nr.to_s
17
+ end
18
+
19
+ def copy_migrations
20
+ migration_template( "earthdistance_migration.rb", "db/migrate/add_earthdistance.rb" )
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ class AddEarthdistance < ActiveRecord::Migration
2
+ def self.up
3
+
4
+ # comented out to avoid PG::InsufficientPrivilege-ERROR
5
+ # add with cap postgresql:add_extensions
6
+ # => execute "CREATE EXTENSION IF NOT EXISTS cube"
7
+ # => execute "CREATE EXTENSION IF NOT EXISTS earthdistance"
8
+
9
+ if Rails.env.development? || Rails.env.test?
10
+ enable_extension "cube"
11
+ enable_extension "earthdistance"
12
+ end
13
+
14
+ unless index_exists?(:mgca_addresses, [:latitude,:longitude], name: "mgca_addresses_earthdistance_ix")
15
+ add_earthdistance_index :mgca_addresses, lat: 'latitude', lng: 'longitude'
16
+ end
17
+
18
+ end
19
+
20
+ def self.down
21
+ # => execute "DROP EXTENSION IF EXISTS earthdistance"
22
+ # => execute "DROP EXTENSION IF EXISTS cube"
23
+ # comented out in staging and production to avoid PG::InsufficientPrivilege-ERROR .. add with cap postgresql:remove_extensions
24
+ if Rails.env.development? || Rails.env.test?
25
+ disable_extension "earthdistance"
26
+ disable_extension "cube"
27
+ end
28
+
29
+ remove_index :mgca_addresses, [:latitude,:longitude], name: "mgca_addresses_earthdistance_ix"
30
+
31
+ end
32
+ end
@@ -1,5 +1,6 @@
1
1
  # Geocoder initialer slightly changed to work with magic_addresses
2
2
  Geocoder.configure(
3
+
3
4
  # geocoding options
4
5
  :timeout => 5, # geocoding service timeout (secs)
5
6
  :lookup => :google, # name of geocoding service (symbol)
@@ -15,14 +16,15 @@ Geocoder.configure(
15
16
  # (if you want to implement custom error handling);
16
17
  # supports SocketError and TimeoutError
17
18
  # :always_raise => [],
18
-
19
+
19
20
  # needs to raise OverQueryLimitError to change lookup type when appears
20
21
  :always_raise => [Geocoder::OverQueryLimitError],
21
22
 
22
23
  # calculation options
23
24
  # :units => :mi, # :km for kilometers or :mi for miles
24
25
  # :distances => :linear # :spherical or :linear
25
-
26
+
26
27
  # needed for nominatim lookups
27
28
  :http_headers => { "User-Agent" => "YOUR-APP-NAME", "Accept-Language" => "de" },
29
+
28
30
  )
@@ -147,6 +147,11 @@ class AddMagicAddresses < ActiveRecord::Migration
147
147
  end
148
148
  def down
149
149
 
150
+ # when use postgres earthdistance
151
+ if MagicAddresses.configuration.earthdistance
152
+ remove_index :mgca_addresses, [:latitude,:longitude], name: "mgca_addresses_earthdistance_ix"
153
+ end
154
+
150
155
  ## Addresses
151
156
  remove_index :mgca_addresses, :subdistrict_id
152
157
  remove_index :mgca_addresses, :district_id
@@ -1,12 +1,18 @@
1
1
  MagicAddresses.configure do |config|
2
+ # Address Owners .. all models that use addresses (name + class_name => {users: "User", things: "Namespace::Thing"})
3
+ config.address_owners = {}
2
4
  # in which locales addresses should be saved
3
- config.active_locales = [:en, :de]
5
+ config.active_locales = [:en, :de]
4
6
  # what is the default language (should be :en, except you don't need english at all)
5
- config.default_locale = :en
6
- # what is the default country (for lookup)
7
- config.default_country = "Germany"
8
- # use a background-process for the lookups
9
- config.job_backend = :none
10
- # use a postgres earthdistance for distance calculation
11
- config.earthdistance = false
12
- end
7
+ config.default_locale = :en
8
+ # what is the default country for query
9
+ config.default_country = "Germany"
10
+ # add default country in each query ?
11
+ config.query_defaults = true
12
+ # only save tranlations when differs from default-locale?
13
+ config.uniq_translations = false
14
+ # use background-process for the lookups ( :none | :sidekiq )
15
+ config.job_backend = :none
16
+ # use postgres earthdistance for distance calculation
17
+ config.earthdistance = false
18
+ end