Module: HammerCLIKatello::IdNameOptionsValidator
- Defined in:
- lib/hammer_cli_katello/id_name_options_validator.rb
Class Method Summary collapse
- .build_child_options(record_name) ⇒ Object
- .build_options(record_name, options) ⇒ Object
- .build_parent_options(parent) ⇒ Object
Instance Method Summary collapse
-
#validate_id_or_name(record_name = nil) ⇒ Object
This method simply checks that either id or name is supplied.
-
#validate_id_or_name_with_parent(record_name = nil, parent: 'organization', required: true) ⇒ Object
This is a method that requires: 1.
Class Method Details
.build_child_options(record_name) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/hammer_cli_katello/id_name_options_validator.rb', line 47 def self.(record_name) if record_name.nil? %w(option_id option_name) else IdNameOptionsValidator.(record_name, %w(id name)) end end |
.build_options(record_name, options) ⇒ Object
67 68 69 70 71 |
# File 'lib/hammer_cli_katello/id_name_options_validator.rb', line 67 def self.(record_name, ) .map do |opt| "option_#{record_name}_#{opt}" end end |
.build_parent_options(parent) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hammer_cli_katello/id_name_options_validator.rb', line 55 def self.(parent) if parent.is_a?(String) || parent.is_a?(Symbol) opts = parent.to_s == 'organization' ? %w(id name label) : %w(id name) elsif parent.is_a?(Hash) parent, opts = parent.first.to_a else raise "Unkown parent class: #{parent.class} for #{parent}" end IdNameOptionsValidator.(parent, opts) end |
Instance Method Details
#validate_id_or_name(record_name = nil) ⇒ Object
This method simply checks that either id or name is supplied
Some examples:
# checks for a –id or –name option validate_id_or_name # checks for –content-view-id or –content-view-name validate_id_or_name :content_view
39 40 41 42 43 44 45 |
# File 'lib/hammer_cli_katello/id_name_options_validator.rb', line 39 def validate_id_or_name(record_name = nil) = IdNameOptionsValidator.(record_name) do any(*).required end end |
#validate_id_or_name_with_parent(record_name = nil, parent: 'organization', required: true) ⇒ Object
This is a method that requires:
-
either name or id has been supplied
-
if name is supplied, parent id/name/etc is also required
Normally the parent will be organization as with products, content views, etc but this could also apply to repos for example whose names are unique per product
Some examples:
validate_id_or_name_with_parent validate_id_or_name_with_parent :content_view validate_id_or_name_with_parent :repository, parent: ‘product’, required: false validate_id_or_name_with_parent :content_view, parent: [‘id’, ‘name’]
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hammer_cli_katello/id_name_options_validator.rb', line 17 def validate_id_or_name_with_parent(record_name = nil, parent: 'organization', required: true) = IdNameOptionsValidator.(record_name) = IdNameOptionsValidator.(parent) :before, 'IdResolution' do any(*).required if required if (name_option = .detect { |opt| opt.end_with?('_name') }) && option(name_option).exist? any(*).required end end end |