Module: OpenStudio::Extension
- Defined in:
- lib/openstudio/extension.rb,
lib/openstudio/extension/runner.rb,
lib/openstudio/extension/version.rb,
lib/openstudio/extension/rake_task.rb,
lib/openstudio/extension/runner_config.rb
Defined Under Namespace
Classes: Extension, RakeTask, Runner, RunnerConfig
Constant Summary collapse
- VERSION =
'0.6.0.rc1'.freeze
Class Method Summary collapse
-
.all_extensions ⇒ Object
Module method to return all classes derived from OpenStudio::Extension::Extension Note all extension classes must be loaded before calling this method.
-
.all_file_dirs ⇒ Object
Module method to return file directories from all extensions.
-
.all_measure_dirs ⇒ Object
Module method to return measure directories from all extensions.
-
.check_for_name_conflicts ⇒ Object
Module method to check for duplicate file, measure, or measure resource names across all extensions.
-
.configure_osw(in_osw) ⇒ Object
Module method used to configure an input OSW with paths to all OpenStudio::Extension measure and file directories.
-
.measure_in_osw(osw, measure_dir_name, step_name = nil) ⇒ Object
Module method used to check whether a measure is present in an OSW file.
-
.set_measure_argument(osw, measure_dir_name, argument_name, argument_value, step_name = nil) ⇒ Object
Module method used to set the measure argument for measure_dir_name to argument_value, argument_name must appear in the OSW or exception will be raised.
Class Method Details
.all_extensions ⇒ Object
Module method to return all classes derived from OpenStudio::Extension::Extension Note all extension classes must be loaded before calling this method
@return [Array]: Array of classes
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/openstudio/extension.rb', line 85 def self.all_extensions # DLM: consider calling Bundler.require in this method # do not call Bundler.require when requiring this file, only when calling this method result = [] ObjectSpace.each_object(::Class) do |obj| next if !obj.ancestors.include?(OpenStudio::Extension::Extension) result << obj end return result.uniq end |
.all_file_dirs ⇒ Object
Module method to return file directories from all extensions
@return [Array] Array of measure resource directories
117 118 119 120 121 122 123 124 125 |
# File 'lib/openstudio/extension.rb', line 117 def self.all_file_dirs result = [] all_extensions.each do |obj| dir = obj.new.files_dir result << dir if dir rescue StandardError end return result.uniq.sort end |
.all_measure_dirs ⇒ Object
Module method to return measure directories from all extensions
@return [Array]: Array of measure directories
103 104 105 106 107 108 109 110 111 |
# File 'lib/openstudio/extension.rb', line 103 def self.all_measure_dirs result = [] all_extensions.each do |obj| dir = obj.new.measures_dir result << dir if dir rescue StandardError end return result.uniq.sort end |
.check_for_name_conflicts ⇒ Object
Module method to check for duplicate file, measure, or measure resource names across all extensions
Will raise an error if conflicting file names are found. Note that file names in measure_files_dir names (e.g. License.md) are expected to be the same across all extensions.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/openstudio/extension.rb', line 133 def self.check_for_name_conflicts measure_dirs = all_measure_dirs file_dirs = all_file_dirs conflicts = [] measure_dir_names = {} measure_dirs.each do |dir| Dir.glob(File.join(dir, '*')).each do |file| next if !File.directory?(file) next if !File.exist?(File.join(file, 'measure.rb')) # puts file file_name = File.basename(file).downcase if measure_dir_names[file_name] conflicts << "Measure '#{file}' conflicts with '#{measure_dir_names[file_name]}'" else measure_dir_names[file_name] = file end end end file_names = {} file_dirs.each do |dir| Dir.glob(File.join(dir, '*')).each do |file| next if !File.file?(file) # puts file file_name = File.basename(file).downcase if file_names[file_name] conflicts << "File '#{file}' conflicts with '#{file_names[file_name]}'" else file_names[file_name] = file end end end if !conflicts.empty? raise "Conflicting file names found: [#{conflicts.join(', ')}]" end return false end |
.configure_osw(in_osw) ⇒ Object
Module method used to configure an input OSW with paths to all OpenStudio::Extension measure and file directories
@param [Hash] in_osw Initial OSW object as a Hash, keys should be symbolized
@return [Hash] Output OSW with measure and file paths configured
182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/openstudio/extension.rb', line 182 def self.configure_osw(in_osw) check_for_name_conflicts measure_dirs = all_measure_dirs file_dirs = all_file_dirs in_osw[:measure_paths] = [] if in_osw[:measure_paths].nil? in_osw[:file_paths] = [] if in_osw[:file_paths].nil? in_osw[:measure_paths] = in_osw[:measure_paths].concat(measure_dirs).uniq in_osw[:file_paths] = in_osw[:file_paths].concat(file_dirs).uniq return in_osw end |
.measure_in_osw(osw, measure_dir_name, step_name = nil) ⇒ Object
Module method used to check whether a measure is present in an OSW file
@param [Hash] in_osw Initial OSW object as a Hash, keys should be symbolized
@param [String] measure_dir_name Directory name of measure to set argument on
@param [String] step_name Optional argument, if present used to further identify the measure
@return [Boolean] true or false
238 239 240 241 242 243 244 245 246 247 |
# File 'lib/openstudio/extension.rb', line 238 def self.measure_in_osw(osw, measure_dir_name, step_name = nil) result = false osw[:steps].each do |step| if step[:measure_dir_name] == measure_dir_name && (step_name.nil? || step[:name] == step_name) result = true end end return result end |
.set_measure_argument(osw, measure_dir_name, argument_name, argument_value, step_name = nil) ⇒ Object
Module method used to set the measure argument for measure_dir_name to argument_value, argument_name must appear in the OSW or exception will be raised. If step_name is nil then all workflow steps matching measure_dir_name will be affected. If step_name is not nil, then only workflow steps matching measure_dir_name and step_name will be affected.
@param [Hash] in_osw Initial OSW object as a Hash, keys should be symbolized
@param [String] measure_dir_name Directory name of measure to set argument on
@param [String] argument_name Name of the argument to set
@param [String] argument_value Value to set the argument name to
@param [String] step_name Optional argument, if present used to select workflow step to modify
@return [Hash] Output OSW with measure argument set to argument value
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/openstudio/extension.rb', line 210 def self.set_measure_argument(osw, measure_dir_name, argument_name, argument_value, step_name = nil) result = false osw[:steps].each do |step| if step[:measure_dir_name] == measure_dir_name && (step_name.nil? || step[:name] == step_name) step[:arguments][argument_name.to_sym] = argument_value result = true end end if !result if step_name raise "Could not set '#{argument_name}' to '#{argument_value}' for measure '#{measure_dir_name}' in step '#{step_name}'" else raise "Could not set '#{argument_name}' to '#{argument_value}' for measure '#{measure_dir_name}'" end end return osw end |