Class: Waw::StaticController::WawAccess::DSL

Inherits:
Object
  • Object
show all
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

Validation::Array

Instance Method Summary collapse

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

#initialize(wawaccess) ⇒ DSL

Creates a new DSL instance

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/waw/controllers/static/waw_access_dsl.rb', line 9

def initialize(wawaccess)
  raise ArgumentError, "wawaccess cannot be nil" unless WawAccess===wawaccess
  @wawaccess = wawaccess
  @matchers = {}
end

Instance Method Details

#inherits(which = "unknown") ⇒ Object

Installs the inherits strategy

Raises:



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

Raises:



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

#rootObject

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.expand_path(served_file) == File.expand_path(@wawaccess.root.folder)}
end

#strategy(which = :unknown) ⇒ Object

Installs the default strategy

Raises:



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

#wawaccess(&block) ⇒ Object

Starts a wawaccess file

Raises:



29
30
31
32
# File 'lib/waw/controllers/static/waw_access_dsl.rb', line 29

def wawaccess(&block)
  raise WawError, "#{@wawaccess.identifier}: missing block in wawaccess call" unless block
  self.instance_eval(&block)
end