module Thor::Base::SharedConcern
Share stuff… define {Thor::Argument}, {Thor::Option} and whatever else you like once then apply those definitions to many commands.
Public Instance Methods
copy_shared_defs_to(array, inherited: true)
click to toggle source
# File lib/thor/base/shared_concern.rb, line 47 def copy_shared_defs_to array, inherited: true array.push *this_class_shared_defs_ref if inherited && superclass && superclass.respond_to?( :copy_shared_defs_to, true ) superclass.copy_shared_defs_to array end array end
def_shared(kind, name:, groups: nil, **options)
click to toggle source
# File lib/thor/base/shared_concern.rb, line 69 def def_shared kind, name:, groups: nil, **options this_class_shared_defs_ref << { name: name.to_sym, kind: kind.to_sym, groups: Set[*groups].freeze, options: options.freeze, }.freeze end
include_shared(selector, **overrides)
click to toggle source
# File lib/thor/base/shared_concern.rb, line 79 def include_shared selector, **overrides defs = shared_defs.select &selector if defs.empty? logger.warn "No shared parameters found", selector: selector, class: self end defs.each do |name:, kind:, groups:, options:| send kind, name, **options.merge( overrides ) end end
shared_defs(inherited: true)
click to toggle source
# File lib/thor/base/shared_concern.rb, line 62 def shared_defs inherited: true [].tap do |array| copy_shared_defs_to array, inherited: inherited end end