Total Complexity | 3 |
Total Lines | 26 |
Duplicated Lines | 0 % |
1 | require "thor/core_ext/hash_with_indifferent_access" |
||
3 | module Carrasco |
||
4 | class CommandBuilder |
||
5 | def from_config(config) |
||
6 | config = Thor::CoreExt::HashWithIndifferentAccess.new(config) |
||
7 | klass = Class.new(Thor) |
||
8 | |||
9 | build_commands(config[:commands] || [], klass) |
||
10 | build_grups(config[:groups] || [], klass) |
||
11 | |||
12 | klass |
||
13 | end |
||
14 | |||
15 | private |
||
16 | |||
17 | def build_commands(commands, klass) |
||
18 | commands.each do |method, options| |
||
19 | command = Command.new(method, options) |
||
20 | command.inject_into_class(klass) |
||
21 | end |
||
22 | end |
||
23 | |||
24 | def build_grups(groups, klass) |
||
25 | groups.each do |group_name, options| |
||
26 | Group.new(group_name, options).inject_into_class(klass) |
||
27 | end |
||
28 | end |
||
29 | end |
||
31 |