card 1.16.6 → 1.16.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (440) hide show
  1. checksums.yaml +4 -4
  2. data/.yardoc/checksums +234 -49
  3. data/.yardoc/object_types +0 -0
  4. data/.yardoc/objects/root.dat +0 -0
  5. data/VERSION +1 -1
  6. data/config/initializers/mime_types.rb +3 -3
  7. data/config/initializers/notification.rb +1 -1
  8. data/db/migrate/20121118115000_update_link_type.rb +8 -8
  9. data/db/migrate/20130411210957_update_codenames.rb +2 -2
  10. data/db/migrate/20140822073704_create_new_revision_tables.rb +12 -13
  11. data/db/migrate/20141001105348_move_revisions_to_actions.rb +16 -16
  12. data/db/migrate/20141121172918_rename_card_migration_table.rb +4 -4
  13. data/db/migrate_core_cards/20130419215612_import_help_text.rb +3 -3
  14. data/db/migrate_core_cards/20130823192433_add_style_cards.rb +45 -47
  15. data/db/migrate_core_cards/20130910183318_move_styles_to_content.rb +1 -1
  16. data/db/migrate_core_cards/20130920214038_jsonize_tinymce.rb +3 -3
  17. data/db/migrate_core_cards/20130920291703_update_stylesheets.rb +3 -3
  18. data/db/migrate_core_cards/20130927191728_account_events.rb +6 -6
  19. data/db/migrate_core_cards/20131016172445_common_css_patch.rb +1 -1
  20. data/db/migrate_core_cards/20140110193325_reset_account_request_type.rb +1 -1
  21. data/db/migrate_core_cards/20140307231621_user_data_to_cards.rb +19 -19
  22. data/db/migrate_core_cards/20140317035504_account_requests_to_signups.rb +11 -12
  23. data/db/migrate_core_cards/20140512155840_add_script_cards.rb +35 -36
  24. data/db/migrate_core_cards/20140629222005_add_email_cards.rb +55 -55
  25. data/db/migrate_core_cards/20140725180118_config_card_updates.rb +1 -1
  26. data/db/migrate_core_cards/20141111083921_delete_machine_output.rb +2 -2
  27. data/db/migrate_core_cards/20141115034214_config_descriptions_etc.rb +3 -3
  28. data/db/migrate_core_cards/20141120120605_fix_notification_html_message.rb +2 -2
  29. data/db/migrate_core_cards/20141204061304_watchers_to_following.rb +8 -8
  30. data/db/migrate_core_cards/20141208162106_add_ace_script.rb +2 -2
  31. data/db/migrate_core_cards/20141216155251_add_more_following_cards.rb +16 -16
  32. data/db/migrate_core_cards/20141230204340_uri_codename.rb +1 -1
  33. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +19 -19
  34. data/db/migrate_core_cards/20150220134731_following_to_follow_rule.rb +3 -3
  35. data/db/migrate_core_cards/20150317162412_bootstrap_themes.rb +15 -15
  36. data/db/migrate_core_cards/20150326205655_bootswatch_themes.rb +11 -11
  37. data/db/migrate_core_cards/20150331135745_new_card_menu.rb +1 -1
  38. data/db/migrate_core_cards/20150429090551_search_card_context.rb +1 -1
  39. data/db/migrate_core_cards/20150508212032_menu_compatibility.rb +3 -3
  40. data/db/migrate_core_cards/20150510031118_fix_skin_images.rb +1 -1
  41. data/db/migrate_core_cards/20150528084659_add_session_cardtype.rb +4 -4
  42. data/db/migrate_core_cards/20150601133433_add_recent_setting_session_card.rb +5 -5
  43. data/db/migrate_core_cards/20150605115802_add_performance_log_card.rb +1 -1
  44. data/db/migrate_core_cards/20150610171702_add_debugger_session_card.rb +2 -2
  45. data/db/migrate_core_cards/20150611203506_rails_inflection_updates.rb +5 -5
  46. data/db/migrate_core_cards/20150627205133_fix_script_bootstrap_card_type.rb +1 -1
  47. data/db/migrate_core_cards/20150702130543_remove_edit_toolbar_pinned.rb +1 -1
  48. data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +5 -5
  49. data/db/migrate_core_cards/20150807205221_create_references_for_search_cards.rb +1 -1
  50. data/db/migrate_core_cards/20150824135418_update_file_history.rb +3 -3
  51. data/db/migrate_core_cards/20150903130006_attachment_upload_cards.rb +2 -2
  52. data/db/migrate_core_cards/20150910085603_remove_performance_log_card.rb +1 -1
  53. data/lib/card.rb +4 -4
  54. data/lib/card/active_record_ext.rb +8 -8
  55. data/lib/card/auth.rb +6 -6
  56. data/lib/card/cache.rb +1 -1
  57. data/lib/card/chunk.rb +1 -1
  58. data/lib/card/content.rb +1 -1
  59. data/lib/card/diff.rb +10 -10
  60. data/lib/card/env.rb +1 -1
  61. data/lib/card/format.rb +12 -12
  62. data/lib/card/loader.rb +1 -1
  63. data/lib/card/migration.rb +1 -1
  64. data/lib/card/name.rb +4 -4
  65. data/lib/card/query.rb +255 -61
  66. data/lib/card/query/attributes.rb +310 -0
  67. data/lib/card/query/clause.rb +12 -15
  68. data/lib/card/query/join.rb +73 -0
  69. data/lib/card/query/reference.rb +51 -0
  70. data/lib/card/query/sql_statement.rb +228 -0
  71. data/lib/card/query/value.rb +66 -0
  72. data/lib/card/reference.rb +6 -6
  73. data/lib/card/set.rb +12 -12
  74. data/lib/card/set_pattern.rb +9 -9
  75. data/lib/card/spec_helper.rb +5 -5
  76. data/lib/card/success.rb +1 -1
  77. data/lib/cardio.rb +7 -7
  78. data/lib/generators/card/format/format_generator.rb +3 -3
  79. data/lib/generators/card/migration/migration_generator.rb +5 -5
  80. data/lib/generators/card/set/set_generator.rb +4 -4
  81. data/mod/01_core/chunk/include.rb +4 -4
  82. data/mod/01_core/chunk/link.rb +5 -5
  83. data/mod/01_core/chunk/literal.rb +2 -2
  84. data/mod/01_core/chunk/query_reference.rb +8 -8
  85. data/mod/01_core/chunk/uri.rb +18 -18
  86. data/mod/01_core/format/html_format.rb +4 -4
  87. data/mod/01_core/set/all/active_card.rb +2 -2
  88. data/mod/01_core/set/all/collection.rb +21 -26
  89. data/mod/01_core/set/all/content.rb +2 -2
  90. data/mod/01_core/set/all/fetch.rb +6 -6
  91. data/mod/01_core/set/all/initialize.rb +4 -4
  92. data/mod/01_core/set/all/location_history.rb +2 -2
  93. data/mod/01_core/set/all/name.rb +14 -14
  94. data/mod/01_core/set/all/pattern.rb +1 -1
  95. data/mod/01_core/set/all/permissions.rb +12 -12
  96. data/mod/01_core/set/all/phases.rb +29 -12
  97. data/mod/01_core/set/all/references.rb +14 -14
  98. data/mod/01_core/set/all/rules.rb +8 -8
  99. data/mod/01_core/set/all/templating.rb +10 -9
  100. data/mod/01_core/set/all/tracked_attributes.rb +7 -7
  101. data/mod/01_core/set/all/trash.rb +6 -6
  102. data/mod/01_core/set/all/type.rb +7 -7
  103. data/mod/01_core/set/all/utils.rb +4 -4
  104. data/mod/01_core/set/all/view_cache.rb +1 -1
  105. data/mod/01_core/set_pattern/02_all_plus.rb +2 -2
  106. data/mod/01_core/set_pattern/03_type.rb +1 -1
  107. data/mod/01_core/set_pattern/04_star.rb +1 -1
  108. data/mod/01_core/set_pattern/05_rstar.rb +2 -2
  109. data/mod/01_core/set_pattern/06_right.rb +4 -4
  110. data/mod/01_core/set_pattern/07_type_plus_right.rb +4 -4
  111. data/mod/01_core/set_pattern/08_self.rb +1 -1
  112. data/mod/01_core/spec/chunk/uri_spec.rb +73 -73
  113. data/mod/01_core/spec/format/html_format_spec.rb +5 -5
  114. data/mod/01_core/spec/set/all/attribute_tracking_spec.rb +1 -1
  115. data/mod/01_core/spec/set/all/collection_spec.rb +22 -22
  116. data/mod/01_core/spec/set/all/content_spec.rb +1 -1
  117. data/mod/01_core/spec/set/all/fetch_spec.rb +24 -24
  118. data/mod/01_core/spec/set/all/initialize_spec.rb +9 -9
  119. data/mod/01_core/spec/set/all/name_spec.rb +8 -8
  120. data/mod/01_core/spec/set/all/pattern_spec.rb +10 -10
  121. data/mod/01_core/spec/set/all/permissions_spec.rb +45 -45
  122. data/mod/01_core/spec/set/all/references_spec.rb +1 -1
  123. data/mod/01_core/spec/set/all/rules2_spec.rb +15 -15
  124. data/mod/01_core/spec/set/all/rules_spec.rb +37 -37
  125. data/mod/01_core/spec/set/all/templating_spec.rb +21 -21
  126. data/mod/01_core/spec/set/all/tracked_attributes_spec.rb +55 -55
  127. data/mod/01_core/spec/set/all/trash_spec.rb +4 -4
  128. data/mod/01_core/spec/set/all/type_spec.rb +15 -15
  129. data/mod/01_history/lib/card/act.rb +2 -2
  130. data/mod/01_history/lib/card/action.rb +22 -22
  131. data/mod/01_history/lib/card/change.rb +1 -1
  132. data/mod/01_history/set/all/actions.rb +2 -2
  133. data/mod/01_history/set/all/content_history.rb +4 -4
  134. data/mod/01_history/set/all/history.rb +46 -46
  135. data/mod/02_basic_types/set/all/all_css.rb +10 -10
  136. data/mod/02_basic_types/set/all/all_csv.rb +7 -7
  137. data/mod/02_basic_types/set/all/base.rb +25 -25
  138. data/mod/02_basic_types/set/all/json.rb +16 -16
  139. data/mod/02_basic_types/set/all/rss.rb +7 -7
  140. data/mod/02_basic_types/set/type/html.rb +2 -2
  141. data/mod/02_basic_types/set/type/plain_text.rb +1 -1
  142. data/mod/02_basic_types/set/type/pointer.rb +39 -31
  143. data/mod/02_basic_types/spec/set/all/all_css_spec.rb +1 -1
  144. data/mod/02_basic_types/spec/set/all/all_csv_spec.rb +1 -1
  145. data/mod/02_basic_types/spec/set/all/base_spec.rb +18 -18
  146. data/mod/02_basic_types/spec/set/all/json_spec.rb +4 -4
  147. data/mod/02_basic_types/spec/set/all/rss_spec.rb +8 -2
  148. data/mod/02_basic_types/spec/set/type/plain_text_spec.rb +1 -1
  149. data/mod/02_basic_types/spec/set/type/pointer_spec.rb +54 -44
  150. data/mod/03_machines/lib/card/machine.rb +46 -29
  151. data/mod/03_machines/lib/card/machine_input.rb +34 -10
  152. data/mod/03_machines/set/type/coffee_script.rb +3 -3
  153. data/mod/03_machines/set/type/css.rb +8 -8
  154. data/mod/03_machines/set/type/java_script.rb +4 -4
  155. data/mod/03_machines/set/type/scss.rb +2 -2
  156. data/mod/03_machines/set/type/skin.rb +1 -1
  157. data/mod/03_machines/spec/lib/shared_machine_examples.rb +27 -27
  158. data/mod/03_machines/spec/lib/shared_machine_input_examples.rb +8 -8
  159. data/mod/03_machines/spec/set/type/coffeescript_spec.rb +6 -6
  160. data/mod/03_machines/spec/set/type/css_spec.rb +9 -9
  161. data/mod/03_machines/spec/set/type/javascript_spec.rb +6 -6
  162. data/mod/03_machines/spec/set/type/scss_spec.rb +5 -5
  163. data/mod/03_machines/spec/set/type/skin_spec.rb +25 -25
  164. data/mod/04_settings/lib/card/setting.rb +11 -11
  165. data/mod/04_settings/set/abstract/permission.rb +9 -9
  166. data/mod/04_settings/set/right/script.rb +1 -1
  167. data/mod/04_settings/set/right/structure.rb +0 -5
  168. data/mod/04_settings/set/right/style.rb +2 -2
  169. data/mod/04_settings/set/self/accountable.rb +1 -1
  170. data/mod/04_settings/set/self/add_help.rb +1 -1
  171. data/mod/04_settings/set/self/autoname.rb +1 -1
  172. data/mod/04_settings/set/self/captcha.rb +1 -1
  173. data/mod/04_settings/set/self/create.rb +1 -1
  174. data/mod/04_settings/set/self/default.rb +1 -1
  175. data/mod/04_settings/set/self/delete.rb +1 -1
  176. data/mod/04_settings/set/self/help.rb +1 -1
  177. data/mod/04_settings/set/self/input.rb +1 -1
  178. data/mod/04_settings/set/self/layout.rb +1 -1
  179. data/mod/04_settings/set/self/on_create.rb +1 -1
  180. data/mod/04_settings/set/self/on_delete.rb +1 -1
  181. data/mod/04_settings/set/self/on_update.rb +1 -1
  182. data/mod/04_settings/set/self/options.rb +1 -1
  183. data/mod/04_settings/set/self/options_label.rb +1 -1
  184. data/mod/04_settings/set/self/read.rb +1 -1
  185. data/mod/04_settings/set/self/script.rb +1 -1
  186. data/mod/04_settings/set/self/structure.rb +1 -1
  187. data/mod/04_settings/set/self/style.rb +1 -1
  188. data/mod/04_settings/set/self/table_of_contents.rb +1 -1
  189. data/mod/04_settings/set/self/thanks.rb +1 -1
  190. data/mod/04_settings/set/self/update.rb +1 -1
  191. data/mod/04_settings/set/type/setting.rb +14 -14
  192. data/mod/04_settings/spec/set/right/comment_spec.rb +5 -5
  193. data/mod/04_settings/spec/set/right/create_spec.rb +1 -1
  194. data/mod/04_settings/spec/set/right/script_spec.rb +5 -5
  195. data/mod/04_settings/spec/set/right/structure_spec.rb +4 -2
  196. data/mod/04_settings/spec/set/right/style_spec.rb +7 -7
  197. data/mod/04_settings/spec/set/type/setting_spec.rb +2 -2
  198. data/mod/05_email/lib/card/follow_option.rb +24 -24
  199. data/mod/05_email/set/all/follow.rb +24 -16
  200. data/mod/05_email/set/all/notify.rb +25 -23
  201. data/mod/05_email/set/all/observer.rb +5 -5
  202. data/mod/05_email/set/right/bcc.rb +8 -8
  203. data/mod/05_email/set/right/follow.rb +44 -17
  204. data/mod/05_email/set/right/follow_fields.rb +1 -1
  205. data/mod/05_email/set/right/following.rb +49 -40
  206. data/mod/05_email/set/self/always.rb +2 -2
  207. data/mod/05_email/set/self/created.rb +1 -1
  208. data/mod/05_email/set/self/edited.rb +4 -4
  209. data/mod/05_email/set/self/follow.rb +1 -1
  210. data/mod/05_email/set/self/follow_defaults.rb +9 -9
  211. data/mod/05_email/set/self/never.rb +1 -1
  212. data/mod/05_email/set/type/email_template.rb +9 -9
  213. data/mod/05_email/set/type_plus_right/user/follow.rb +16 -16
  214. data/mod/05_email/spec/set/all/follow_spec.rb +10 -10
  215. data/mod/05_email/spec/set/all/notify_spec.rb +82 -82
  216. data/mod/05_email/spec/set/all/observer_spec.rb +16 -16
  217. data/mod/05_email/spec/set/right/followers_spec.rb +6 -6
  218. data/mod/05_email/spec/set/self/follow_defaults_spec.rb +2 -2
  219. data/mod/05_standard/lib/carrier_wave/cardmount.rb +5 -5
  220. data/mod/05_standard/lib/image_uploader.rb +8 -8
  221. data/mod/05_standard/set/abstract/attachment.rb +18 -18
  222. data/mod/05_standard/set/all/account.rb +5 -5
  223. data/mod/05_standard/set/all/comment.rb +7 -7
  224. data/mod/05_standard/set/all/error.rb +25 -25
  225. data/mod/05_standard/set/all/event_viz.rb +1 -1
  226. data/mod/05_standard/set/all/links.rb +9 -9
  227. data/mod/05_standard/set/all/rich_html/content.rb +34 -34
  228. data/mod/05_standard/set/all/rich_html/editing.rb +35 -35
  229. data/mod/05_standard/set/all/rich_html/form.rb +20 -20
  230. data/mod/05_standard/set/all/rich_html/header.rb +8 -8
  231. data/mod/05_standard/set/all/rich_html/menu.rb +33 -33
  232. data/mod/05_standard/set/all/rich_html/modal.rb +16 -16
  233. data/mod/05_standard/set/all/rich_html/toolbar.rb +63 -63
  234. data/mod/05_standard/set/all/rich_html/wrapper.rb +8 -8
  235. data/mod/05_standard/set/right/account.rb +27 -27
  236. data/mod/05_standard/set/right/email.rb +5 -5
  237. data/mod/05_standard/set/right/password.rb +5 -5
  238. data/mod/05_standard/set/rstar/rules.rb +52 -52
  239. data/mod/05_standard/set/self/account_links.rb +27 -27
  240. data/mod/05_standard/set/self/all.rb +1 -1
  241. data/mod/05_standard/set/self/head.rb +5 -5
  242. data/mod/05_standard/set/self/navbox.rb +11 -11
  243. data/mod/05_standard/set/self/recent.rb +2 -2
  244. data/mod/05_standard/set/self/search.rb +13 -13
  245. data/mod/05_standard/set/self/signin.rb +19 -19
  246. data/mod/05_standard/set/self/stats.rb +2 -2
  247. data/mod/05_standard/set/type/basic.rb +1 -1
  248. data/mod/05_standard/set/type/cardtype.rb +5 -5
  249. data/mod/05_standard/set/type/date.rb +1 -1
  250. data/mod/05_standard/set/type/file.rb +7 -7
  251. data/mod/05_standard/set/type/image.rb +8 -8
  252. data/mod/05_standard/set/type/number.rb +2 -2
  253. data/mod/05_standard/set/type/phrase.rb +1 -1
  254. data/mod/05_standard/set/type/search_type.rb +27 -21
  255. data/mod/05_standard/set/type/session.rb +2 -2
  256. data/mod/05_standard/set/type/set.rb +37 -37
  257. data/mod/05_standard/set/type/signup.rb +25 -25
  258. data/mod/05_standard/set/type/uri.rb +1 -1
  259. data/mod/05_standard/set/type/user.rb +21 -21
  260. data/mod/05_standard/spec/chunk/include_spec.rb +16 -16
  261. data/mod/05_standard/spec/chunk/link_spec.rb +18 -18
  262. data/mod/05_standard/spec/chunk/query_reference_spec.rb +1 -1
  263. data/mod/05_standard/spec/set/all/account_spec.rb +7 -7
  264. data/mod/05_standard/spec/set/all/email_html_spec.rb +3 -3
  265. data/mod/05_standard/spec/set/all/history_spec.rb +14 -14
  266. data/mod/05_standard/spec/set/all/rich_html/editing_spec.rb +1 -1
  267. data/mod/05_standard/spec/set/all/rich_html/form_spec.rb +2 -2
  268. data/mod/05_standard/spec/set/right/account_spec.rb +9 -9
  269. data/mod/05_standard/spec/set/right/email_spec.rb +8 -8
  270. data/mod/05_standard/spec/set/right/password_spec.rb +9 -9
  271. data/mod/05_standard/spec/set/right/stats_spec.rb +1 -1
  272. data/mod/05_standard/spec/set/right/when_created_spec.rb +1 -1
  273. data/mod/05_standard/spec/set/right/when_last_edited_spec.rb +1 -1
  274. data/mod/05_standard/spec/set/rstar/rules_spec.rb +2 -2
  275. data/mod/05_standard/spec/set/self/account_links_spec.rb +2 -2
  276. data/mod/05_standard/spec/set/self/all_spec.rb +8 -11
  277. data/mod/05_standard/spec/set/self/head_spec.rb +1 -1
  278. data/mod/05_standard/spec/set/self/navbox_spec.rb +1 -1
  279. data/mod/05_standard/spec/set/self/now_spec.rb +1 -1
  280. data/mod/05_standard/spec/set/self/stats_spec.rb +1 -1
  281. data/mod/05_standard/spec/set/self/version_spec.rb +1 -1
  282. data/mod/05_standard/spec/set/type/email_template_spec.rb +25 -25
  283. data/mod/05_standard/spec/set/type/file_spec.rb +4 -4
  284. data/mod/05_standard/spec/set/type/html_spec.rb +3 -3
  285. data/mod/05_standard/spec/set/type/image_spec.rb +6 -6
  286. data/mod/05_standard/spec/set/type/layout_type_spec.rb +1 -1
  287. data/mod/05_standard/spec/set/type/search_type_spec.rb +10 -10
  288. data/mod/05_standard/spec/set/type/signup_spec.rb +11 -11
  289. data/mod/05_standard/spec/set/type/toggle_spec.rb +2 -2
  290. data/mod/05_standard/spec/set/type/uri_spec.rb +9 -9
  291. data/mod/06_bootstrap/set/all/bootstrap/helper.rb +10 -10
  292. data/mod/06_bootstrap/set/all/bootstrap/wrapper.rb +4 -4
  293. data/mod/06_bootstrap/set/all/rich_bootstrap.rb +1 -1
  294. data/spec/lib/card/action_spec.rb +2 -2
  295. data/spec/lib/card/cache_spec.rb +7 -7
  296. data/spec/lib/card/content_spec.rb +31 -37
  297. data/spec/lib/card/diff_spec.rb +56 -56
  298. data/spec/lib/card/format_spec.rb +11 -11
  299. data/spec/lib/card/query_spec.rb +382 -265
  300. data/spec/lib/card/reference_spec.rb +133 -140
  301. data/spec/lib/card/set_pattern_spec.rb +10 -9
  302. data/spec/lib/card/set_spec.rb +11 -11
  303. data/spec/lib/card/success_spec.rb +16 -8
  304. data/spec/mailers/mailer_spec.rb +5 -5
  305. data/spec/models/card/cardtype_spec.rb +20 -20
  306. data/spec/models/card/create_spec.rb +6 -6
  307. data/spec/models/card/trash_spec.rb +20 -20
  308. data/spec/models/card/type_transition_spec.rb +3 -3
  309. data/spec/models/card/validation_spec.rb +5 -5
  310. data/spec/models/card_spec.rb +24 -24
  311. data/spec/spec_helper.rb +5 -5
  312. data/tmpsets/set/mod001-01_core/all/active_card.rb +2 -2
  313. data/tmpsets/set/mod001-01_core/all/collection.rb +23 -26
  314. data/tmpsets/set/mod001-01_core/all/content.rb +2 -2
  315. data/tmpsets/set/mod001-01_core/all/fetch.rb +6 -6
  316. data/tmpsets/set/mod001-01_core/all/initialize.rb +8 -4
  317. data/tmpsets/set/mod001-01_core/all/name.rb +14 -14
  318. data/tmpsets/set/mod001-01_core/all/pattern.rb +1 -1
  319. data/tmpsets/set/mod001-01_core/all/permissions.rb +12 -12
  320. data/tmpsets/set/mod001-01_core/all/phases.rb +31 -13
  321. data/tmpsets/set/mod001-01_core/all/references.rb +14 -14
  322. data/tmpsets/set/mod001-01_core/all/rules.rb +8 -10
  323. data/tmpsets/set/mod001-01_core/all/templating.rb +10 -9
  324. data/tmpsets/set/mod001-01_core/all/tracked_attributes.rb +7 -7
  325. data/tmpsets/set/mod001-01_core/all/trash.rb +9 -8
  326. data/tmpsets/set/mod001-01_core/all/type.rb +7 -7
  327. data/tmpsets/set/mod001-01_core/all/utils.rb +16 -4
  328. data/tmpsets/set/mod001-01_core/all/view_cache.rb +1 -1
  329. data/tmpsets/set/mod002-01_history/all/actions.rb +2 -2
  330. data/tmpsets/set/mod002-01_history/all/content_history.rb +11 -7
  331. data/tmpsets/set/mod002-01_history/all/history.rb +46 -46
  332. data/tmpsets/set/mod003-02_basic_types/all/all_css.rb +10 -10
  333. data/tmpsets/set/mod003-02_basic_types/all/all_csv.rb +7 -7
  334. data/tmpsets/set/mod003-02_basic_types/all/base.rb +25 -25
  335. data/tmpsets/set/mod003-02_basic_types/all/json.rb +16 -16
  336. data/tmpsets/set/mod003-02_basic_types/all/rss.rb +7 -7
  337. data/tmpsets/set/mod003-02_basic_types/type/html.rb +2 -2
  338. data/tmpsets/set/mod003-02_basic_types/type/plain_text.rb +1 -1
  339. data/tmpsets/set/mod003-02_basic_types/type/pointer.rb +38 -31
  340. data/tmpsets/set/mod004-03_machines/right/machine_output.rb +4 -0
  341. data/tmpsets/set/mod004-03_machines/type/coffee_script.rb +3 -3
  342. data/tmpsets/set/mod004-03_machines/type/css.rb +8 -8
  343. data/tmpsets/set/mod004-03_machines/type/java_script.rb +4 -4
  344. data/tmpsets/set/mod004-03_machines/type/scss.rb +2 -2
  345. data/tmpsets/set/mod004-03_machines/type/skin.rb +1 -1
  346. data/tmpsets/set/mod005-04_settings/abstract/permission.rb +9 -9
  347. data/tmpsets/set/mod005-04_settings/right/script.rb +1 -1
  348. data/tmpsets/set/mod005-04_settings/right/structure.rb +0 -5
  349. data/tmpsets/set/mod005-04_settings/right/style.rb +2 -2
  350. data/tmpsets/set/mod005-04_settings/self/accountable.rb +1 -1
  351. data/tmpsets/set/mod005-04_settings/self/add_help.rb +1 -1
  352. data/tmpsets/set/mod005-04_settings/self/autoname.rb +1 -1
  353. data/tmpsets/set/mod005-04_settings/self/captcha.rb +1 -1
  354. data/tmpsets/set/mod005-04_settings/self/create.rb +1 -1
  355. data/tmpsets/set/mod005-04_settings/self/default.rb +1 -1
  356. data/tmpsets/set/mod005-04_settings/self/delete.rb +1 -1
  357. data/tmpsets/set/mod005-04_settings/self/help.rb +1 -1
  358. data/tmpsets/set/mod005-04_settings/self/input.rb +1 -1
  359. data/tmpsets/set/mod005-04_settings/self/layout.rb +1 -1
  360. data/tmpsets/set/mod005-04_settings/self/on_create.rb +1 -1
  361. data/tmpsets/set/mod005-04_settings/self/on_delete.rb +1 -1
  362. data/tmpsets/set/mod005-04_settings/self/on_update.rb +1 -1
  363. data/tmpsets/set/mod005-04_settings/self/options.rb +1 -1
  364. data/tmpsets/set/mod005-04_settings/self/options_label.rb +1 -1
  365. data/tmpsets/set/mod005-04_settings/self/read.rb +1 -1
  366. data/tmpsets/set/mod005-04_settings/self/script.rb +1 -1
  367. data/tmpsets/set/mod005-04_settings/self/structure.rb +1 -1
  368. data/tmpsets/set/mod005-04_settings/self/style.rb +1 -1
  369. data/tmpsets/set/mod005-04_settings/self/table_of_contents.rb +1 -1
  370. data/tmpsets/set/mod005-04_settings/self/thanks.rb +1 -1
  371. data/tmpsets/set/mod005-04_settings/self/update.rb +1 -1
  372. data/tmpsets/set/mod005-04_settings/type/setting.rb +14 -14
  373. data/tmpsets/set/mod006-05_email/all/follow.rb +24 -16
  374. data/tmpsets/set/mod006-05_email/all/notify.rb +25 -23
  375. data/tmpsets/set/mod006-05_email/all/observer.rb +8 -8
  376. data/tmpsets/set/mod006-05_email/right/bcc.rb +8 -8
  377. data/tmpsets/set/mod006-05_email/right/follow.rb +44 -17
  378. data/tmpsets/set/mod006-05_email/right/follow_fields.rb +1 -1
  379. data/tmpsets/set/mod006-05_email/right/following.rb +49 -40
  380. data/tmpsets/set/mod006-05_email/self/always.rb +2 -2
  381. data/tmpsets/set/mod006-05_email/self/created.rb +1 -1
  382. data/tmpsets/set/mod006-05_email/self/edited.rb +4 -4
  383. data/tmpsets/set/mod006-05_email/self/follow.rb +1 -1
  384. data/tmpsets/set/mod006-05_email/self/follow_defaults.rb +9 -9
  385. data/tmpsets/set/mod006-05_email/self/never.rb +1 -1
  386. data/tmpsets/set/mod006-05_email/type/email_template.rb +9 -9
  387. data/tmpsets/set/mod006-05_email/type_plus_right/user/follow.rb +17 -17
  388. data/tmpsets/set/mod007-05_standard/abstract/attachment.rb +98 -46
  389. data/tmpsets/set/mod007-05_standard/all/account.rb +5 -5
  390. data/tmpsets/set/mod007-05_standard/all/comment.rb +7 -7
  391. data/tmpsets/set/mod007-05_standard/all/error.rb +26 -26
  392. data/tmpsets/set/mod007-05_standard/all/event_viz.rb +1 -1
  393. data/tmpsets/set/mod007-05_standard/all/links.rb +10 -9
  394. data/tmpsets/set/mod007-05_standard/all/rich_html/content.rb +34 -34
  395. data/tmpsets/set/mod007-05_standard/all/rich_html/editing.rb +35 -35
  396. data/tmpsets/set/mod007-05_standard/all/rich_html/form.rb +20 -20
  397. data/tmpsets/set/mod007-05_standard/all/rich_html/header.rb +8 -8
  398. data/tmpsets/set/mod007-05_standard/all/rich_html/menu.rb +33 -33
  399. data/tmpsets/set/mod007-05_standard/all/rich_html/modal.rb +16 -16
  400. data/tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb +63 -63
  401. data/tmpsets/set/mod007-05_standard/all/rich_html/wrapper.rb +8 -8
  402. data/tmpsets/set/mod007-05_standard/right/account.rb +27 -27
  403. data/tmpsets/set/mod007-05_standard/right/email.rb +5 -5
  404. data/tmpsets/set/mod007-05_standard/right/password.rb +5 -5
  405. data/tmpsets/set/mod007-05_standard/rstar/rules.rb +52 -52
  406. data/tmpsets/set/mod007-05_standard/self/account_links.rb +27 -27
  407. data/tmpsets/set/mod007-05_standard/self/all.rb +1 -1
  408. data/tmpsets/set/mod007-05_standard/self/head.rb +5 -5
  409. data/tmpsets/set/mod007-05_standard/self/navbox.rb +11 -11
  410. data/tmpsets/set/mod007-05_standard/self/recent.rb +2 -2
  411. data/tmpsets/set/mod007-05_standard/self/search.rb +13 -13
  412. data/tmpsets/set/mod007-05_standard/self/signin.rb +19 -19
  413. data/tmpsets/set/mod007-05_standard/self/stats.rb +2 -2
  414. data/tmpsets/set/mod007-05_standard/type/basic.rb +1 -1
  415. data/tmpsets/set/mod007-05_standard/type/cardtype.rb +5 -5
  416. data/tmpsets/set/mod007-05_standard/type/date.rb +1 -1
  417. data/tmpsets/set/mod007-05_standard/type/file.rb +23 -8
  418. data/tmpsets/set/mod007-05_standard/type/image.rb +10 -8
  419. data/tmpsets/set/mod007-05_standard/type/number.rb +2 -2
  420. data/tmpsets/set/mod007-05_standard/type/phrase.rb +1 -1
  421. data/tmpsets/set/mod007-05_standard/type/search_type.rb +21 -19
  422. data/tmpsets/set/mod007-05_standard/type/session.rb +2 -2
  423. data/tmpsets/set/mod007-05_standard/type/set.rb +37 -37
  424. data/tmpsets/set/mod007-05_standard/type/signup.rb +25 -25
  425. data/tmpsets/set/mod007-05_standard/type/uri.rb +1 -1
  426. data/tmpsets/set/mod007-05_standard/type/user.rb +21 -21
  427. data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb +10 -10
  428. data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/wrapper.rb +4 -4
  429. data/tmpsets/set/mod008-06_bootstrap/all/rich_bootstrap.rb +1 -1
  430. data/tmpsets/set_pattern/101-all_plus.rb +2 -2
  431. data/tmpsets/set_pattern/102-type.rb +1 -1
  432. data/tmpsets/set_pattern/103-star.rb +1 -1
  433. data/tmpsets/set_pattern/104-rstar.rb +2 -2
  434. data/tmpsets/set_pattern/105-right.rb +4 -4
  435. data/tmpsets/set_pattern/106-type_plus_right.rb +4 -4
  436. data/tmpsets/set_pattern/107-self.rb +1 -1
  437. metadata +7 -5
  438. data/lib/card/query/card_clause.rb +0 -528
  439. data/lib/card/query/ref_clause.rb +0 -47
  440. data/lib/card/query/value_clause.rb +0 -65
data/lib/card/env.rb CHANGED
@@ -7,7 +7,7 @@ class Card
7
7
  module Env
8
8
  class << self
9
9
  def reset args={}
10
- @@env = { :main_name => nil }
10
+ @@env = { main_name: nil }
11
11
 
12
12
  if c = args[:controller]
13
13
  self[:controller] = c
data/lib/card/format.rb CHANGED
@@ -4,9 +4,9 @@ class Card
4
4
  class Format
5
5
  include Card::Location
6
6
 
7
- DEPRECATED_VIEWS = { :view=>:open, :card=>:open, :line=>:closed, :bare=>:core, :naked=>:core }
8
- INCLUSION_MODES = { :closed=>:closed, :closed_content=>:closed, :edit=>:edit,
9
- :layout=>:layout, :new=>:edit, :setup=>:edit, :normal=>:normal, :template=>:template } #should be set in views
7
+ DEPRECATED_VIEWS = { view: :open, card: :open, line: :closed, bare: :core, naked: :core }
8
+ INCLUSION_MODES = { closed: :closed, closed_content: :closed, edit: :edit,
9
+ layout: :layout, new: :edit, setup: :edit, normal: :normal, template: :template } #should be set in views
10
10
 
11
11
  cattr_accessor :ajax_call, :registered
12
12
  [ :perms, :denial_views, :closed_views, :error_codes, :view_tags, :aliases ].each do |acc|
@@ -122,7 +122,7 @@ class Card
122
122
  end
123
123
 
124
124
  def get_inclusion_defaults nested_card
125
- { :view => :name }
125
+ { view: :name }
126
126
  end
127
127
 
128
128
  def params
@@ -168,7 +168,7 @@ class Card
168
168
  def template
169
169
  @template ||= begin
170
170
  c = controller
171
- t = ActionView::Base.new c.class.view_paths, {:_routes=>c._routes}, c
171
+ t = ActionView::Base.new c.class.view_paths, {_routes: c._routes}, c
172
172
  t.extend c.class._helpers
173
173
  t
174
174
  end
@@ -179,7 +179,7 @@ class Card
179
179
  when /(_)?(optional_)?render(_(\w+))?/
180
180
  view = $3 ? $4 : opts.shift
181
181
  args = opts[0] ? opts.shift.clone : {}
182
- args.merge!( :optional=>true, :default_visibility=>opts.shift) if $2
182
+ args.merge!( optional: true, default_visibility: opts.shift) if $2
183
183
  args[ :skip_permissions ] = true if $1
184
184
  render view, args
185
185
  when /^_view_(\w+)/
@@ -299,11 +299,11 @@ class Card
299
299
  #
300
300
 
301
301
  def subformat subcard
302
- subcard = Card.fetch( subcard, :new=>{} ) if String===subcard
303
- sub = self.class.new subcard, :parent=>self, :depth=>@depth+1, :root=>@root,
302
+ subcard = Card.fetch( subcard, new: {} ) if String===subcard
303
+ sub = self.class.new subcard, parent: self, depth: @depth+1, root: @root,
304
304
  # FIXME - the following four should not be hard-coded here. need a generalized mechanism
305
305
  # for attribute inheritance
306
- :context_names=>@context_names, :mode=>@mode, :mainline=>@mainline, :form=>@form
306
+ context_names: @context_names, mode: @mode, mainline: @mainline, form: @form
307
307
  end
308
308
 
309
309
 
@@ -433,7 +433,7 @@ class Card
433
433
  end
434
434
 
435
435
  if val=params[:item] and val.present?
436
- opts[:items] = (opts[:items] || {}).reverse_merge :view=>val.to_sym
436
+ opts[:items] = (opts[:items] || {}).reverse_merge view: val.to_sym
437
437
  end
438
438
  end
439
439
 
@@ -492,7 +492,7 @@ class Card
492
492
  end
493
493
 
494
494
  def fetch_nested_card options
495
- args = { :name=>options[:inc_name], :type=>options[:type], :supercard=>card }
495
+ args = { name: options[:inc_name], type: options[:type], supercard: card }
496
496
  args.delete(:supercard) if options[:inc_name].strip.blank? # special case. gets absolutized incorrectly. fix in smartname?
497
497
  if options[:inc_name] =~ /^_main\+/
498
498
  # FIXME this is a rather hacky (and untested) way to get @superleft to work on new cards named _main+whatever
@@ -502,7 +502,7 @@ class Card
502
502
  if content=get_inclusion_content(options[:inc_name])
503
503
  args[:content]=content
504
504
  end
505
- Card.fetch options[:inc_name], :new=>args
505
+ Card.fetch options[:inc_name], new: args
506
506
  end
507
507
 
508
508
  def default_item_view
data/lib/card/loader.rb CHANGED
@@ -133,7 +133,7 @@ class Card
133
133
  if rewrite_tmp_files?
134
134
  p = Card.paths[ path ]
135
135
  if p.existent.first
136
- FileUtils.rm_rf p.first, :secure=>true
136
+ FileUtils.rm_rf p.first, secure: true
137
137
  end
138
138
  Dir.mkdir p.first
139
139
  end
@@ -78,7 +78,7 @@ class Card::Migration < ActiveRecord::Migration
78
78
 
79
79
  def import_json filename, merge_opts={}
80
80
  Card.config.action_mailer.perform_deliveries = false
81
- merge_opts.reverse_merge! :output_file=>File.join(data_path,"unmerged_#{ filename }")
81
+ merge_opts.reverse_merge! output_file: File.join(data_path,"unmerged_#{ filename }")
82
82
  Card.merge_list read_json(filename), merge_opts
83
83
  end
84
84
 
data/lib/card/name.rb CHANGED
@@ -22,14 +22,14 @@ class Card
22
22
  junction? && begin
23
23
  right_key = right_name.key
24
24
  !!traitlist.find do |codename|
25
- card_id = Card::Codename[ codename ] and card = Card.fetch( card_id, :skip_modules=>true, :skip_virtual=>true ) and
25
+ card_id = Card::Codename[ codename ] and card = Card.fetch( card_id, skip_modules: true, skip_virtual: true ) and
26
26
  card.key == right_key
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
31
  def trait_name tag_code
32
- card_id = Card::Codename[ tag_code ] and card = Card.fetch( card_id, :skip_modules=>true, :skip_virtual=>true ) and
32
+ card_id = Card::Codename[ tag_code ] and card = Card.fetch( card_id, skip_modules: true, skip_virtual: true ) and
33
33
  [ self, card.cardname ].to_name
34
34
  end
35
35
 
@@ -53,11 +53,11 @@ class Card
53
53
  self.s.match /^\s*\+/
54
54
  end
55
55
  end
56
-
56
+
57
57
  def is_setting?
58
58
  Set::Type::Setting.member_names[ key ]
59
59
  end
60
-
60
+
61
61
  def is_set?
62
62
  SetPattern.card_keys[ tag_name.key ]
63
63
  end
data/lib/card/query.rb CHANGED
@@ -1,91 +1,285 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- class Card::Query
4
- require_dependency 'card/query/clause'
5
- require_dependency 'card/query/card_clause'
6
- require_dependency 'card/query/value_clause'
7
- require_dependency 'card/query/ref_clause'
3
+ class Card
4
+ # Card::Query is for finding implicit lists (or counts of lists) of cards.
5
+ #
6
+ # Search and Set cards use Card::Query to query the database, and it's also
7
+ # frequently used directly in code.
8
+ #
9
+ # Query "statements" (objects, really) are made in WQL (Wagn Query
10
+ # Language). Because WQL is used by Wagneers, the primary language
11
+ # documentation is on wagn.org. (http://wagn.org/WQL_Syntax). Note that the
12
+ # examples there are in JSON, like Search card content, but statements in
13
+ # Card::Query are in ruby form.
14
+ #
15
+ # In Wagn's current form, Card::Query generates and executes SQL statements.
16
+ # However, the SQL generation is largely (not yet fully) separated from the
17
+ # WQL statement interpretation.
18
+ #
19
+ # The most common way to use Card::Query is as follows:
20
+ # list_of_cards = Card::Query.run(statement)
21
+ #
22
+ # This is equivalent to:
23
+ # query = Card::Query.new(statement)
24
+ # list_of_cards = query.run
25
+ #
26
+ # Upon initiation, the query is interpreted, and the following key objects
27
+ # are populated:
28
+ #
29
+ # - @join - an Array of Card::Query::Join objects
30
+ # - @conditions - an Array of conditions
31
+ # - @mod - a Hash of other query-altering keys
32
+ # - @subqueries - a list of other queries nested within this one
33
+ #
34
+ # Each condition is either a SQL-ready string (boo) or an Array in this form:
35
+ # [ field_string_or_sym, Card::Value::Query object ]
36
+ class Query
37
+ require_dependency 'card/query/clause'
38
+ require_dependency 'card/query/value'
39
+ require_dependency 'card/query/reference'
40
+ require_dependency 'card/query/attributes'
41
+ require_dependency 'card/query/sql_statement'
42
+ require_dependency 'card/query/join'
8
43
 
9
- MODIFIERS = {}; %w{ conj return sort sort_as group dir limit offset }.each{|key| MODIFIERS[key.to_sym] = nil }
44
+ include Clause
45
+ include Attributes
10
46
 
11
- OPERATORS = %w{ != = =~ < > in ~ }.inject({}) {|h,v| h[v]=nil; h }.merge({
12
- :eq => '=', :gt => '>', :lt => '<',
13
- :match => '~', :ne => '!=', 'not in' => nil
14
- }.stringify_keys)
47
+ ATTRIBUTES = {
48
+ basic: %w( id name key type_id content left_id right_id
49
+ creator_id updater_id codename ),
50
+ relational: %w( type part left right
51
+ editor_of edited_by last_editor_of last_edited_by
52
+ creator_of created_by member_of member ),
53
+ plus_relational: %w( plus left_plus right_plus ),
54
+ ref_relational: %w( refer_to referred_to_by
55
+ link_to linked_to_by
56
+ include included_by ),
57
+ conjunction: %w( and or all any ),
58
+ special: %w( found_by not sort match complete extension_type ),
59
+ ignore: %w( prepend append view params vars size )
60
+ }.inject({}) {|h,pair| pair[1].each { |v| h[v.to_sym]=pair[0] }; h }
15
61
 
16
- def initialize query
17
- @card_clause = CardClause.build query
18
- end
62
+ CONJUNCTIONS = { any: :or, in: :or, or: :or, all: :and, and: :and }
19
63
 
20
- def query
21
- @card_clause.query
22
- end
64
+ MODIFIERS = %w( conj return sort sort_as group dir limit offset )
65
+ .inject({}) { |h,v| h[v.to_sym]=nil; h }
23
66
 
24
- def sql
25
- @sql ||= @card_clause.to_sql
26
- end
67
+ OPERATORS = %w( != = =~ < > in ~ ).inject({}) {|h,v| h[v]=v; h }.merge({
68
+ eq: '=', gt: '>', lt: '<', match: '~', ne: '!=', :'not in'=> nil
69
+ }.stringify_keys)
27
70
 
28
- def run
29
- retrn = query[:return].present? ? query[:return].to_s : 'card'
30
- if retrn == 'card'
31
- simple_run('name').map do |name|
32
- Card.fetch name, :new=>{}
33
- end
34
- else
35
- simple_run retrn
71
+ DEFAULT_ORDER_DIRS = { :update => "desc", :relevance => "desc" }
72
+
73
+ attr_reader :statement, :mods, :conditions,
74
+ :subqueries, :superquery
75
+ attr_accessor :joins, :table_seq, :unjoined, :conditions_on_join
76
+
77
+ def initialize statement
78
+ @subqueries = []
79
+ @conditions = []
80
+ @joins = []
81
+ @mods = {}
82
+ @statement = statement.clone
83
+
84
+ @unjoined = @statement.delete(:unjoined ) || nil
85
+ @context = @statement.delete(:context ) || nil
86
+ @superquery = @statement.delete(:superquery) || nil
87
+ @vars = @statement.delete(:vars ) || {}
88
+ @vars.symbolize_keys!
89
+
90
+ interpret @statement
91
+ self
36
92
  end
37
- end
38
93
 
94
+ # Query Execution
95
+ # By default a query returns card objects. This is accomplished by returning
96
+ # a card identifier from SQL and then hooking into our caching system (see
97
+ # Card::Fetch)
98
+
99
+ def self.run statement
100
+ query = new statement
101
+ query.run
102
+ end
39
103
 
40
- def simple_run retrn
41
- rows = run_sql
104
+ # run the current query
105
+ # @return array of card objects by default
106
+ def run
107
+ retrn = statement[:return].present? ? statement[:return].to_s : 'card'
108
+ if retrn == 'card'
109
+ get_results('name').map do |name|
110
+ Card.fetch name, new: {}
111
+ end
112
+ else
113
+ get_results retrn
114
+ end
115
+ end
42
116
 
43
- case retrn
44
- when 'name' #common case
45
- if query[:prepend] || query[:append]
117
+ # @return Integer for :count, otherwise Array of Strings or Integers
118
+ def get_results retrn
119
+ rows = run_sql
120
+ if retrn == 'name' && (statement[:prepend] || statement[:append])
46
121
  rows.map do |row|
47
- [ query[:prepend], row['name'], query[:append] ].compact * '+'
122
+ [statement[:prepend], row['name'], statement[:append]].compact * '+'
48
123
  end
49
124
  else
50
- rows.map { |row| row['name'] }
125
+ case retrn
126
+ when 'count' then rows.first['count'].to_i
127
+ when 'raw' then rows
128
+ when /id$/ then rows.map { |row| row[retrn].to_i }
129
+ else rows.map { |row| row[retrn] }
130
+ end
51
131
  end
52
- when 'count'
53
- rows.first['count'].to_i
54
- when 'raw'
55
- rows
56
- when /id$/
57
- rows.map { |row| row[retrn].to_i }
58
- else
59
- rows.map { |row| row[retrn] }
60
132
  end
61
- end
62
133
 
63
- def run_sql
64
- ActiveRecord::Base.connection.select_all( sql )
65
- end
134
+ def run_sql
135
+ # puts "\nstatement = #{@statement}"
136
+ # puts "sql = #{sql}"
137
+ ActiveRecord::Base.connection.select_all(sql)
138
+ end
139
+
140
+ def sql
141
+ @sql ||= SqlStatement.new(self).build.to_s
142
+ end
66
143
 
144
+ # Query Hierarchy
145
+ # @root, @subqueries, and @superquery are used to track a hierarchy of
146
+ # query objects. This nesting allows to find, for example, cards that
147
+ # link to cards that link to cards....
67
148
 
68
- class SqlCond < String
69
- def to_sql(*args) self end
70
- end
149
+ def root
150
+ @root ||= @superquery ? @superquery.root : self
151
+ end
71
152
 
153
+ def subquery opts={}
154
+ subquery = Query.new opts.merge(superquery: self)
155
+ @subqueries << subquery
156
+ subquery
157
+ end
72
158
 
73
- class SqlStatement
74
- attr_accessor :fields, :tables, :joins, :conditions, :group, :order, :limit, :offset, :distinct
159
+ # Query Interpretation
75
160
 
76
- def initialize
77
- @fields, @joins, @conditions = [],[],[],[]
78
- @tables = @group = @order = @limit = @offset = @distinct = nil
161
+ # normalize and extract meaning from a clause
162
+ # @param clause [Hash, String, Integer] statement or chunk thereof
163
+ def interpret clause
164
+ interpret_by_key normalize_clause(clause)
79
165
  end
80
166
 
81
- def to_s
82
- select = fields.reject(&:blank?) * ', '
83
- where = conditions.reject(&:blank?) * ' and '
167
+ def normalize_clause clause
168
+ clause = clause_to_hash clause
169
+ clause.symbolize_keys!
170
+ clause.each do |key, val|
171
+ clause[key] = normalize_value val
172
+ end
173
+ clause
174
+ end
84
175
 
85
- ['(SELECT', distinct, select, 'FROM', tables, joins, 'WHERE', where, group, order, limit, offset, ')'].compact * ' '
176
+ def clause_to_hash clause
177
+ case clause
178
+ when Hash then clause
179
+ when String then { key: clause.to_name.key }
180
+ when Integer then { id: clause }
181
+ else fail BadQuery, "Invalid query args #{clause.inspect}"
182
+ end
86
183
  end
87
- end
88
184
 
185
+ def normalize_value val
186
+ case val
187
+ when Integer, Float, Symbol, Hash then val
188
+ when String, Card::Name then normalize_string_value val
189
+ when Array then val.map { |v| normalize_value v }
190
+ else fail BadQuery, "unknown WQL value type: #{val.class}"
191
+ end
192
+ end
89
193
 
90
- end
194
+ def normalize_string_value val
195
+ case val.to_s
196
+ when /^\$(\w+)$/ # replace from @vars
197
+ @vars[Regexp.last_match[1].to_sym].to_s.strip
198
+ when /\b_/ # absolutize based on @context
199
+ val.to_name.to_absolute(context)
200
+ else
201
+ val
202
+ end
203
+ end
204
+
205
+ def context
206
+ if !@context.nil?
207
+ @context
208
+ else
209
+ @context = @superquery ? @superquery.context : ''
210
+ end
211
+ end
212
+
213
+ def interpret_by_key clause
214
+ clause.each do |key, val|
215
+ case
216
+ when OPERATORS.key?(key.to_s) && !ATTRIBUTES[key]
217
+ # eg "match" is both operator and attribute;
218
+ # interpret as attribute when "match" is key
219
+ interpret content: [key, val]
220
+ when MODIFIERS.key?(key) && !clause[key].is_a?(Hash)
221
+ # eg when "sort" is hash, it can have subqueries
222
+ # and must be interpreted like an attribute
223
+ @mods[key] = val.is_a?(Array) ? val : val.to_s
224
+ else
225
+ interpret_attributes key, val
226
+ end
227
+ end
228
+ end
229
+
230
+ def add_condition *args
231
+ @conditions <<
232
+ if args.size > 1
233
+ [args.shift, Value.new(args.shift, self)]
234
+ else
235
+ args[0]
236
+ end
237
+ end
238
+
239
+ def interpret_attributes key, val
240
+ case ATTRIBUTES[key]
241
+ when :basic then add_condition key, val
242
+ when :conjunction then send key, val
243
+ when :relational then relate key, val
244
+ when :special then relate key, val
245
+ when :ref_relational then relate key, val, method: :join_references
246
+ when :plus_relational then relate_compound key, val
247
+ when :ignore then # noop
248
+ else fail BadQuery, "Invalid attribute #{key}"
249
+ end
250
+ end
251
+
252
+ def relate_compound key, val
253
+ has_multiple_values =
254
+ val.is_a?(Array) &&
255
+ (val.first.is_a?(Array) || conjunction(val.first).present?)
256
+ relate key, val, multiple: has_multiple_values
257
+ end
91
258
 
259
+ def relate key, val, opts={}
260
+ multiple = opts[:multiple].nil? ? val.is_a?(Array) : opts[:multiple]
261
+ method = opts[:method] || :send
262
+
263
+ if multiple
264
+ conj = conjunction(val.first) ? conjunction(val.shift) : :and
265
+ if conj == current_conjunction
266
+ # same conjunction as container, no need for subcondition
267
+ val.each { |v| send method, key, v }
268
+ else
269
+ send conj, val.map { |v| { key => v } }
270
+ end
271
+ else
272
+ send method, key, val
273
+ end
274
+ end
275
+
276
+ def current_conjunction
277
+ @mods[:conj].blank? ? :and : @mods[:conj]
278
+ end
279
+
280
+ def all_joins
281
+ @all_joins ||=
282
+ (joins + subqueries.find_all(&:unjoined).map(&:all_joins)).flatten
283
+ end
284
+ end
285
+ end