Module: Contrast::Components::Scope::InstanceMethods

Overview

Methods defined in C:

For each instance method on a scope, define a forwarder to the scope on the current execution context’s scope. def scope_for_current_ec end;

all the methods bellow are used as forwarders to be executed in the current ec. exp: in_contrast_scope? => scope_for_current_ec.enter_contrast_scope!

Check if we are in contrast scope. def in_contrast_scope? end; check if we are in deserialization scope. def in_deserialization_scope? end; check if we are in split scope. def in_split_scope? end; enter contrast scope. def enter_contrast_scope! end; enter deserialization scope. def enter_deserialization_scope! end; enter split scope. def enter_split_scope! end; check split scope depth. def split_scope_depth end; exit contrast scope. def exit_contrast_scope! end; exit deserialization scope. def exit_deserialization_scope! end; exit split scope. def exit_split_scope! end; Static methods to be used, the cases are defined by the usage from the above methods

check if are in specific scope. def in_scope? name end; enter specific scope. def enter_scope! name end; exit specific scope. def exit_cope! name end;

Returns:

  • (Boolean)

    check if we are in contrast scope if the scope is above 0 return true.

  • (Boolean)

    check if we are in contrast scope if the scope is above 0 return true.

  • (Boolean)

    check if we are in contrast scope if the scope is above 0 return true.

  • (Boolean)

    check if we are in passed scope.

Instance Method Summary collapse

Instance Method Details

#contrast_enter_method_scopes!(scopes_to_enter) ⇒ Object

Note:

def enter_method_scope! scopes_to_enter scopes_to_enter.each do |scope|

enter_scope!(scope)

method_policy#scopes_to_enter for the scope current method policy

 end
end

Parameters:

  • self

    VALUE

  • scopes_to_enter

    VALUE [Array<Symbol>] Scopes form



592
593
594
595
596
597
598
599
600
601
602
603
604
# File 'ext/cs__scope/cs__scope.c', line 592

VALUE inst_methods_enter_method_scope(VALUE self, VALUE scopes_to_enter) {
    VALUE scopes_ary, scope;

    scopes_ary = rb_ary_dup(scopes_to_enter);
    scope = rb_ary_pop(scopes_ary);

    while (!RB_TYPE_P(scope, T_NIL)) {
        inst_methods_enter_scope(self, scope);
        scope = rb_ary_pop(scopes_ary);
    }

    return scopes_to_enter;
}

#contrast_exit_method_scopes!(scopes_to_exit) ⇒ Object

Note:

def enter_method_scope! scopes_to_exit scopes_to_exit.each do |scope|

enter_scope!(scope)

method_policy#scopes_to_exit for the scope current method policy

  end
end

Parameters:

  • self

    VALUE

  • scopes_to_exit

    VALUE [Array<Symbol>] Scopes form



620
621
622
623
624
625
626
627
628
629
630
631
632
# File 'ext/cs__scope/cs__scope.c', line 620

VALUE inst_methods_exit_method_scope(VALUE self, VALUE scopes_to_exit) {
    VALUE scopes_ary, scope;

    scopes_ary = rb_ary_dup(scopes_to_exit);
    scope = rb_ary_pop(scopes_ary);

    while (!RB_TYPE_P(scope, T_NIL)) {
        inst_methods_exit_scope(self, scope);
        scope = rb_ary_pop(scopes_ary);
    }

    return scopes_to_exit;
}

#with_app_scopeObject

Enter app scope



134
135
136
137
138
139
# File 'lib/contrast/components/scope.rb', line 134

def with_app_scope
  scope_for_current_ec.exit_contrast_scope!
  yield
ensure
  scope_for_current_ec.enter_contrast_scope!
end

#with_contrast_scopeObject

Forwarder to execute block in contrast scope under current method execution context. On completion exits scope.



108
109
110
111
112
113
# File 'lib/contrast/components/scope.rb', line 108

def with_contrast_scope
  scope_for_current_ec.enter_contrast_scope!
  yield
ensure
  scope_for_current_ec.exit_contrast_scope!
end

#with_deserialization_scopeObject

Forwarder to execute block in deserialization scope under current method execution context. On completion exits scope.



117
118
119
120
121
122
# File 'lib/contrast/components/scope.rb', line 117

def with_deserialization_scope
  scope_for_current_ec.enter_deserialization_scope!
  yield
ensure
  scope_for_current_ec.exit_deserialization_scope!
end

#with_split_scopeObject

Forwarder to execute block in split scope under current method execution context. On completion exits scope.



126
127
128
129
130
131
# File 'lib/contrast/components/scope.rb', line 126

def with_split_scope
  scope_for_current_ec.enter_split_scope!
  yield
ensure
  scope_for_current_ec.exit_split_scope!
end