Module: Aquarium::Utils::OptionsUtils::ClassMethods
- Defined in:
- lib/aquarium/utils/options_utils.rb
Instance Method Summary collapse
-
#add_exclude_options_for(option, options_hash) ⇒ Object
Service method that adds a new canonical option and corresponding array with “exclude_” prepended to all values.
-
#add_prepositional_option_variants_for(option, options_hash) ⇒ Object
Service method that adds a new canonical option and corresponding array with “preposition” prefixes, e.g., “on_”, “for_”, etc.
- #canonical_option_accessor(*canonical_option_key_list) ⇒ Object
- #canonical_option_reader(*canonical_option_key_list) ⇒ Object
- #canonical_option_writer(*canonical_option_key_list) ⇒ Object
- #canonical_options_given_methods(canonical_options) ⇒ Object
Instance Method Details
#add_exclude_options_for(option, options_hash) ⇒ Object
Service method that adds a new canonical option and corresponding array with “exclude_” prepended to all values. The new options are added to the input hash.
196 197 198 199 |
# File 'lib/aquarium/utils/options_utils.rb', line 196 def option, all_variants = [option].dup ["exclude_#{option}"] = all_variants.map {|x| "exclude_#{x}"} end |
#add_prepositional_option_variants_for(option, options_hash) ⇒ Object
Service method that adds a new canonical option and corresponding array with “preposition” prefixes, e.g., “on_”, “for_”, etc. prepended to all values. The new options are added to the input hash.
204 205 206 207 208 209 210 211 |
# File 'lib/aquarium/utils/options_utils.rb', line 204 def add_prepositional_option_variants_for option, all_variants = [option].dup + [option] OptionsUtils.universal_prepositions.each do |prefix| all_variants.each do |variant| [option] << "#{prefix}_#{variant}" end end end |
#canonical_option_accessor(*canonical_option_key_list) ⇒ Object
174 175 176 177 |
# File 'lib/aquarium/utils/options_utils.rb', line 174 def canonical_option_accessor *canonical_option_key_list canonical_option_reader *canonical_option_key_list canonical_option_writer *canonical_option_key_list end |
#canonical_option_reader(*canonical_option_key_list) ⇒ Object
156 157 158 159 160 161 162 163 164 |
# File 'lib/aquarium/utils/options_utils.rb', line 156 def canonical_option_reader *canonical_option_key_list return if canonical_option_key_list.nil? or canonical_option_key_list.empty? keys = canonical_option_key_list keys.each do |name| define_method(name) do @specification[name] end end end |
#canonical_option_writer(*canonical_option_key_list) ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'lib/aquarium/utils/options_utils.rb', line 165 def canonical_option_writer *canonical_option_key_list return if canonical_option_key_list.nil? or canonical_option_key_list.empty? keys = canonical_option_key_list keys.each do |name| define_method("#{name}=") do |value| @specification[name] = make_set(make_array(value)) end end end |
#canonical_options_given_methods(canonical_options) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/aquarium/utils/options_utils.rb', line 179 def keys = .respond_to?(:keys) ? .keys : (keys + OptionsUtils::).each do |name| module_eval(<<-EOF, __FILE__, __LINE__) def #{name}_given @specification[:#{name}] end def #{name}_given? not (#{name}_given.nil? or #{name}_given.empty?) end EOF end end |