Class: Guard::Internals::Scope
- Inherits:
-
Object
- Object
- Guard::Internals::Scope
- Defined in:
- lib/guard/internals/scope.rb
Instance Method Summary collapse
- #from_interactor(scope) ⇒ Object
-
#grouped_plugins(scope = { plugins: [], groups: [] }) ⇒ Object
TODO: refactor.
-
#initialize ⇒ Scope
constructor
A new instance of Scope.
- #titles(scope = nil) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Scope
Returns a new instance of Scope.
7 8 9 10 |
# File 'lib/guard/internals/scope.rb', line 7 def initialize @interactor_plugin_scope = [] @interactor_group_scope = [] end |
Instance Method Details
#from_interactor(scope) ⇒ Object
51 52 53 54 |
# File 'lib/guard/internals/scope.rb', line 51 def from_interactor(scope) @interactor_plugin_scope = Array(scope[:plugins]) @interactor_group_scope = Array(scope[:groups]) end |
#grouped_plugins(scope = { plugins: [], groups: [] }) ⇒ Object
TODO: refactor
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/guard/internals/scope.rb', line 20 def grouped_plugins(scope = { plugins: [], groups: [] }) items = nil plugins = _find_non_empty_scope(:plugins, scope) if plugins items = Array(plugins).map { |plugin| _instantiate(:plugin, plugin) } end unless items # TODO: no coverage here!! found = _find_non_empty_scope(:groups, scope) found ||= Guard.state.session.groups.all groups = Array(found).map { |group| _instantiate(:group, group) } if groups.any? { |g| g.name == :common } items = groups else items = ([_instantiate(:group, :common)] + Array(found)).compact end end items.map do |plugin_or_group| group = nil plugins = [plugin_or_group] if plugin_or_group.is_a?(Group) # TODO: no coverage here! group = plugin_or_group plugins = Guard.state.session.plugins.all(group: group.name) end [group, plugins] end end |
#titles(scope = nil) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/guard/internals/scope.rb', line 56 def titles(scope = nil) hash = scope || to_hash plugins = hash[:plugins] groups = hash[:groups] return plugins.map(&:title) unless plugins.nil? || plugins.empty? return hash[:groups].map(&:title) unless groups.nil? || groups.empty? ["all"] end |
#to_hash ⇒ Object
12 13 14 15 16 17 |
# File 'lib/guard/internals/scope.rb', line 12 def to_hash { plugins: _hashify_scope(:plugin), groups: _hashify_scope(:group) }.dup.freeze end |