Class: Respect::GlobalDef

Inherits:
Object
  • Object
show all
Defined in:
lib/respect/global_def.rb

Overview

Global context of the schema definition DSL.

This is the base class of all DSL evaluation context. It provides minimal evaluation support. Any methods added to this class will be available in every context of DSL.

You can evaluate a block using the #eval method. Sub-classes must implement the evalulation_result methods (which must returns the result of the evaluation) or provides their own eval methods.

End-users are not supposed to sub-class this class yet. Its API is experimental.

Direct Known Subclasses

ArrayDef, HashDef, ItemsDef, SchemaDef

Constant Summary

@@core_contexts =
Set.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept_name?

Return whether the statements declared in this context accept a name as first argument. All classes not including DefWithoutName accept names.

Returns:

  • (Boolean)


35
36
37
# File 'lib/respect/global_def.rb', line 35

def accept_name?
  !(self < DefWithoutName)
end

+ (Object) core_contexts

Return the list of all classes including CoreStatements.



49
50
51
# File 'lib/respect/global_def.rb', line 49

def core_contexts
  @@core_contexts
end

+ (Object) eval(*args, &block)

Instantiate this evaluation context using the given args and evaluate the given block within it.



28
29
30
# File 'lib/respect/global_def.rb', line 28

def eval(*args, &block)
  new(*args).eval(&block)
end

+ (Object) include_core_statements

Call this method in "def" class willing to offer core statements. Do not include CoreStatements directly.



43
44
45
46
# File 'lib/respect/global_def.rb', line 43

def include_core_statements
  @@core_contexts << self
  include CoreStatements
end

Instance Method Details

- (Boolean) accept_name?

Shortcut to accept_name?.

Returns:

  • (Boolean)


56
57
58
# File 'lib/respect/global_def.rb', line 56

def accept_name?
  self.class.accept_name?
end

- (Object) eval(&block)

Evaluate the given block in the context of this class through a FakeNameProxy with this class as target. #evaluation_result is called at the end to return the result of this evaluation.



64
65
66
67
68
# File 'lib/respect/global_def.rb', line 64

def eval(&block)
  @def_evaluator ||= FakeNameProxy.new(self)
  @def_evaluator.eval(&block)
  evaluation_result
end