Class: Waw::StaticController::WawAccess::DSL
- Includes:
- Validation
- Defined in:
- lib/waw/controllers/static/waw_access_dsl.rb
Overview
Domain specific language for .wawaccess language
Constant Summary
Constants included from Validation
Instance Method Summary collapse
-
#inherits(which = "unknown") ⇒ Object
Installs the inherits strategy.
-
#initialize(wawaccess) ⇒ DSL
constructor
Creates a new DSL instance.
-
#match(*patterns, &block) ⇒ Object
Serve some patterns.
-
#matcher(name, &predicate) ⇒ Object
Installs a matcher.
-
#root ⇒ Object
Returns a validator that matches the root of the wawaccess tree.
-
#strategy(which = :unknown) ⇒ Object
Installs the default strategy.
-
#wawaccess(&block) ⇒ Object
Starts a wawaccess file.
Methods included from Validation
included, method_missing, ruby_class_to_validator, signature, validator, validator_for_ruby_class
Methods included from Validation::Helpers
#all_missing?, #any_missing?, #argument_safe, #error, #is_missing?, #missings_to_nil, #no_missing?, #to_validator
Constructor Details
Instance Method Details
#inherits(which = "unknown") ⇒ Object
Installs the inherits strategy
41 42 43 44 |
# File 'lib/waw/controllers/static/waw_access_dsl.rb', line 41 def inherits(which = "unknown") raise WawError, "#{@wawaccess.identifier}: unrecognized wawaccess inherits #{which}" unless [true, false].include?(which) @wawaccess.inherits = which end |
#match(*patterns, &block) ⇒ Object
Serve some patterns
47 48 49 50 51 52 |
# File 'lib/waw/controllers/static/waw_access_dsl.rb', line 47 def match(*patterns, &block) patterns = patterns.compact raise WawError, "#{@wawaccess.identifier}: missing patterns in wawaccess.match call" if patterns.empty? raise WawError, "#{@wawaccess.identifier}: missing block in wawaccess.match call" if block.nil? @wawaccess.add_serve(patterns, &block) end |
#matcher(name, &predicate) ⇒ Object
Installs a matcher
21 22 23 24 25 26 |
# File 'lib/waw/controllers/static/waw_access_dsl.rb', line 21 def matcher(name, &predicate) @matchers[name] = Matcher.new(@wawaccess, predicate) (class << self; self; end).send(:define_method,name) do @matchers[name] end end |
#root ⇒ Object
Returns a validator that matches the root of the wawaccess tree
16 17 18 |
# File 'lib/waw/controllers/static/waw_access_dsl.rb', line 16 def root Waw::Validation.validator{|served_file| File.(served_file) == File.(@wawaccess.root.folder)} end |
#strategy(which = :unknown) ⇒ Object
Installs the default strategy
35 36 37 38 |
# File 'lib/waw/controllers/static/waw_access_dsl.rb', line 35 def strategy(which = :unknown) raise WawError, "#{@wawaccess.identifier}: unrecognized wawaccess strategy #{which}" unless [:deny_all, :allow_all].include?(which) @wawaccess.strategy = which end |