state_pattern 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +8 -4
  3. data/examples/rails_3_button_example/script/rails +0 -0
  4. data/examples/rails_4_button_example/Gemfile +46 -0
  5. data/examples/rails_4_button_example/Gemfile.lock +157 -0
  6. data/examples/rails_4_button_example/README.rdoc +28 -0
  7. data/examples/{rails_2_3_8_button_example → rails_4_button_example}/Rakefile +2 -6
  8. data/examples/rails_4_button_example/app/assets/javascripts/application.js +16 -0
  9. data/examples/rails_4_button_example/app/assets/stylesheets/application.css +15 -0
  10. data/examples/rails_4_button_example/app/controllers/application_controller.rb +5 -0
  11. data/examples/{rails_2_3_8_button_example → rails_4_button_example}/app/controllers/buttons_controller.rb +3 -8
  12. data/examples/rails_4_button_example/app/helpers/application_helper.rb +2 -0
  13. data/examples/{rails_2_3_8_button_example → rails_4_button_example}/app/models/button.rb +0 -0
  14. data/examples/{rails_2_3_8_button_example → rails_4_button_example}/app/models/button/off.rb +0 -0
  15. data/examples/{rails_2_3_8_button_example → rails_4_button_example}/app/models/button/on.rb +0 -0
  16. data/examples/rails_4_button_example/app/views/buttons/_form.html.erb +21 -0
  17. data/examples/rails_4_button_example/app/views/buttons/edit.html.erb +6 -0
  18. data/examples/rails_4_button_example/app/views/buttons/index.html.erb +23 -0
  19. data/examples/rails_4_button_example/app/views/buttons/new.html.erb +5 -0
  20. data/examples/{rails_2_3_8_button_example → rails_4_button_example}/app/views/buttons/show.html.erb +1 -1
  21. data/examples/rails_4_button_example/app/views/layouts/application.html.erb +12 -0
  22. data/examples/rails_4_button_example/bin/bundle +3 -0
  23. data/examples/rails_4_button_example/bin/rails +8 -0
  24. data/examples/rails_4_button_example/bin/rake +8 -0
  25. data/examples/rails_4_button_example/bin/setup +29 -0
  26. data/examples/rails_4_button_example/bin/spring +15 -0
  27. data/examples/rails_4_button_example/config.ru +4 -0
  28. data/examples/rails_4_button_example/config/application.rb +26 -0
  29. data/examples/rails_4_button_example/config/boot.rb +3 -0
  30. data/examples/{rails_2_3_8_button_example → rails_4_button_example}/config/database.yml +0 -0
  31. data/examples/rails_4_button_example/config/environment.rb +5 -0
  32. data/examples/rails_4_button_example/config/environments/development.rb +41 -0
  33. data/examples/rails_4_button_example/config/environments/production.rb +79 -0
  34. data/examples/rails_4_button_example/config/environments/test.rb +42 -0
  35. data/examples/rails_4_button_example/config/initializers/assets.rb +11 -0
  36. data/examples/{rails_2_3_8_button_example → rails_4_button_example}/config/initializers/backtrace_silencers.rb +2 -2
  37. data/examples/rails_4_button_example/config/initializers/cookies_serializer.rb +3 -0
  38. data/examples/rails_4_button_example/config/initializers/filter_parameter_logging.rb +4 -0
  39. data/examples/rails_4_button_example/config/initializers/inflections.rb +16 -0
  40. data/examples/{rails_2_3_8_button_example → rails_4_button_example}/config/initializers/mime_types.rb +0 -1
  41. data/examples/rails_4_button_example/config/initializers/session_store.rb +3 -0
  42. data/examples/rails_4_button_example/config/initializers/wrap_parameters.rb +14 -0
  43. data/examples/rails_4_button_example/config/locales/en.yml +23 -0
  44. data/examples/rails_4_button_example/config/routes.rb +5 -0
  45. data/examples/rails_4_button_example/config/secrets.yml +22 -0
  46. data/examples/{rails_3_button_example → rails_4_button_example}/db/development.sqlite3 +0 -0
  47. data/examples/rails_4_button_example/db/schema.rb +21 -0
  48. data/examples/{rails_2_3_8_button_example → rails_4_button_example}/db/seeds.rb +3 -3
  49. data/examples/rails_4_button_example/db/test.sqlite3 +0 -0
  50. data/examples/rails_4_button_example/public/404.html +67 -0
  51. data/examples/rails_4_button_example/public/422.html +67 -0
  52. data/examples/rails_4_button_example/public/500.html +66 -0
  53. data/examples/rails_4_button_example/public/favicon.ico +0 -0
  54. data/examples/rails_4_button_example/public/robots.txt +5 -0
  55. data/examples/rails_4_button_example/test/test_helper.rb +10 -0
  56. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/0BJF3aE6L9I-CdqfM1vkFjpFBWqYfezN_FW0Lj8RF4A.cache +2 -0
  57. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/25cnngfH_LUdZUzCkWGHXzOa7gYAIbK1KokOftWRmAQ.cache +0 -0
  58. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/3hl1sZkns5ee8V-i-WR-XsJ9Q1Eb8R4ae2xOpLheBN0.cache +1 -0
  59. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/AgXtbwKSwhtftp5wI3VQUtwmz6kB4r6m75W7b-iFYZ4.cache +1 -0
  60. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/BRmY2myye-FTQX-95MjIHm2DL2xKXJlLcGl7Xh1lE_I.cache +1 -0
  61. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/D4INSAJh2MuaZXOe1khQPTL-_wxRvNDwJb3gTkgnye4.cache +1 -0
  62. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/ESVS2t_92m256UsCWPucHsMgAf3mK8kYdKuc1047Lwo.cache +3 -0
  63. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/GpmXMnR78YiAOw85MO8NNmw2iLQ79-a_9GExT6Vt0lI.cache +1 -0
  64. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/GyoBO1Lr-5cRy5clwoTZ5p1jZFNLHymE44cE0tlBKFY.cache +0 -0
  65. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/IEoe5zOhmWy0JaBQe7z0EuqQ7QyiWkdBzstXZjsEKZo.cache +0 -0
  66. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/ISkwmSSt8rrkdRL1GwBn9o4ILWaNnOJyixxf4RX94z4.cache +2 -0
  67. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/Im0488zfiXCJH-KMbI4A7h6A1rax9XpKQnC3DFko1Tg.cache +1 -0
  68. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/LiJ9_nrPkr74731F6YeBknQUCRFqzKeo-P1LntAfTl8.cache +2 -0
  69. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/N7RuW5y7R05Kmq0ismjda4wp0u1UCLE5TqStjtASNMU.cache +0 -0
  70. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/OuEnX_z_G8Ja1YbbCjd5aQ9O9ry06I8X0EKCdZ0GO04.cache +1 -0
  71. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/TMI1rsUDvy6QDgEC4o39T2vtzA2PbuzLav-J4rCXSuM.cache +1 -0
  72. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/VT3u8_h-fkin9_cEH_E8D6BLsz_3vEtZF2KwWX3RZE8.cache +1 -0
  73. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/X7l7HU-zo5WW5WmIJE9MnY5wKmCphQiqiI0l00JWUA4.cache +1 -0
  74. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/XU4CHJPKIryEop9D5jhiVfnW-9F5Cxzujoa6zwA9egE.cache +1 -0
  75. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/aOzh5w6UU36ks31JV_onH2aPBTI5dFTF-zF7-vvKK1c.cache +1 -0
  76. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/bMj6M9wSBtZfHLG65eW2u9NINz-F2yWF0wvJnx5xBpg.cache +0 -0
  77. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/c8UWC3Xah91Ham9SSBwpt2O02vgnSIUTWNiCyfI5YJ8.cache +2 -0
  78. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/dHBwAzZ_u-AXSdVdNW0B7bIzniKy2EAWcNcrvMTxh_k.cache +2 -0
  79. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/fZ12J5mB4ihVvZDBTocYdXAen7YEXjkzDkaqa3D1mI8.cache +1 -0
  80. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/fnePkpq2OgSfrlujhk1_fNG6kjuMZ61mDG0c0Ivit9U.cache +0 -0
  81. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/g0XgcH-GeMIj0lwPaHV5IqDcQzJvnR3Xw_8dg0DBVho.cache +0 -0
  82. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/iGYHI6OqKX0w3ivvIXR-boAWL5x81VEM_GqoNJCBr6s.cache +0 -0
  83. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/l4fHH1Zo47D2G0zAnbfyDyaxlUq4_R6O1R_xNoqmHhw.cache +0 -0
  84. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/mKQKN_P_8jYD-Q80hhjvo4e3LImaXAMIThYLqa9Apvw.cache +0 -0
  85. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/mWqYee_LlZoGLCIvrCNU_U1gCixLtE_1c-aRqNkooZE.cache +2 -0
  86. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/my8kgZGxmOFYs4sBIlBx4mPLa3-bz0D1PfUl737ixlU.cache +1 -0
  87. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/nW-hLkhpsu1Zh2w1u0dXHVkdIslZUKkcvE8CLVIW62Y.cache +0 -0
  88. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/p_8FlTUmjyxhzHW7PiP9gJydL0GWbtF7zMAsolZQt7s.cache +0 -0
  89. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/sRmbkRkNO0Rz5igafyTEwypjH6THAj7wiv24NFKOouw.cache +1 -0
  90. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/uHtYDCLtnVci3xvC8mW10dfUdR20jK-cAPNTSx-uWBg.cache +0 -0
  91. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/vWSj4lAxWQ9AJD4chDHnsj4iDBTcPAQKSVOIqHe_4Pg.cache +1 -0
  92. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/ychj6_LlHUXHJTPKIinw5cIDiTrudXh6MR_7zO-kpAw.cache +1 -0
  93. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/zh122yIBAuJyzL1VU2PIldcpbQl7ecXz-EmuWGZYFrk.cache +1 -0
  94. data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/zo647VN_kDb913bXE7Ta0qarVlYZJ2iCgNNAmquQftQ.cache +0 -0
  95. data/lib/state_pattern/active_record.rb +1 -1
  96. data/test/state_pattern/active_record/active_record_test.rb +1 -0
  97. data/test/test_helper.rb +2 -5
  98. metadata +309 -233
  99. data/examples/rails_2_3_8_button_example/README +0 -243
  100. data/examples/rails_2_3_8_button_example/app/controllers/application_controller.rb +0 -2
  101. data/examples/rails_2_3_8_button_example/app/helpers/application_helper.rb +0 -3
  102. data/examples/rails_2_3_8_button_example/app/views/layouts/application.html.erb +0 -12
  103. data/examples/rails_2_3_8_button_example/config/boot.rb +0 -110
  104. data/examples/rails_2_3_8_button_example/config/environment.rb +0 -41
  105. data/examples/rails_2_3_8_button_example/config/environments/development.rb +0 -17
  106. data/examples/rails_2_3_8_button_example/config/environments/production.rb +0 -28
  107. data/examples/rails_2_3_8_button_example/config/environments/test.rb +0 -28
  108. data/examples/rails_2_3_8_button_example/config/initializers/cookie_verification_secret.rb +0 -7
  109. data/examples/rails_2_3_8_button_example/config/initializers/inflections.rb +0 -10
  110. data/examples/rails_2_3_8_button_example/config/initializers/new_rails_defaults.rb +0 -21
  111. data/examples/rails_2_3_8_button_example/config/initializers/session_store.rb +0 -15
  112. data/examples/rails_2_3_8_button_example/config/locales/en.yml +0 -5
  113. data/examples/rails_2_3_8_button_example/config/routes.rb +0 -4
  114. data/examples/rails_2_3_8_button_example/db/development.sqlite3 +0 -0
  115. data/examples/rails_2_3_8_button_example/db/migrate/20101009073737_create_buttons.rb +0 -13
  116. data/examples/rails_2_3_8_button_example/db/schema.rb +0 -20
  117. data/examples/rails_2_3_8_button_example/db/test.sqlite3 +0 -0
  118. data/examples/rails_2_3_8_button_example/doc/README_FOR_APP +0 -2
  119. data/examples/rails_2_3_8_button_example/public/images/rails.png +0 -0
  120. data/examples/rails_2_3_8_button_example/public/javascripts/application.js +0 -2
  121. data/examples/rails_2_3_8_button_example/public/javascripts/controls.js +0 -963
  122. data/examples/rails_2_3_8_button_example/public/javascripts/dragdrop.js +0 -973
  123. data/examples/rails_2_3_8_button_example/public/javascripts/effects.js +0 -1128
  124. data/examples/rails_2_3_8_button_example/public/javascripts/prototype.js +0 -4320
  125. data/examples/rails_2_3_8_button_example/public/javascripts/rails.js +0 -175
  126. data/examples/rails_2_3_8_button_example/script/about +0 -4
  127. data/examples/rails_2_3_8_button_example/script/console +0 -3
  128. data/examples/rails_2_3_8_button_example/script/dbconsole +0 -3
  129. data/examples/rails_2_3_8_button_example/script/destroy +0 -3
  130. data/examples/rails_2_3_8_button_example/script/generate +0 -3
  131. data/examples/rails_2_3_8_button_example/script/performance/benchmarker +0 -3
  132. data/examples/rails_2_3_8_button_example/script/performance/profiler +0 -3
  133. data/examples/rails_2_3_8_button_example/script/plugin +0 -3
  134. data/examples/rails_2_3_8_button_example/script/runner +0 -3
  135. data/examples/rails_2_3_8_button_example/script/server +0 -3
@@ -1,175 +0,0 @@
1
- (function() {
2
- // Technique from Juriy Zaytsev
3
- // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
- function isEventSupported(eventName) {
5
- var el = document.createElement('div');
6
- eventName = 'on' + eventName;
7
- var isSupported = (eventName in el);
8
- if (!isSupported) {
9
- el.setAttribute(eventName, 'return;');
10
- isSupported = typeof el[eventName] == 'function';
11
- }
12
- el = null;
13
- return isSupported;
14
- }
15
-
16
- function isForm(element) {
17
- return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
- }
19
-
20
- function isInput(element) {
21
- if (Object.isElement(element)) {
22
- var name = element.nodeName.toUpperCase()
23
- return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
- }
25
- else return false
26
- }
27
-
28
- var submitBubbles = isEventSupported('submit'),
29
- changeBubbles = isEventSupported('change')
30
-
31
- if (!submitBubbles || !changeBubbles) {
32
- // augment the Event.Handler class to observe custom events when needed
33
- Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
- function(init, element, eventName, selector, callback) {
35
- init(element, eventName, selector, callback)
36
- // is the handler being attached to an element that doesn't support this event?
37
- if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
- (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
- // "submit" => "emulated:submit"
40
- this.eventName = 'emulated:' + this.eventName
41
- }
42
- }
43
- )
44
- }
45
-
46
- if (!submitBubbles) {
47
- // discover forms on the page by observing focus events which always bubble
48
- document.on('focusin', 'form', function(focusEvent, form) {
49
- // special handler for the real "submit" event (one-time operation)
50
- if (!form.retrieve('emulated:submit')) {
51
- form.on('submit', function(submitEvent) {
52
- var emulated = form.fire('emulated:submit', submitEvent, true)
53
- // if custom event received preventDefault, cancel the real one too
54
- if (emulated.returnValue === false) submitEvent.preventDefault()
55
- })
56
- form.store('emulated:submit', true)
57
- }
58
- })
59
- }
60
-
61
- if (!changeBubbles) {
62
- // discover form inputs on the page
63
- document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
- // special handler for real "change" events
65
- if (!input.retrieve('emulated:change')) {
66
- input.on('change', function(changeEvent) {
67
- input.fire('emulated:change', changeEvent, true)
68
- })
69
- input.store('emulated:change', true)
70
- }
71
- })
72
- }
73
-
74
- function handleRemote(element) {
75
- var method, url, params;
76
-
77
- var event = element.fire("ajax:before");
78
- if (event.stopped) return false;
79
-
80
- if (element.tagName.toLowerCase() === 'form') {
81
- method = element.readAttribute('method') || 'post';
82
- url = element.readAttribute('action');
83
- params = element.serialize();
84
- } else {
85
- method = element.readAttribute('data-method') || 'get';
86
- url = element.readAttribute('href');
87
- params = {};
88
- }
89
-
90
- new Ajax.Request(url, {
91
- method: method,
92
- parameters: params,
93
- evalScripts: true,
94
-
95
- onComplete: function(request) { element.fire("ajax:complete", request); },
96
- onSuccess: function(request) { element.fire("ajax:success", request); },
97
- onFailure: function(request) { element.fire("ajax:failure", request); }
98
- });
99
-
100
- element.fire("ajax:after");
101
- }
102
-
103
- function handleMethod(element) {
104
- var method = element.readAttribute('data-method'),
105
- url = element.readAttribute('href'),
106
- csrf_param = $$('meta[name=csrf-param]')[0],
107
- csrf_token = $$('meta[name=csrf-token]')[0];
108
-
109
- var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
- element.parentNode.insert(form);
111
-
112
- if (method !== 'post') {
113
- var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
- form.insert(field);
115
- }
116
-
117
- if (csrf_param) {
118
- var param = csrf_param.readAttribute('content'),
119
- token = csrf_token.readAttribute('content'),
120
- field = new Element('input', { type: 'hidden', name: param, value: token });
121
- form.insert(field);
122
- }
123
-
124
- form.submit();
125
- }
126
-
127
-
128
- document.on("click", "*[data-confirm]", function(event, element) {
129
- var message = element.readAttribute('data-confirm');
130
- if (!confirm(message)) event.stop();
131
- });
132
-
133
- document.on("click", "a[data-remote]", function(event, element) {
134
- if (event.stopped) return;
135
- handleRemote(element);
136
- event.stop();
137
- });
138
-
139
- document.on("click", "a[data-method]", function(event, element) {
140
- if (event.stopped) return;
141
- handleMethod(element);
142
- event.stop();
143
- });
144
-
145
- document.on("submit", function(event) {
146
- var element = event.findElement(),
147
- message = element.readAttribute('data-confirm');
148
- if (message && !confirm(message)) {
149
- event.stop();
150
- return false;
151
- }
152
-
153
- var inputs = element.select("input[type=submit][data-disable-with]");
154
- inputs.each(function(input) {
155
- input.disabled = true;
156
- input.writeAttribute('data-original-value', input.value);
157
- input.value = input.readAttribute('data-disable-with');
158
- });
159
-
160
- var element = event.findElement("form[data-remote]");
161
- if (element) {
162
- handleRemote(element);
163
- event.stop();
164
- }
165
- });
166
-
167
- document.on("ajax:after", "form", function(event, element) {
168
- var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
- inputs.each(function(input) {
170
- input.value = input.readAttribute('data-original-value');
171
- input.removeAttribute('data-original-value');
172
- input.disabled = false;
173
- });
174
- });
175
- })();
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../config/boot', __FILE__)
3
- $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
4
- require 'commands/about'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../config/boot', __FILE__)
3
- require 'commands/console'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../config/boot', __FILE__)
3
- require 'commands/dbconsole'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../config/boot', __FILE__)
3
- require 'commands/destroy'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../config/boot', __FILE__)
3
- require 'commands/generate'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../../config/boot', __FILE__)
3
- require 'commands/performance/benchmarker'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../../config/boot', __FILE__)
3
- require 'commands/performance/profiler'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../config/boot', __FILE__)
3
- require 'commands/plugin'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../config/boot', __FILE__)
3
- require 'commands/runner'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path('../../config/boot', __FILE__)
3
- require 'commands/server'