Module: Renee::Core::ClassMethods

Includes:
URLGeneration
Included in:
Renee::Core
Defined in:
lib/renee_core.rb

Overview

Class methods that are included in new instances of Renee::Core

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from URLGeneration

#path, #prefix, #register, #url

Instance Attribute Details

#application_blockObject (readonly)

The application block used to create your application.



33
34
35
# File 'lib/renee_core.rb', line 33

def application_block
  @application_block
end

Instance Method Details

#app { ... } ⇒ Object

Allows you to set the #application_block on your class.

Yields:

  • The application block



43
44
45
46
47
48
49
50
# File 'lib/renee_core.rb', line 43

def app(&app)
  @application_block = app
  setup do
    register_variable_type :integer, IntegerMatcher
    register_variable_type :int, :integer
  end
  self
end

#call(env) ⇒ Object

Provides a rack interface compliant call method. This method creates a new instance of your class and calls

call on it.



37
38
39
# File 'lib/renee_core.rb', line 37

def call(env)
  new.call(env)
end

#register_variable_type(name, matcher) ⇒ Renee::Core::Matcher

Registers a new variable type for use within Routing#variable and others.

Parameters:

  • name (Symbol)

    The name of the variable.

  • matcher (Regexp)

    A regexp describing what part of an arbitrary string to capture.

Returns:



67
68
69
70
71
72
73
74
75
76
# File 'lib/renee_core.rb', line 67

def register_variable_type(name, matcher)
  matcher = case matcher
  when Matcher then matcher
  when Array   then Matcher.new(matcher.map{|m| variable_types[m]})
  when Symbol  then variable_types[matcher]
  else              Matcher.new(matcher)
  end
  matcher.name = name
  variable_types[name] = matcher
end

#setup(&blk) ⇒ Object

Runs class methods on your application.



53
54
55
56
# File 'lib/renee_core.rb', line 53

def setup(&blk)
  instance_eval(&blk)
  self
end

#variable_typesObject

The currently available variable types you've defined.



59
60
61
# File 'lib/renee_core.rb', line 59

def variable_types
  @variable_types ||= {}
end