Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from 0exp/release/v0.3.0
[release] 0.2.0 => 0.3.0
- Loading branch information
Showing
14 changed files
with
251 additions
and
84 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
language: ruby | ||
rvm: | ||
- 2.2.9 | ||
- 2.3.6 | ||
- 2.4.3 | ||
- 2.5.0 | ||
- 2.2.10 | ||
- 2.3.7 | ||
- 2.4.4 | ||
- 2.5.1 | ||
- ruby-head | ||
|
||
sudo: false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'bundler/setup' | ||
require 'symbiont/ruby' | ||
require 'symbiont' | ||
|
||
require 'pry' | ||
Pry.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
# frozen_string_literal: true | ||
|
||
module Symbiont | ||
# Special object that wraps your proc object from any place and provides | ||
# an ability to invoke this proc object lazily inside an any series of contexts. | ||
# | ||
# @api public | ||
# @since 0.3.0 | ||
class Isolator | ||
# Is raised when closure is not provided. | ||
# | ||
# @see #initialize | ||
# | ||
# @api public | ||
# @since 0.3.0 | ||
UnprovidedClosureAttributeError = Class.new(ArgumentError) | ||
|
||
# Proc object that will be evaluated in many contexts: initial, outer and kernel. | ||
# Will be used as an outer-context for the method resolution. | ||
# | ||
# @return [Proc] | ||
# | ||
# @api public | ||
# @since 0.3.0 | ||
attr_reader :closure | ||
|
||
# An array of symbols that represents the direction of contexts. Used by default. | ||
# | ||
# @return [Array<Symbol>] | ||
# | ||
# @api public | ||
# @since 0.3.0 | ||
attr_reader :default_direction | ||
|
||
# Instantiates isolator object with corresponding default direction and closure. | ||
# | ||
# @option default_direction [Array<Symbol>] | ||
# An array of symbols that represents the direction of contexts which is used as default | ||
# context direction. Symbiont::Trigger::IOK is chosen by default. | ||
# @param closure [Proc] | ||
# Proc object that will be evaluated in many contexts: initial, outer and kernel. | ||
# Will be used as an outer-context for the method resolution. | ||
# | ||
# @api public | ||
# @since 0.3.0 | ||
def initialize(default_direction: Trigger::IOK, &closure) | ||
raise UnprovidedClosureAttributeError, 'You should provide a closure' unless block_given? | ||
|
||
@default_direction = default_direction | ||
@closure = closure | ||
end | ||
|
||
# Starts execution of a proc object in the context of the passed object with the selected | ||
# direction of method dispatching. Delegates execution to a public trigger. | ||
# | ||
# @param required_contexts [Array<Object>] | ||
# A set of objects that should be used as the main context series for method resolving | ||
# algorithm. | ||
# @param direction [Array<Symbol>] | ||
# An array of symbols that represents the direction of contexts. | ||
# @return [void] | ||
# | ||
# @see Symbiont::Trigger#__evaluate__ | ||
# @see Symbiont::PublicTrigger | ||
# | ||
# @api public | ||
# @since 0.3.0 | ||
def evaluate(*required_contexts, direction: default_direction) | ||
public_trigger(*required_contexts, direction: direction).__evaluate__ | ||
end | ||
|
||
# Starts execution of a proc object in the context of the passed object with the selected | ||
# direction of method dispatching. Delegates execution to a private trigger. | ||
# | ||
# @param required_contexts [Array<Object>] | ||
# A set of objects that should be used as the main context series for method resolving | ||
# algorithm. | ||
# @param direction [Array<Symbol>] | ||
# An array of symbols that represents the direction of contexts. | ||
# @return [void] | ||
# | ||
# @see Symbiont::Trigger#__evaluate__ | ||
# @see Symbiont::PrivateTrigger | ||
# | ||
# @api public | ||
# @since 0.3.0 | ||
def evaluate_private(*required_contexts, direction: default_direction) | ||
private_trigger(*required_contexts, direction: direction).__evaluate__ | ||
end | ||
|
||
# Gets the method object taken from the context that can respond to it. | ||
# Considers only public methods. | ||
# | ||
# @param method_name [Symbol,String] A name of required method. | ||
# @param required_contexts [Array<Object>] | ||
# A set of objects that should be used as the main context series for method resolving | ||
# algorithm. | ||
# @param direction [Array<Symbol>] | ||
# An array of symbols that represents the direction of contexts. | ||
# @return [Method] | ||
# | ||
# @see Symbiont::PublicTrigger | ||
# @see Symbiont::Trigger#method | ||
# | ||
# @api public | ||
# @since 0.3.0 | ||
def public_method(method_name, *required_contexts, direction: default_direction) | ||
public_trigger(*required_contexts, direction: direction).method(method_name) | ||
end | ||
|
||
# Gets the method object taken from the context that can respond to it. | ||
# Considers private methods and public methods. | ||
# | ||
# @param method_name [Symbol,String] A name of required method. | ||
# @param required_contexts [Array<Object>] | ||
# A set of objects that should be used as the main context series for method resolving | ||
# algorithm. | ||
# @param direction [Array<Symbol>] | ||
# An array of symbols that represents the direction of contexts. | ||
# @return [Method] | ||
# | ||
# @see Symbiont::PrivateTrigger | ||
# @see Symbiont::Trigger#method | ||
# | ||
# @api public | ||
# @since 0.3.0 | ||
def private_method(method_name, *required_contexts, direction: default_direction) | ||
private_trigger(*required_contexts, direction: direction).method(method_name) | ||
end | ||
|
||
private | ||
|
||
# Factory method that instantiates a public trigger with the desired execution context, | ||
# the direction of method dispatching and the closure that needs to be performed. | ||
# | ||
# @param required_contexts [Array<Object>] | ||
# A set of objects that should be used as the main context series for method resolving | ||
# algorithm. | ||
# @param direction [Array<Symbol>] | ||
# An array of symbols that represents the direction of contexts. Possible values: | ||
# | ||
# - Symbiont::IOK | ||
# - Symbiont::OIK | ||
# - Symbiont::OKI | ||
# - Symbiont::IKO | ||
# - Symbiont::KOI | ||
# - Symbiont::KIO | ||
# @return [Symbiont::PublicTrigger] | ||
# | ||
# @see Symbiont::PublicTrigger | ||
# @see Symbiont::Trigger | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
def public_trigger(*required_contexts, direction: default_direction) | ||
PublicTrigger.new(*required_contexts, context_direction: direction, &closure) | ||
end | ||
|
||
# Factory method that instantiates a private trigger with the desired execution context, | ||
# the direction of method dispatching and the closure that needs to be performed. | ||
# | ||
# @param required_contexts [Array<Object>] | ||
# A set of objects that should be used as the main context series for method resolving | ||
# algorithm. | ||
# @param direction [Array<Symbol>] | ||
# An array of symbols that represents the direction of contexts. Possible values: | ||
# | ||
# - Symbiont::IOK | ||
# - Symbiont::OIK | ||
# - Symbiont::OKI | ||
# - Symbiont::IKO | ||
# - Symbiont::KOI | ||
# - Symbiont::KIO | ||
# @return [Symbiont::PrivateTrigger] | ||
# | ||
# @see Symbiont::PrivateTrigger | ||
# @see Symbiont::Trigger | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
def private_trigger(*required_contexts, direction: default_direction) | ||
PrivateTrigger.new(*required_contexts, context_direction: direction, &closure) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ module Symbiont | |
# | ||
# @api public | ||
# @since 0.1.0 | ||
VERSION = '0.2.0' | ||
VERSION = '0.3.0' | ||
end |
Oops, something went wrong.