Class: Tardvig::Toolkit
- Inherits:
-
Object
- Object
- Tardvig::Toolkit
- Defined in:
- lib/tardvig/toolkit.rb
Overview
Container which initializes and gives you access to its tools (objects). Useful when you need to do a DSL
Class Method Summary collapse
-
.tool(name, tool_itself = nil) ⇒ Object
Adds a new tool (object).
-
.tools ⇒ Hash
Your tools.
Instance Method Summary collapse
-
#create_tools ⇒ Object
You can create tools to use them through this method if you have not done this on toolkit initialize.
-
#initialize(params = {}) ⇒ Toolkit
constructor
Creates a new toolbox instance and initializes its tools.
Constructor Details
#initialize(params = {}) ⇒ Toolkit
Creates a new toolbox instance and initializes its tools.
31 32 33 34 35 |
# File 'lib/tardvig/toolkit.rb', line 31 def initialize(params = {}) default_params = { initialize_tools: true } @params = default_params.merge params create_tools if @params[:initialize_tools] end |
Class Method Details
.tool(name, tool_itself = nil) ⇒ Object
Adds a new tool (object).
If the given object has either ‘call` or `new` methods then result of the method execution will be used as a tool instead. When the `call` method of your tool is executed, the toolkit will be given as the first argument and the `params` (see #initialize) as the second.
19 20 21 |
# File 'lib/tardvig/toolkit.rb', line 19 def tool(name, tool_itself = nil) tools[name] = tool_itself || Proc.new end |
.tools ⇒ Hash
Returns your tools.
7 8 9 |
# File 'lib/tardvig/toolkit.rb', line 7 def tools @tools ||= {} end |
Instance Method Details
#create_tools ⇒ Object
You can create tools to use them through this method if you have not done this on toolkit initialize.
39 40 41 |
# File 'lib/tardvig/toolkit.rb', line 39 def create_tools create_tools_readers end |