Module: Thor::Base::SharedOptionsConcern
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/thor/base/shared_options_concern.rb
Overview
Class Method Summary collapse
-
.find_shared_method_options(*names, groups: nil) ⇒ Hash<Symbol, Thor::SharedOption>
(also: find_shared_options)
Find shared options given names and groups.
-
.include_method_options(*names, groups: nil) ⇒ Hash<Symbol, Thor::SharedOption>
(also: include_options)
Add the SharedOption instances with
namesand ingroupsto the next defined command method. -
.shared_method_option(name, **options) ⇒ Object
(also: shared_option)
Declare a shared method option with an optional groups that can then be added by name or group to commands.
-
.shared_method_options(options = nil) ⇒ Hash<Symbol, Thor::SharedOption] Get all shared options
(also: shared_options)
Hash<Symbol, Thor::SharedOption] Get all shared options.
Class Method Details
.find_shared_method_options(*names, groups: nil) ⇒ Hash<Symbol, Thor::SharedOption> Also known as:
Find shared options given names and groups.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/thor/base/shared_options_concern.rb', line 183 def *names, groups: nil groups_set = Set[*groups] .each_with_object( {} ) do |(name, option), results| match = {} if names.include? name match[:name] = true end match_groups = option.groups & groups_set unless match_groups.empty? match[:groups] = match_groups end unless match.empty? results[name] = { option: option, match: match, } end end end |
.include_method_options(*names, groups: nil) ⇒ Hash<Symbol, Thor::SharedOption> Also known as: include_options
Add the SharedOption instances with names and in groups to the next defined command method.
217 218 219 220 221 222 |
# File 'lib/thor/base/shared_options_concern.rb', line 217 def *names, groups: nil ( *names, groups: groups ). each do |name, result| [name] = Thor::IncludedOption.new **result end end |
.shared_method_option(name, **options) ⇒ Object Also known as:
Declare a shared method option with an optional groups that can then be added by name or group to commands.
The shared options can then be added to methods individually by name and collectively as groups with Thor.include_method_options.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/thor/base/shared_options_concern.rb', line 128 def shared_method_option name, ** # Don't think the `:for` option makes sense... that would just be a # regular method option, right? I guess `:for` could be an array and # apply the option to each command, but it seems like that would just # be better as an extension to the {.method_option} behavior. # # So, we raise if we see it if .key? :for raise ArgumentError, ".shared_method_option does not accept the `:for` option" end build_shared_option(name, ) end |
.shared_method_options(options = nil) ⇒ Hash<Symbol, Thor::SharedOption] Get all shared options Also known as:
Returns Hash<Symbol, Thor::SharedOption] Get all shared options.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/thor/base/shared_options_concern.rb', line 149 def ( = nil) @shared_method_options ||= begin # Reach up the inheritance chain, if there's anyone there if superclass.respond_to? __method__ superclass.send( __method__ ).dup else # Or just default to empty {} end end if # We don't support this (yet at least) raise NotImplementedError, "Bulk set not supported, use .shared_method_option" # build_shared_options(options, @shared_method_options) end @shared_method_options end |