Module: Mustermann
- Included in:
- Pattern
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/error.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/caster.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/concat.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/mapper.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/pattern.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/regular.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/version.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/ast/node.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/expander.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/identity.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/composite.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/ast/parser.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/to_pattern.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/ast/pattern.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/ast/compiler.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/ast/expander.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/equality_map.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/regexp_based.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/simple_match.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/pattern_cache.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/ast/boundaries.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/ast/translator.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/ast/validation.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra/parser.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/ast/transformer.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/ast/param_scanner.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra/try_convert.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra/safe_renderer.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/ast/template_generator.rb
Overview
Namespace and main entry point for the Mustermann library.
Under normal circumstances the only external API entry point you should be using is Mustermann.new.
Defined Under Namespace
Modules: AST, ToPattern Classes: Composite, Concat, EqualityMap, Expander, Identity, Mapper, Pattern, PatternCache, RegexpBased, Regular, SimpleMatch, Sinatra
Constant Summary collapse
- DEFAULT_TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Type to use if no type is given.
:sinatra
- Error =
Raised if anything goes wrong while generating a Pattern.
Class.new(StandardError)
- CompileError =
Raised if anything goes wrong while compiling a Pattern.
Class.new(Error)
- ParseError =
Raised if anything goes wrong while parsing a Pattern.
Class.new(Error)
- ExpandError =
Raised if anything goes wrong while expanding a Pattern.
Class.new(Error)
Class Method Summary collapse
-
.[](name) ⇒ Class, #new
Maps a type to its factory.
-
.new(*input, type: DEFAULT_TYPE, operator: :|, **options) ⇒ Mustermann::Pattern
Creates a new pattern based on input.
Class Method Details
.[](name) ⇒ Class, #new
Maps a type to its factory.
89 90 91 92 93 94 95 96 97 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann.rb', line 89 def self.[](name) return name if name.respond_to? :new @types.fetch(normalized = normalized_type(name)) do @mutex.synchronize do error = try_require "mustermann/#{normalized}" @types.fetch(normalized) { raise ArgumentError, "unsupported type %p#{" (#{error.})" if error}" % name } end end end |
.new(*input, type: DEFAULT_TYPE, operator: :|, **options) ⇒ Mustermann::Pattern
Creates a new pattern based on input.
-
From Pattern: returns given pattern.
-
From String: creates a pattern from the string, depending on type option (defaults to Sinatra)
-
From Regexp: creates a Regular pattern.
-
From Symbol: creates a Sinatra pattern with a single named capture named after the input.
-
From an Array or multiple inputs: creates a new pattern from each element, combines them to a Composite.
-
From anything else: Will try to call to_pattern on it or raise a TypeError.
Note that if the input is a Pattern, Regexp or Symbol, the type option is ignored and if to_pattern is called on the object, the type will be handed on but might be ignored by the input object.
If you want to enforce the pattern type, you should create them via their expected class.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann.rb', line 62 def self.new(*input, type: DEFAULT_TYPE, operator: :|, **) type ||= DEFAULT_TYPE input = input.first if input.size < 2 case input when Pattern then input when Regexp then self[:regexp].new(input, **) when String then self[type].new(input, **) when Symbol then self[:sinatra].new(input.inspect, **) when Array then input.map { |i| new(i, type: type, **) }.inject(operator) else pattern = input.to_pattern(type: type, **) if input.respond_to? :to_pattern raise TypeError, "#{input.class} can't be coerced into Mustermann::Pattern" if pattern.nil? pattern end end |