Module: Thor::Base::SharedConcern
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/thor/base/shared_concern.rb
Overview
Class Method Summary collapse
- .def_shared(kind, name:, groups: nil, **options) ⇒ Object
-
.find_shared(*names, kinds: nil, groups: nil) ⇒ Hash<Symbol, Thor::SharedOption>
Find shared options given names and groups.
- .include_shared(*names, kinds: nil, groups: nil, **overrides) ⇒ Object
-
.shared_defs ⇒ Object
.
Class Method Details
.def_shared(kind, name:, groups: nil, **options) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/thor/base/shared_concern.rb', line 51 def def_shared kind, name:, groups: nil, ** shared_defs << { name: name.to_s, kind: kind, groups: Set[*groups], options: , } end |
.find_shared(*names, kinds: nil, groups: nil) ⇒ Hash<Symbol, Thor::SharedOption>
Find shared options given names and groups.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/thor/base/shared_concern.rb', line 80 def find_shared *names, kinds: nil, groups: nil groups_set = Set[*groups] kinds_set = Set[*kinds] names.map! &:to_s results = [] shared_defs.each do |name:, kind:, groups:, options:| match = {} if names.include? name match[:name] = true end match_groups = groups & groups_set unless match_groups.empty? match[:groups] = match_groups end if kinds_set.include? kind match[:kind] = true end unless match.empty? results << { name: name, kind: kind, groups: groups, options: , } end end end |
.include_shared(*names, kinds: nil, groups: nil, **overrides) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/thor/base/shared_concern.rb', line 61 def include_shared *names, kinds: nil, groups: nil, **overrides find_shared( *names, kinds: kinds, groups: groups ). each do |name:, kind:, groups:, options:| send kind, name, **.merge( overrides ) end end |
.shared_defs ⇒ Object
38 39 40 |
# File 'lib/thor/base/shared_concern.rb', line 38 def shared_defs @shared_defs ||= [] end |