summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-01-08 09:17:10 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-01-08 09:17:10 +0100
commitd59521f3bec769dfe35f1d822617998468f78d7d (patch)
treead0bd822bb883c1d48556cb3c9b8059f676b2a8b /lib
parent8b5ac512744905424c191ea56124a0e7b9f1f787 (diff)
downloadzorglub-d59521f3bec769dfe35f1d822617998468f78d7d.zip
zorglub-d59521f3bec769dfe35f1d822617998468f78d7d.tar.gz
inherited_vars in cli_vals, fix and comment
Diffstat (limited to 'lib')
-rw-r--r--lib/zorglub/node.rb55
1 files changed, 29 insertions, 26 deletions
diff --git a/lib/zorglub/node.rb b/lib/zorglub/node.rb
index 5421046..8fe1e4e 100644
--- a/lib/zorglub/node.rb
+++ b/lib/zorglub/node.rb
@@ -154,59 +154,60 @@ module Zorglub
"You are being redirected, please follow this link to: <a href='#{target}'>#{target}</a>!"
end
#
- # inherited vars, they can be modified at class level only
+ # class level inherited values are key=>array, copied at inheritance
+ # so they can be extanded at class level
+ # values are copied from class into instance at object creation
+ # so that can be extanded without modifying class level values
+ # typical usage are css or js inclusions
#
- @inherited_vars = { }
+ @cli_vals = { }
#
class << self
#
- attr_reader :inherited_vars
+ attr_reader :cli_vals
#
- def inherited_var sym, *args
- var = @inherited_vars[sym] ||=[]
+ def cli_val sym, *args
+ vals = @cli_vals[sym] ||=[]
unless args.empty?
- var.concat args
- var.uniq!
+ vals.concat args
+ vals.uniq!
end
- var
+ vals
end
#
end
#
- def inherited_var sym, *args
- @instance_inherited_vars ||={}
- var= @instance_inherited_vars[sym] ||= self.class.inherited_vars[sym].clone || []
+ def cli_val sym, *args
+ vals = @cli_vals[sym] ||=[]
unless args.empty?
- var.concat args
- var.uniq!
+ vals.concat args
+ vals.uniq!
end
- var
+ vals
end
#
# before_all and after_all hooks
#
- @inherited_vars[:before_all] = []
- @inherited_vars[:after_all] = []
+ @cli_vals[:before_all] = []
+ @cli_vals[:after_all] = []
class << self
#
- attr_reader :hooks
- #
def call_before_hooks obj
- @inherited_vars[:before_all].each do |blk| blk.call obj end
+ @cli_vals[:before_all].each do |blk| blk.call obj end
end
#
def before_all &blk
- @inherited_vars[:before_all]<< blk
- @inherited_vars[:before_all].uniq!
+ @cli_vals[:before_all]<< blk
+ @cli_vals[:before_all].uniq!
end
#
def call_after_hooks obj
- @inherited_vars[:after_all].each do |blk| blk.call obj end
+ @cli_vals[:after_all].each do |blk| blk.call obj end
end
#
def after_all &blk
- @inherited_vars[:after_all]<< blk
- @inherited_vars[:after_all].uniq!
+ @cli_vals[:after_all]<< blk
+ @cli_vals[:after_all].uniq!
end
#
end
@@ -218,8 +219,8 @@ module Zorglub
def inherited sub
sub.engine! engine||(self==Zorglub::Node ? UNDEFINED : nil )
sub.layout! layout||(self==Zorglub::Node ? UNDEFINED : nil )
- sub.instance_variable_set :@inherited_vars, {}
- @inherited_vars.each do |s,v| sub.inherited_var s, *v end
+ sub.instance_variable_set :@cli_vals, {}
+ @cli_vals.each do |s,v| sub.cli_val s, *v end
end
#
def call env
@@ -256,6 +257,8 @@ module Zorglub
@options = options
@request = Rack::Request.new env
@response = Rack::Response.new
+ @cli_vals ={}
+ self.class.cli_vals.each do |s,v| cli_val s, *v end
end
#
def state state=nil