waw 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/LICENCE.rdoc +25 -0
  2. data/README.rdoc +32 -0
  3. data/bin/waw +32 -0
  4. data/bin/waw-profile +26 -0
  5. data/bin/waw-start +26 -0
  6. data/bin/wspec +33 -0
  7. data/layouts/empty/Rakefile +14 -0
  8. data/layouts/empty/config.ru +5 -0
  9. data/layouts/empty/config/commons.cfg +31 -0
  10. data/layouts/empty/config/devel.cfg +21 -0
  11. data/layouts/empty/ignore +7 -0
  12. data/layouts/empty/logs/dontforgetme +0 -0
  13. data/layouts/empty/resources/messages.rs +1 -0
  14. data/layouts/empty/test/wspec/site_respond.wspec +3 -0
  15. data/layouts/empty/test/wspec/test_all.rb +13 -0
  16. data/layouts/empty/waw.deploy +1 -0
  17. data/layouts/empty/waw.routing +6 -0
  18. data/layouts/static/dependencies +1 -0
  19. data/layouts/static/public/.wawaccess +18 -0
  20. data/layouts/static/public/css/style.css +0 -0
  21. data/layouts/static/public/images/dontforgetme +0 -0
  22. data/layouts/static/public/js/project.js +0 -0
  23. data/layouts/static/public/pages/.wawaccess +30 -0
  24. data/layouts/static/public/pages/404.wtpl +1 -0
  25. data/layouts/static/public/pages/index.wtpl +5 -0
  26. data/layouts/static/public/templates/.wawaccess +9 -0
  27. data/layouts/static/public/templates/layout.wtpl +17 -0
  28. data/layouts/static/test/wspec/static_pages_are_served.wspec +21 -0
  29. data/layouts/static/waw.routing +8 -0
  30. data/lib/waw.rb +99 -0
  31. data/lib/waw/commands/command.rb +115 -0
  32. data/lib/waw/commands/profile_command.rb +66 -0
  33. data/lib/waw/commands/start_command.rb +59 -0
  34. data/lib/waw/config.rb +110 -0
  35. data/lib/waw/controller.rb +25 -0
  36. data/lib/waw/controllers/action/action.rb +91 -0
  37. data/lib/waw/controllers/action/action_utils.rb +30 -0
  38. data/lib/waw/controllers/action/js_generation.rb +116 -0
  39. data/lib/waw/controllers/action_controller.rb +133 -0
  40. data/lib/waw/controllers/error/backtrace.rb +54 -0
  41. data/lib/waw/controllers/error_handler.rb +62 -0
  42. data/lib/waw/controllers/json_controller.rb +31 -0
  43. data/lib/waw/controllers/no_cache.rb +22 -0
  44. data/lib/waw/controllers/static/match.rb +80 -0
  45. data/lib/waw/controllers/static/waw_access.rb +235 -0
  46. data/lib/waw/controllers/static/waw_access_dsl.rb +48 -0
  47. data/lib/waw/controllers/static_controller.rb +37 -0
  48. data/lib/waw/default_config.cfg +14 -0
  49. data/lib/waw/environment_utils.rb +57 -0
  50. data/lib/waw/errors.rb +4 -0
  51. data/lib/waw/ext.rb +3 -0
  52. data/lib/waw/ext/core.rb +4 -0
  53. data/lib/waw/ext/core/hash.rb +47 -0
  54. data/lib/waw/ext/core/logger.rb +10 -0
  55. data/lib/waw/ext/core/module.rb +20 -0
  56. data/lib/waw/ext/core/object.rb +29 -0
  57. data/lib/waw/ext/rack.rb +19 -0
  58. data/lib/waw/ext/rack/builder.rb +43 -0
  59. data/lib/waw/ext/rack/delegator.rb +51 -0
  60. data/lib/waw/ext/rack/urlmap.rb +55 -0
  61. data/lib/waw/ext/wlang.rb +1 -0
  62. data/lib/waw/ext/wlang/hosted_language.rb +21 -0
  63. data/lib/waw/fullstate.rb +8 -0
  64. data/lib/waw/fullstate/on_class.rb +37 -0
  65. data/lib/waw/fullstate/on_instance.rb +27 -0
  66. data/lib/waw/fullstate/variable.rb +36 -0
  67. data/lib/waw/kern.rb +6 -0
  68. data/lib/waw/kern/app.rb +48 -0
  69. data/lib/waw/kern/empty/waw.deploy +0 -0
  70. data/lib/waw/kern/empty/waw.routing +1 -0
  71. data/lib/waw/kern/freezed_state.rb +32 -0
  72. data/lib/waw/kern/hooks.rb +53 -0
  73. data/lib/waw/kern/lifecycle.rb +248 -0
  74. data/lib/waw/kern/living_state.rb +87 -0
  75. data/lib/waw/kern/utils.rb +27 -0
  76. data/lib/waw/resource_collection.rb +100 -0
  77. data/lib/waw/restart.rb +32 -0
  78. data/lib/waw/routing.rb +43 -0
  79. data/lib/waw/routing/action_routing.rb +78 -0
  80. data/lib/waw/routing/dsl.rb +45 -0
  81. data/lib/waw/routing/feedback.rb +23 -0
  82. data/lib/waw/routing/form_validation_feedback.rb +36 -0
  83. data/lib/waw/routing/javascript.rb +17 -0
  84. data/lib/waw/routing/redirect.rb +26 -0
  85. data/lib/waw/routing/refresh.rb +17 -0
  86. data/lib/waw/routing/routing_rule.rb +16 -0
  87. data/lib/waw/scope_utils.rb +69 -0
  88. data/lib/waw/session.rb +51 -0
  89. data/lib/waw/testing.rb +1 -0
  90. data/lib/waw/tools/mail.rb +4 -0
  91. data/lib/waw/tools/mail/mail.rb +119 -0
  92. data/lib/waw/tools/mail/mail_agent.rb +123 -0
  93. data/lib/waw/tools/mail/mailbox.rb +62 -0
  94. data/lib/waw/tools/mail/template.rb +38 -0
  95. data/lib/waw/utils/dsl_helper.rb +116 -0
  96. data/lib/waw/validation.rb +175 -0
  97. data/lib/waw/validation/and_validator.rb +27 -0
  98. data/lib/waw/validation/array_validations.rb +38 -0
  99. data/lib/waw/validation/boolean_validator.rb +32 -0
  100. data/lib/waw/validation/comparison_validations.rb +45 -0
  101. data/lib/waw/validation/date_validator.rb +31 -0
  102. data/lib/waw/validation/default_validator.rb +30 -0
  103. data/lib/waw/validation/dsl_ruby_extensions.rb +11 -0
  104. data/lib/waw/validation/errors.rb +17 -0
  105. data/lib/waw/validation/ext.rb +3 -0
  106. data/lib/waw/validation/file_validator.rb +30 -0
  107. data/lib/waw/validation/float_validator.rb +19 -0
  108. data/lib/waw/validation/helpers.rb +67 -0
  109. data/lib/waw/validation/integer_validator.rb +16 -0
  110. data/lib/waw/validation/isin_validator.rb +24 -0
  111. data/lib/waw/validation/mandatory_validator.rb +17 -0
  112. data/lib/waw/validation/missing_validator.rb +17 -0
  113. data/lib/waw/validation/not_validator.rb +20 -0
  114. data/lib/waw/validation/or_validator.rb +34 -0
  115. data/lib/waw/validation/regexp_validator.rb +29 -0
  116. data/lib/waw/validation/same_validator.rb +16 -0
  117. data/lib/waw/validation/signature.rb +157 -0
  118. data/lib/waw/validation/size_validations.rb +44 -0
  119. data/lib/waw/validation/string_validator.rb +15 -0
  120. data/lib/waw/validation/validator.rb +48 -0
  121. data/lib/waw/wawgen.rb +2 -0
  122. data/lib/waw/wawgen/create.rb +166 -0
  123. data/lib/waw/wawgen/project.rb +25 -0
  124. data/lib/waw/wspec.rb +5 -0
  125. data/lib/waw/wspec/browser.rb +240 -0
  126. data/lib/waw/wspec/dsl.rb +201 -0
  127. data/lib/waw/wspec/html_analysis.rb +136 -0
  128. data/lib/waw/wspec/html_analysis/tag.rb +56 -0
  129. data/lib/waw/wspec/runner.rb +70 -0
  130. data/lib/waw/wspec/scenario.rb +35 -0
  131. data/lib/waw/wspec/suite.rb +54 -0
  132. data/test/bricks/error_handler/config/test.cfg +2 -0
  133. data/test/bricks/error_handler/logs/webapp.log +1411 -0
  134. data/test/bricks/error_handler/test/error_handler.wspec +16 -0
  135. data/test/bricks/error_handler/waw.deploy +1 -0
  136. data/test/bricks/error_handler/waw.routing +27 -0
  137. data/test/integration/waw_create_integration_test.rb +24 -0
  138. data/test/spec/assumptions_spec.rb +30 -0
  139. data/test/spec/controllers/action_controller_spec.rb +14 -0
  140. data/test/spec/controllers/static/waw_access_spec.rb +112 -0
  141. data/test/spec/environment_utils_spec.rb +15 -0
  142. data/test/spec/ext/core/hash_spec.rb +58 -0
  143. data/test/spec/fixtures.rb +41 -0
  144. data/test/spec/fixtures/action/config/default.cfg +2 -0
  145. data/test/spec/fixtures/action/lib/action_controller_test.rb +12 -0
  146. data/test/spec/fixtures/action/waw.deploy +1 -0
  147. data/test/spec/fixtures/action/waw.routing +6 -0
  148. data/test/spec/fixtures/empty/waw.deploy +0 -0
  149. data/test/spec/fixtures/empty/waw.routing +0 -0
  150. data/test/spec/fullstate/on_class_spec.rb +59 -0
  151. data/test/spec/fullstate/on_instance_spec.rb +59 -0
  152. data/test/spec/fullstate/session_spec.rb +43 -0
  153. data/test/spec/fullstate/variable_spec.rb +55 -0
  154. data/test/spec/resource_collection_spec.rb +50 -0
  155. data/test/spec/test_all.rb +9 -0
  156. data/test/spec/tools/mail/mail_agent_spec.rb +116 -0
  157. data/test/spec/tools/mail/mail_spec.rb +56 -0
  158. data/test/spec/tools/mail/mailbox_spec.rb +57 -0
  159. data/test/spec/tools/mail/template_spec.rb +47 -0
  160. data/test/spec/validation/array_validation_spec.rb +63 -0
  161. data/test/spec/validation/array_validator_spec.rb +17 -0
  162. data/test/spec/validation/date_validation_spec.rb +35 -0
  163. data/test/spec/validation/default_validation_spec.rb +37 -0
  164. data/test/spec/validation/disjuctive_validation_spec.rb +33 -0
  165. data/test/spec/validation/errors_spec.rb +37 -0
  166. data/test/spec/validation/file_validator_spec.rb +34 -0
  167. data/test/spec/validation/mail_validation_spec.rb +51 -0
  168. data/test/spec/validation/missing_validation_spec.rb +43 -0
  169. data/test/spec/validation/same_validation_spec.rb +24 -0
  170. data/test/spec/validation/signature_intuition_spec.rb +37 -0
  171. data/test/spec/validation/signature_spec.rb +164 -0
  172. data/test/spec/validation/validation_spec.rb +28 -0
  173. data/test/spec/wspec/html_analysis/tag_spec.rb +38 -0
  174. data/test/spec/wspec/html_analysis_spec.rb +170 -0
  175. data/test/unit/test_all.rb +8 -0
  176. data/test/unit/waw/app_test.rb +126 -0
  177. data/test/unit/waw/app_test/config/commons.cfg +2 -0
  178. data/test/unit/waw/app_test/config/devel.cfg +1 -0
  179. data/test/unit/waw/config_test.rb +54 -0
  180. data/test/unit/waw/controllers/action_controller_test.rb +76 -0
  181. data/test/unit/waw/controllers/action_test.rb +35 -0
  182. data/test/unit/waw/controllers/example_action_controller_test.rb +24 -0
  183. data/test/unit/waw/controllers/multiple_action_controller_test.rb +78 -0
  184. data/test/unit/waw/controllers/static/example/css/example.css +1 -0
  185. data/test/unit/waw/controllers/static/example/index.html +1 -0
  186. data/test/unit/waw/controllers/static/example/js/example.js +1 -0
  187. data/test/unit/waw/controllers/static/example/pages/hello.wtpl +1 -0
  188. data/test/unit/waw/controllers/static/waw_access_test.rb +76 -0
  189. data/test/unit/waw/ext/rack_test.rb +74 -0
  190. data/test/unit/waw/resource_collection_test.rb +49 -0
  191. data/test/unit/waw/resources.txt +4 -0
  192. data/test/unit/waw/routing/routing_test.rb +26 -0
  193. data/test/unit/waw/utils/dsl_helper_test.rb +79 -0
  194. data/test/unit/waw/utils/dsl_helper_test_extensions1.rb +4 -0
  195. data/test/unit/waw/validation/signature_test.rb +193 -0
  196. data/test/unit/waw/validation_test.rb +319 -0
  197. data/test/unit/waw/wspec/html_analysis_test.html +81 -0
  198. data/test/unit/waw/wspec/html_analysis_test.rb +26 -0
  199. metadata +272 -0
@@ -0,0 +1,4 @@
1
+ module Waw
2
+ class WawError < StandardError; end
3
+ class ConfigurationError < WawError; end
4
+ end
@@ -0,0 +1,3 @@
1
+ require 'waw/ext/core'
2
+ require 'waw/ext/rack'
3
+ require 'waw/ext/wlang'
@@ -0,0 +1,4 @@
1
+ require 'waw/ext/core/object'
2
+ require 'waw/ext/core/module'
3
+ require 'waw/ext/core/hash'
4
+ require 'waw/ext/core/logger'
@@ -0,0 +1,47 @@
1
+ class Hash
2
+
3
+ def keep!(*keys)
4
+ self.delete_if{|k,v| !keys.flatten.include?(k)}
5
+ end
6
+
7
+ def keep(*keys)
8
+ self.dup.delete_if{|k,v| !keys.flatten.include?(k)}
9
+ end
10
+
11
+ def forget!(*keys)
12
+ self.delete_if{|k,v| keys.flatten.include?(k)}
13
+ end
14
+
15
+ def forget(*keys)
16
+ self.dup.delete_if{|k,v| keys.flatten.include?(k)}
17
+ end
18
+
19
+ def symbolize_keys
20
+ copy = Hash.new
21
+ self.each_pair {|k,v| copy[k.to_s.to_sym] = v}
22
+ copy
23
+ end
24
+
25
+ def methodize
26
+ copy = self.symbolize_keys
27
+ keys.each {|key|
28
+ copy.instance_eval <<-EOF
29
+ def #{key}
30
+ self[:"#{key}"]
31
+ end
32
+ EOF
33
+ }
34
+ copy
35
+ end
36
+
37
+ def unsymbolize_keys
38
+ copy = Hash.new
39
+ self.each_pair {|k,v| copy[k.to_s] = v}
40
+ copy
41
+ end
42
+
43
+ def to_url_query
44
+ ::Rack::Utils.build_query(self)
45
+ end
46
+
47
+ end
@@ -0,0 +1,10 @@
1
+ require 'logger'
2
+
3
+ class Logger
4
+
5
+ def write(*args)
6
+ info(*args)
7
+ end
8
+
9
+ end
10
+
@@ -0,0 +1,20 @@
1
+ class Module
2
+
3
+ def deprecated(msg = "The method ${method_name} is deprecated")
4
+ @deprecated = msg
5
+ end
6
+
7
+ # If a signature has been installed, let the next added method
8
+ # become an action
9
+ def method_added(name)
10
+ if @deprecated
11
+ deprecated, @deprecated = @deprecated.gsub(/#{Regexp.escape('${method_name}')}/, "#{self.name}.#{name}"), nil
12
+ method = instance_method(name)
13
+ define_method name do |*args|
14
+ $waw_deprecated_io << deprecated << " (#{caller[0]})\n" if $waw_deprecated_io
15
+ method.bind(self).call(*args)
16
+ end
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,29 @@
1
+ class Object
2
+ # From active_support 2.3.4
3
+ unless defined? instance_exec # 1.9
4
+ module InstanceExecMethods #:nodoc:
5
+ end
6
+ include InstanceExecMethods
7
+
8
+ # Evaluate the block with the given arguments within the context of
9
+ # this object, so self is set to the method receiver.
10
+ #
11
+ # From Mauricio's http://eigenclass.org/hiki/bounded+space+instance_exec
12
+ def instance_exec(*args, &block)
13
+ begin
14
+ old_critical, Thread.critical = Thread.critical, true
15
+ n = 0
16
+ n += 1 while respond_to?(method_name = "__instance_exec#{n}")
17
+ InstanceExecMethods.module_eval { define_method(method_name, &block) }
18
+ ensure
19
+ Thread.critical = old_critical
20
+ end
21
+
22
+ begin
23
+ send(method_name, *args)
24
+ ensure
25
+ InstanceExecMethods.module_eval { remove_method(method_name) } rescue nil
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ # Force some auto loading ...
2
+ require 'rubygems'
3
+ require 'rack'
4
+ ::Rack::Session::Pool
5
+
6
+ # Let the delegator be known
7
+ require 'waw/ext/rack/delegator'
8
+
9
+ # Install the delegator on all standard Rack applications
10
+ [::Rack::Builder, ::Rack::Session::Abstract::ID, ::Rack::CommonLogger,
11
+ ::Rack::ShowExceptions, ::Rack::Static, ::Rack::URLMap, ::Rack::Reloader].each do |rack_app|
12
+ rack_app.instance_eval <<-EOF
13
+ include ::Rack::Delegator
14
+ EOF
15
+ end
16
+
17
+ # Makes overrides now
18
+ require 'waw/ext/rack/builder.rb'
19
+ require 'waw/ext/rack/urlmap.rb'
@@ -0,0 +1,43 @@
1
+ module Rack
2
+ class Builder
3
+
4
+ #
5
+ # Adds or push an error handler on top of the application chain.
6
+ #
7
+ # The method accepts the following argument variants:
8
+ #
9
+ # error_handler{|k,ex| ... }
10
+ # error_handler(SomeValidator){|k,ex| ... }
11
+ # error_handler(SomeHandler)
12
+ # error_handler(SomeValidator, SomeHandler)
13
+ #
14
+ def error_handler(*args, &block)
15
+ @ins << lambda{|app|
16
+ if ::Waw::ErrorHandler === app
17
+ app.unshift(*args, &block)
18
+ app
19
+ else
20
+ handler = ::Waw::ErrorHandler.new(app)
21
+ handler.push(*args, &block)
22
+ handler
23
+ end
24
+ }
25
+ end
26
+
27
+ #
28
+ # The to_app method works as follows:
29
+ #
30
+ # error_handler(args_1) ->
31
+ # error_handler(args_2) ->
32
+ # use X -> lambda{|app| X.new(app)}
33
+ # use Y -> lambda{|app| Y.new(app)}
34
+ # run Z -> Z
35
+ #
36
+ # which leads to a memo call on the @ins array
37
+ # Y_instance = lambdaY.call(Z)
38
+ # X_instance = lambdaX.call(Y_instance)
39
+ # ...
40
+ #
41
+
42
+ end # module Builder
43
+ end # module Rack
@@ -0,0 +1,51 @@
1
+ module Rack
2
+ # Extends Rack application with utilities. This module may be included
3
+ # by standard rack applications delegating to another one. The later is
4
+ # expected to be returned by delegate. Methods are intended to be
5
+ # overriden for matching specific situations.
6
+ module Delegator
7
+
8
+ # Returns delegate rack application. By default, returns @app.
9
+ def delegate
10
+ @app
11
+ end
12
+
13
+ # Checks if an app may be safely considered in the chain
14
+ def is_delegate?(app)
15
+ Delegator===app
16
+ end
17
+
18
+ # Checks if a delegate exists.
19
+ def has_delegate?
20
+ not(delegate.nil?) and is_delegate?(delegate)
21
+ end
22
+
23
+ # Finds a rack application mapped to a given path. If a block is
24
+ # provided it is used as a predicate matcher.
25
+ def find_rack_app(path = nil, &block)
26
+ return self if (block && block.call(self))
27
+ has_delegate? ? delegate.find_rack_app(path, &block) : nil
28
+ end
29
+
30
+ # Recursively finds the URL on which a given application is installed.
31
+ def find_url_of(app)
32
+ visit{|path, visited| return path if app==visited}
33
+ nil
34
+ end
35
+
36
+ # Visits the Rack application tree recursively by calling the block.
37
+ # The later is expected to have two parameters |path,app|. The first
38
+ # one is an array containing url components, the second is the
39
+ # visited application.
40
+ def visit(&block)
41
+ _visit("/", block)
42
+ end
43
+
44
+ # Internal implementation of visit.
45
+ def _visit(path, block)
46
+ block.call(path, self)
47
+ delegate._visit(path, block) if has_delegate?
48
+ end
49
+
50
+ end # module Delegator
51
+ end # module Rack
@@ -0,0 +1,55 @@
1
+ module Rack
2
+
3
+ # Some overridings of Delegator
4
+ class URLMap
5
+
6
+ # Overrides Delegator.find_rack_app
7
+ def find_rack_app(path = nil, &block)
8
+ return self if (block && block.call(self))
9
+ the_app, the_rest = nil, nil
10
+ if path.nil?
11
+ @mapping.each do |host, location, match, app|
12
+ if is_delegate?(app)
13
+ found = app.find_rack_app(path, &block)
14
+ return found if found
15
+ end
16
+ end
17
+ return nil
18
+ else
19
+ @mapping.each do |host, location, match, app|
20
+ next unless path =~ match && rest = $1
21
+ next unless rest.empty? || rest[0] == ?/
22
+ the_app, the_rest = app, rest
23
+ break
24
+ end
25
+ if the_app
26
+ # we've found one
27
+ if the_rest.empty? or the_rest=='/'
28
+ block ? the_app.find_rack_app(nil, &block) : the_app
29
+ else
30
+ the_app.find_rack_app(the_rest, &block)
31
+ end
32
+ else
33
+ nil
34
+ end
35
+ end
36
+ end
37
+
38
+ # Overrides Delegator._visit
39
+ def _visit(path, block)
40
+ block.call(path, self)
41
+ @mapping.each do |host, location, match, app|
42
+ # seems required on some configurations where rack does not acts
43
+ # as expected (3 arguments and not 4)
44
+ app = match if app.nil?
45
+ unless is_delegate?(app)
46
+ Waw.logger.warn("We found a rack application which is not a delegator on #{path}: #{app.inspect}!")
47
+ next
48
+ end
49
+ app._visit((location.to_s.empty? ? path : path.chomp('/') + location.to_s), block)
50
+ end
51
+ end
52
+
53
+ end # class URLMap
54
+
55
+ end # module Rack
@@ -0,0 +1 @@
1
+ require 'waw/ext/wlang/hosted_language'
@@ -0,0 +1,21 @@
1
+ module WLang
2
+ class HostedLanguage
3
+ include ::Waw::ScopeUtils
4
+
5
+ #
6
+ # Overrides the original version that always raises an UndefinedVariableError
7
+ # to put waw scoping utilities as low-level variables in all wlang scopes as
8
+ # well as installed resources.
9
+ #
10
+ def variable_missing(name)
11
+ if self.respond_to?(name)
12
+ self.send(name)
13
+ elsif resources && resources.has_resource?(name)
14
+ resources[name]
15
+ else
16
+ raise ::WLang::UndefinedVariableError.new(nil, nil, nil, name)
17
+ end
18
+ end
19
+
20
+ end # class HostedLanguage
21
+ end # module WLang
@@ -0,0 +1,8 @@
1
+ require 'waw/fullstate/on_instance'
2
+ require 'waw/fullstate/on_class'
3
+ require 'waw/fullstate/variable'
4
+ module Waw
5
+ module FullState
6
+
7
+ end
8
+ end
@@ -0,0 +1,37 @@
1
+ module Waw
2
+ module FullState
3
+ # Provides the introspection methods for installing fullstate
4
+ # utilities on classes.
5
+ module OnClass
6
+
7
+ # Returns the class full state variables
8
+ def __full_state_variables
9
+ @__full_state_variables ||= {}
10
+ end
11
+
12
+ # Installs a friendly session variable on the controller
13
+ def session_var(name, default_value=nil, &block)
14
+ __full_state_variables[name] = Waw::FullState::Variable.new(name, default_value, &block)
15
+ instance_eval <<-EOF
16
+ class << self
17
+ def #{name}
18
+ __full_state_variables[:#{name}].value(self)
19
+ end
20
+ def #{name}=(arg)
21
+ __full_state_variables[:#{name}].value = arg
22
+ end
23
+ def reset(varname)
24
+ __full_state_variables[varname].reset
25
+ end
26
+ end
27
+ EOF
28
+ end
29
+
30
+ # Installs a query variable with a given block
31
+ def query_var(name, &block)
32
+ session_var(name, nil, &block)
33
+ end
34
+
35
+ end # module OnClasses
36
+ end # module FullState
37
+ end # module Waw
@@ -0,0 +1,27 @@
1
+ module Waw
2
+ module FullState
3
+ # Provides the introspection methods for installing fullstate
4
+ # utilities on instances.
5
+ module OnInstance
6
+
7
+ # Installs a friendly session variable on the controller
8
+ def session_var(name, default_value=nil, &block)
9
+ var = Waw::FullState::Variable.new(name, default_value, &block)
10
+ define_method name do
11
+ var.value(self)
12
+ end
13
+ define_method :"#{name}=" do |arg|
14
+ var.value = arg
15
+ end
16
+ rescue ArgumentError => ex
17
+ raise ex, ex.message, ex.backtrace[1..-1]
18
+ end
19
+
20
+ # Installs a query variable with a given block
21
+ def query_var(name, &block)
22
+ session_var(name, nil, &block)
23
+ end
24
+
25
+ end # module OnInstances
26
+ end # module FullState
27
+ end # module Waw
@@ -0,0 +1,36 @@
1
+ module Waw
2
+ module FullState
3
+ class Variable
4
+ include Waw::ScopeUtils
5
+
6
+ # Creates a variable instance with a default value
7
+ def initialize(name, default_value = nil, &block)
8
+ raise ArgumentError, "Waw variables accept a default value or a block, but not both"\
9
+ unless default_value.nil? or block.nil?
10
+ @name, @default_value = name, (block ? block : default_value)
11
+ end
12
+
13
+ # Resets to the default value
14
+ def reset
15
+ session.unset(@name)
16
+ end
17
+
18
+ # Returns the current value of the variable
19
+ def value(*args)
20
+ if session.has_key?(@name)
21
+ session.get(@name)
22
+ elsif @default_value.is_a?(Proc)
23
+ @default_value.call(*args)
24
+ else
25
+ @default_value
26
+ end
27
+ end
28
+
29
+ # Sets the value of the variable
30
+ def value=(val)
31
+ session.set(@name, val)
32
+ end
33
+
34
+ end # class Variable
35
+ end # module FullState
36
+ end # module Waw
@@ -0,0 +1,6 @@
1
+ require 'waw/kern/freezed_state'
2
+ require 'waw/kern/living_state'
3
+ require 'waw/kern/hooks'
4
+ require 'waw/kern/lifecycle'
5
+ require 'waw/kern/utils'
6
+ require 'waw/kern/app'