openstudio-extension 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -0
  3. data/.rubocop.yml +9 -0
  4. data/Gemfile +3 -1
  5. data/Jenkinsfile +10 -0
  6. data/README.md +230 -12
  7. data/Rakefile +88 -3
  8. data/bin/console +3 -3
  9. data/doc_templates/LICENSE.md +27 -0
  10. data/doc_templates/README.md.erb +42 -0
  11. data/doc_templates/copyright_erb.txt +36 -0
  12. data/doc_templates/copyright_js.txt +4 -0
  13. data/doc_templates/copyright_ruby.txt +34 -0
  14. data/init_templates/README.md +37 -0
  15. data/init_templates/gemspec.txt +32 -0
  16. data/init_templates/openstudio_module.rb +50 -0
  17. data/init_templates/spec.rb +47 -0
  18. data/init_templates/spec_helper.rb +49 -0
  19. data/init_templates/template_gemfile.txt +17 -0
  20. data/init_templates/template_rakefile.txt +15 -0
  21. data/init_templates/version.rb +40 -0
  22. data/lib/files/openstudio-extension-gem-test.ddy +536 -0
  23. data/lib/files/openstudio-extension-gem-test.epw +8768 -0
  24. data/lib/files/openstudio-extension-gem-test.stat +554 -0
  25. data/lib/measures/openstudio_extension_test_measure/LICENSE.md +27 -0
  26. data/lib/measures/openstudio_extension_test_measure/README.md +26 -0
  27. data/lib/measures/openstudio_extension_test_measure/README.md.erb +42 -0
  28. data/lib/measures/openstudio_extension_test_measure/measure.rb +72 -0
  29. data/lib/measures/openstudio_extension_test_measure/measure.xml +83 -0
  30. data/lib/measures/openstudio_extension_test_measure/resources/os_lib_helper_methods.rb +399 -0
  31. data/lib/measures/openstudio_extension_test_measure/tests/OpenStudioExtensionTestMeasure_Test.rb +75 -0
  32. data/lib/openstudio/extension.rb +220 -0
  33. data/lib/openstudio/extension/core/CreateResults.rb +879 -0
  34. data/lib/openstudio/extension/core/check_air_sys_temps.rb +190 -0
  35. data/lib/openstudio/extension/core/check_calibration.rb +155 -0
  36. data/lib/openstudio/extension/core/check_cond_zns.rb +84 -0
  37. data/lib/openstudio/extension/core/check_domestic_hot_water.rb +334 -0
  38. data/lib/openstudio/extension/core/check_envelope_conductance.rb +453 -0
  39. data/lib/openstudio/extension/core/check_eui_by_end_use.rb +162 -0
  40. data/lib/openstudio/extension/core/check_eui_reasonableness.rb +135 -0
  41. data/lib/openstudio/extension/core/check_fan_pwr.rb +98 -0
  42. data/lib/openstudio/extension/core/check_internal_loads.rb +393 -0
  43. data/lib/openstudio/extension/core/check_mech_sys_capacity.rb +226 -0
  44. data/lib/openstudio/extension/core/check_mech_sys_efficiency.rb +326 -0
  45. data/lib/openstudio/extension/core/check_mech_sys_part_load_eff.rb +464 -0
  46. data/lib/openstudio/extension/core/check_mech_sys_type.rb +139 -0
  47. data/lib/openstudio/extension/core/check_part_loads.rb +451 -0
  48. data/lib/openstudio/extension/core/check_placeholder.rb +75 -0
  49. data/lib/openstudio/extension/core/check_plant_cap.rb +123 -0
  50. data/lib/openstudio/extension/core/check_plant_temps.rb +159 -0
  51. data/lib/openstudio/extension/core/check_plenum_loads.rb +87 -0
  52. data/lib/openstudio/extension/core/check_pump_pwr.rb +108 -0
  53. data/lib/openstudio/extension/core/check_sch_coord.rb +241 -0
  54. data/lib/openstudio/extension/core/check_schedules.rb +311 -0
  55. data/lib/openstudio/extension/core/check_simultaneous_heating_and_cooling.rb +158 -0
  56. data/lib/openstudio/extension/core/check_supply_air_and_thermostat_temp_difference.rb +148 -0
  57. data/lib/openstudio/extension/core/check_weather_files.rb +132 -0
  58. data/lib/openstudio/extension/core/deer_vintages.rb +311 -0
  59. data/lib/openstudio/extension/core/os_lib_aedg_measures.rb +491 -0
  60. data/lib/openstudio/extension/core/os_lib_cofee.rb +259 -0
  61. data/lib/openstudio/extension/core/os_lib_constructions.rb +378 -0
  62. data/lib/openstudio/extension/core/os_lib_geometry.rb +1022 -0
  63. data/lib/openstudio/extension/core/os_lib_helper_methods.rb +399 -0
  64. data/lib/openstudio/extension/core/os_lib_hvac.rb +2171 -0
  65. data/lib/openstudio/extension/core/os_lib_lighting_and_equipment.rb +214 -0
  66. data/lib/openstudio/extension/core/os_lib_model_generation.rb +817 -0
  67. data/lib/openstudio/extension/core/os_lib_model_simplification.rb +1049 -0
  68. data/lib/openstudio/extension/core/os_lib_outdoorair_and_infiltration.rb +165 -0
  69. data/lib/openstudio/extension/core/os_lib_reporting.rb +4652 -0
  70. data/lib/openstudio/extension/core/os_lib_reporting_qaqc.rb +200 -0
  71. data/lib/openstudio/extension/core/os_lib_schedules.rb +963 -0
  72. data/lib/openstudio/extension/rake_task.rb +149 -0
  73. data/lib/openstudio/extension/runner.rb +644 -0
  74. data/lib/openstudio/extension/version.rb +40 -0
  75. data/openstudio-extension.gemspec +20 -15
  76. metadata +150 -14
  77. data/.travis.yml +0 -7
  78. data/lib/OpenStudio/Extension/rake_task.rb +0 -84
  79. data/lib/OpenStudio/Extension/version.rb +0 -33
  80. data/lib/OpenStudio/extension.rb +0 -65
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e84ea4693147440c182272ddb36fce2fab938bd
4
- data.tar.gz: 7f9c6fea6520d12cb9179070fcae33e4d28d53e3
3
+ metadata.gz: 7199026e992efc5a48c8c164cc26ff9a30b78266
4
+ data.tar.gz: 8e609b0ab15f84fbbf05e15255eb8a38a031695f
5
5
  SHA512:
6
- metadata.gz: e7f60f747c1ada979e624def3ba692a22198ee58438484c37c93d21764d67fb574eed03c2faf4fe8e8052b6fddd64ea8eb68363d332a1fbde60c386186360b31
7
- data.tar.gz: 3dfc4a2d409665ea67bf6adf4ccfaf9fd819368a2dfe5031d6204a995adbf0953eb8382d096afa93bc7028607dc5918298b216e00d201a6ecc6d6a7dbb0f7cc3
6
+ metadata.gz: 7e6c4367cd3d0b03a463e799461e1705ef9710b4974ee8d0638d369914369fe629e8dfa560e18312179cb133396a0a70730e7de2357c08a9fc7f9a60f8b2f724
7
+ data.tar.gz: 0c7ad841664b252c48090e6b04b9efd44abe27d02defd91c383e351c1b334a1bbca40570e46e10efa6dd238db79e9d5e1b49398841997f1d6b46a387780f8c1a
data/.gitignore CHANGED
@@ -8,10 +8,19 @@
8
8
  /doc/
9
9
  /pkg/
10
10
  /spec/reports/
11
+ /spec/test/
11
12
  /tmp/
13
+ /test/
14
+ /lib/measures/test_results
15
+ /lib/measures/.rubocop*
12
16
 
13
17
  # rspec failure tracking
14
18
  .rspec_status
15
19
 
16
20
  # Ignore IDE files
17
21
  /.idea
22
+ *.rubocop-http*
23
+
24
+ # measures tests
25
+ lib/measures/.rubocop.yml
26
+ lib/measures/test_results/*
@@ -0,0 +1,9 @@
1
+ AllCops:
2
+ Exclude:
3
+ - gems/**/*
4
+ - lib/measures/**/*
5
+ - lib/openstudio/extension/core/**/*
6
+
7
+ inherit_from:
8
+ - http://s3.amazonaws.com/openstudio-resources/styles/rubocop.yml
9
+
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "https://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in openstudio-extension.gemspec
4
4
  gemspec
5
+
6
+ gem 'simplecov', github: 'NREL/simplecov'
@@ -0,0 +1,10 @@
1
+ //Jenkins pipelines are stored in shared libaries. Please see: https://github.com/tijcolem/nrel_cbci_jenkins_libs
2
+
3
+ @Library('cbci_shared_libs') _
4
+
5
+ // Build for PR to develop branch only.
6
+ if ((env.CHANGE_ID) && (env.CHANGE_TARGET) ) { // check if set
7
+
8
+ openstudio_extension_gems()
9
+
10
+ }
data/README.md CHANGED
@@ -1,10 +1,210 @@
1
- # OpenStudio::Extension
1
+ # OpenStudio Extension Gem
2
2
 
3
- This gem repository serves as a base for single purpose repositories that host API methods, CLI tools, and OpenStudio measures which leverage those methods and tools. Other repositories (e.g. urbanopt-geojson-gem) will depend on this repository and inherit/mix-in needed functionality. The repository is formatted as a gem to allow for semantic versioning via Bundle. The repository includes methods for testing, documentation, and build tasks.
3
+ This gem repository serves as a base for single purpose repositories that host API methods, CLI tools, and OpenStudio measures which leverage those methods and tools. Other derivative extension gem repositories will depend on this repository and inherit/mix-in needed functionality. The repository is formatted as a gem to allow for semantic versioning via Bundle. The repository includes methods for testing, documentation, and build tasks.
4
+
5
+ ## Overview
6
+
7
+ The OpenStudio Extension Gem contains methods and patterns to extend OpenStudio. It is a template that can be used to create other extension gems.
8
+
9
+ Derivative extension gems should include this gem to access common functionality, such as:
10
+ * OpenStudio CLI functionality such as list_measures and update_measures
11
+ * adding documentation and license files to measures
12
+ * adding core resource files to measures
13
+ * pushing measures to BCL
14
+
15
+ Extension gems will contain a small group of related measures. Each extension gem will be the unique location to find these measures, and will be responsible for
16
+ testing and maintaining the measures as well as pushing them to BCL.
17
+
18
+ ## Usage
19
+
20
+ The ```openstudio-extension``` gem is meant to be used as a base for creating new gems to use with OpenStudio. The intention is to standardize best practices and common patterns in one location rather than try to synchronize them across many independent gems.
21
+
22
+ Existing gems such as ```openstudio-standards``` and ```openstudio-workflow``` may be refactored to depend on ```openstudio-extension``` in the future. The immediate use of ```openstudio-extension``` will be for new gems. New gems that may be considered a part of OpenStudio and potentially distributed with OpenStudio in the future should be named as ```openstudio-#{gem-name}```, e.g. ```openstudio-model-articulation``` is a gem to implement model articulation methods for OpenStudio.
23
+ Other gems that extend OpenStudio for specific applications or other domains should be named separately, e.g. ```buildingsync``` is an extension of OpenStudio specifically for use with BuildingSync files.
24
+
25
+ Each OpenStudio extension gem should define its own module name to ensure that there are no code collisions with other extension gems. If the gem name is prefixed with ```openstudio-``` then the module name can be nested under the OpenStudio module.
26
+
27
+ | openstudio-model-articulation | buildingsync |
28
+ |------------------------------------------------------------------------------------------------------------- |----------------------------------------------------------------------------- |
29
+ | module OpenStudio module ModelArticulation class ModelArticulation < OpenStudio::Extension::Extension | module BuildingSync class BuildingSync < OpenStudio::Extension::Extension |
4
30
 
5
31
 
6
32
  ## Installation
7
33
 
34
+ To use this and other extension gems, you will need Ruby 2.2.4 and OpenStudio 2.7.1 or greater.
35
+
36
+ ### Windows Installation
37
+ Install Ruby using the [RubyInstaller](https://rubyinstaller.org/downloads/archives/) for [Ruby 2.2.4 (x64)](https://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.2.4-x64.exe).
38
+
39
+ Install Dekit using the [mingw64](https://dl.bintray.com/oneclick/rubyinstaller/DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe) installer.
40
+
41
+ Check the ruby installation returns the correct Ruby version (2.2.4):
42
+ ```
43
+ ruby -v
44
+ ```
45
+
46
+ Install bundler from the command line
47
+ ```
48
+ gem install bundler -v 1.17
49
+ ```
50
+
51
+ Install OpenStudio. Create a file ```C:\ruby-2.2.4-x64-mingw32\lib\ruby\site_ruby\openstudio.rb``` and point it to your OpenStudio installation by editing the contents. E.g.:
52
+
53
+ ```ruby
54
+ require 'C:\openstudio-2.7.1\Ruby\openstudio.rb'
55
+ ```
56
+
57
+ Verify your OpenStudio and Ruby configuration:
58
+ ```
59
+ ruby -e "require 'openstudio'" -e "puts OpenStudio::Model::Model.new"
60
+ ```
61
+
62
+ ### Mac Installation
63
+ It is recommended that you install [rbenv](https://github.com/rbenv/rbenv) to easily manage difference versions of Ruby.
64
+ rbenv can be installed view Homebrew:
65
+ ```ruby
66
+ brew install rbenv
67
+ rbenv init
68
+ rbenv install 2.2.4
69
+ ```
70
+
71
+ Also install bundler
72
+ ```ruby
73
+ gem install bundler -v 1.17
74
+ ```
75
+
76
+ Install [OpenStudio](https://www.openstudio.net/downloads).
77
+
78
+ Add the RUBYLIB environment variable to your bash_profile file. It should point to the Ruby folder within the OpenStudio Application you just downloaded:
79
+ ```ruby
80
+ export RUBYLIB=“/Applications/OpenStudio-2.7.2/Ruby”
81
+ ```
82
+
83
+
84
+ ## Contents
85
+ The OpenStudio Extension Gem (this repo) contains methods that can be shared across and extended by other derivative extension gems.
86
+
87
+ ### Directory Structure
88
+
89
+ Extension gem and the derivative extension gem should have the following directory structure:
90
+
91
+ ├── doc_templates
92
+
93
+ ├── init_templates
94
+
95
+ ├── lib
96
+
97
+ │       ├── data
98
+
99
+ │       ├── files
100
+
101
+ │       ├── measures
102
+
103
+ │       └── openstudio
104
+
105
+ │                └── extension
106
+
107
+ │                          └── core
108
+
109
+ └── spec
110
+                ├── files
111
+
112
+                └── openstudio
113
+
114
+                          └── core
115
+
116
+ `doc_templates` contains copyright and license file templates that can be copied and added to each measure.
117
+ The derivative extension gems should have their own doc_templates directory.
118
+
119
+ `init_templates` are used with the `init-new-gem` rake task to create a derivative extension gem directory structure.
120
+
121
+ `lib` contains data
122
+ * `data` contains custom data for the gem
123
+ * `files` contains files referenced by measures or workflows
124
+ * `measures` contains the measures included in the gem.
125
+ * `openstudio` and `openstudio\extension` contain the code related to this gem.
126
+ * `openstudio\extension\core` contains core resource files shared across a variety of measures.
127
+
128
+ Your gem should list its gem dependencies (including ```openstudio-extension```) in its gemspec file. This is what is used to determine dependencies for consumers of your gem.
129
+ You should only list actual dependencies of your gem in the gemspec. You can list specific sources for your gems (e.g. on github, local file) in your Gemfile. If you are writing an application rather than a gem, you can only have a Gemfile. You do not need a gemspec unless you are releasing your code as a gem.
130
+ Once you have included ```openstudio-extension``` as a dependency of your gem, you can inherit common rake tasks into your application's Rakefile.
131
+
132
+ ### Core Library
133
+ The `core` folder located at `lib\openstudio\extension` contains core resource files shared across a variety of measures. The files should be edited in the OpenStudio-extension-gem, and the rake task (`bundle exec rake openstudio:measures:copy_resources`) should be used to update the measures that depend on them.
134
+ Note that this folder is for 'core' functionality; if a measure's requires a new one-off function, this should be developed in place, within the measure's `resources` folder.
135
+
136
+ Having a single repository for all measures, such as the OpenStudio-measures repo, can be cumbersome to test and keep up to date.
137
+ In this new framework, each extension gem will contain one or more related measures. The gem will be the new 'home' of these measures, and the repo owner will be responsible for testing and keeping the measures up to date.
138
+
139
+ In the short term, in order to preserve the PAT/OS App functionality, resource files will still be copied directly into the measures, and these measures will be pushed to BCL.
140
+
141
+ ### Rake Tasks
142
+ Common Rake Tasks that are available to derivative extension gems include:
143
+ | Rake Task | Description |
144
+ | --------- | ----------- |
145
+ | openstudio:list_measures | List all measures in the calling gem |
146
+ | openstudio:measures:add_license | Add License File to measures in the calling gem |
147
+ | openstudio:measures:add_readme | Add README.md.erb file if it and the README markdown file do not already exist for a measure |
148
+ | openstudio:measures:copy_resources | Copy the resources files to individual measures in the calling gem |
149
+ | openstudio:measures:update_copyright | Update copyright on measure files in the calling gem |
150
+ | openstudio:stage_bcl | Copy the measures to a location that can be uploaded to BCL |
151
+ | openstudio:push_bcl | Upload measures from the specified location to the BCL |
152
+ | openstudio:test_with_docker | Use openstudio docker image to run tests |
153
+ | openstudio:test_with_openstudio | Use openstudio system ruby to run tests |
154
+ | openstudio:update_measures | Run the CLI task to check for measure updates and update the measure xml files |
155
+
156
+ These can all be invoked from the derivative gem by running the following command in a terminal:
157
+
158
+ ``` bundle exec rake <name_of_rake_task>```
159
+
160
+ To list all available rake tasks:
161
+
162
+ ``` bundle exec rake -T ```
163
+
164
+ ## Derivative Extension Gems
165
+
166
+ The following table contains all current extension gems.
167
+
168
+ | Name | Gem Name | Repo |
169
+ | ------ | ---------- | ------ |
170
+ | OpenStudio Extension Gem | openstudio-extension | https://github.com/NREL/OpenStudio-extension-gem |
171
+ | OpenStudio Common Measures Gem | openstudio-common-measures | https://github.com/NREL/openstudio-common-measures-gem |
172
+ | OpenStudio Model Articulation Gem | openstudio-model-articulation | https://github.com/NREL/openstudio-model-articulation-gem |
173
+ | OpenStudio AEDG Gem | openstudio-aedg | https://github.com/NREL/openstudio-aedg-gem |
174
+ | OpenStudio District Systems Gem | openstudio-district-systems | https://github.com/NREL/openstudio-district-systems-gem |
175
+ | UrbanOpt GeoJSON Gem | urbanopt-geojson | https://github.com/urbanopt/urbanopt-geojson-gem |
176
+ | BuildingSync Gem | buildingsync | https://github.com/BuildingSync/BuildingSync-gem |
177
+
178
+ ### Initializing a new Extension Gem
179
+ The OpenStudio-extension gem can be used to easily initialize a new derivative extension gem.
180
+
181
+ * First, call the rake task:
182
+ ```ruby
183
+ bundle exec rake init-new-gem
184
+ ```
185
+ * Enter the name of the gem repository (use dashes between words and the repo name should end with '-gem')
186
+ * Enter the location of the directory where the gem directory should be created
187
+ The rake task will create the gem directory and stub out the required files.
188
+
189
+ * You can then obtain a github repository and commit the newly created gem directory to it
190
+
191
+ ### Coding Conventions
192
+ * Name your extension gem repo: OpenStudio-<gem name in lowercase>-gem. Use dashes between words. Example: OpenStudio-extension-gem
193
+ * Name the actual gem: openstudio-<gem name in lowercase>. 'openstudio' should be lowercase. Use dashes between words. Example: openstudio-extension
194
+ * Use lowercase snake_case for methods and variables.
195
+ * Use CamelCase for classes and modules. (Keep acronyms like HTTP, RFC, XML uppercase.)
196
+ * All files and classes should have underscores (no dashes) and (lowercase snake_case)
197
+ * Dashes should be used in module names
198
+
199
+ ### Pushing to BCL
200
+ Use the rake tasks listed above to stage and push measures to BCL.
201
+ **Note of warning**: Use caution when pushing to the BCL. Public and private measures could be pushed to BCL from within an extension gem, even though the extension gem repo may be private.
202
+
203
+ TODO: Add warning to rake task and lists what gems will be pushed
204
+ TODO: Check that license files, etc. are present in each measure before pushing to BCL
205
+
206
+ ## Include in a project
207
+
8
208
  Add this line to your application's Gemfile:
9
209
 
10
210
  ```ruby
@@ -13,20 +213,38 @@ gem 'openstudio-extension'
13
213
 
14
214
  And then execute:
15
215
 
16
- $ bundle
17
-
216
+ $ bundle install
217
+ $ bundle update
218
+
18
219
  Or install it yourself as:
19
220
 
20
221
  $ gem install 'openstudio-extension'
21
222
 
22
- ## Usage
23
-
24
- To be filled out later.
25
-
26
- # Releasing
223
+ # Releasing the gem
27
224
 
28
225
  * Update change log
29
- * Update version in `/lib/openstudio_measure_tester/version.rb`
226
+ * Update version in `/lib/openstudio/extension/version.rb`
30
227
  * Merge down to master
31
- * Release via github
32
- * run `rake release` from master
228
+ * run `rake release` from master
229
+
230
+ # TODO
231
+
232
+ - [ ] Finalize documentation on naming conventions, etc
233
+ - [X] Add test measure
234
+ - [X] Rake task ```openstudio:update_measures```
235
+ - [X] Rake task ```openstudio:test_with_openstudio```
236
+ - [ ] Rake task ```stage_bcl``` _DLM: BCL gem should be a development dependency only until we can reduce its dependencies and remove native dependencies? should probably put it into a special group so we can bundle without it in openstudio-gems._
237
+ - [ ] Rake task ```push_bcl``` _DLM: how do we want to test this?
238
+ - [X] Get all rake tasks working on Travis
239
+ - [ ] Capture useful output from Travis (measure dashboard results, log files, zip of build products, etc) and put it somewhere (s3? naming convention?)
240
+ - [X] ```Extension::openstudio_extension_version``` _DLM: should we rename? should people overwrite this in their class?_
241
+ - [X] ```Extension::measures_dir``` _DLM: I think this can have a default implementation, right? If something does not need to be overridden should it be a module method rather than a class one? KAF: this is in rake task for now
242
+ - [X] ```Extension::list_measures``` _DLM: I think this can have a default implementation, right?_KAF: In Rake task for now
243
+ - [ ] ```Extension::files_dir``` _DLM: I think this can have a default implementation, right?_
244
+ - [ ] ```Extension::minimum_openstudio_version``` _DLM: should we rename? should people overwrite this in their class?_
245
+ - [X] ```Runner::initialize``` _DLM: should say that the path argument should be for a dir with a Gemfile right?_
246
+ - [X] ```Runner::configure_osw``` _DLM: should take in an OSW, add paths to all measure and file dirs for loaded OpenStudio Extensions, write out configured OSW_
247
+ - [ ] Run rubocop on all of the core files and remove exclusion from .rubocop.yml file.
248
+ - [ ] Cleanup task after running tests (may need to be in the OpenStudio Measure Tester)
249
+ - [ ] Add a `rake init new_ext_gem` to Rakefile
250
+ - [ ] Add tests to the extension/core
data/Rakefile CHANGED
@@ -26,9 +26,94 @@
26
26
  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  ########################################################################################################################
28
28
 
29
- require "bundler/gem_tasks"
30
- require "rspec/core/rake_task"
29
+ require 'bundler/gem_tasks'
30
+ require 'rspec/core/rake_task'
31
31
 
32
32
  RSpec::Core::RakeTask.new(:spec)
33
33
 
34
- task :default => :spec
34
+ require 'openstudio/extension/rake_task'
35
+ require 'openstudio/extension'
36
+ rake_task = OpenStudio::Extension::RakeTask.new
37
+ rake_task.set_extension_class(OpenStudio::Extension::Extension)
38
+
39
+ require 'rubocop/rake_task'
40
+ RuboCop::RakeTask.new
41
+
42
+ task default: :spec
43
+
44
+ desc 'Initialize a new gem'
45
+ task :init_new_gem do
46
+ puts 'Initializing a new extension gem'
47
+ print "\n Enter the name of the new gem directory (ex: openstudio-something-gem. Should end with '-gem'): "
48
+ gem_name = STDIN.gets.chomp
49
+
50
+ print "\n Enter the path (full or relative to this repo) where you want the new gem directory to be created: "
51
+ dir_path = STDIN.gets.chomp
52
+
53
+ # check if directory already exists at path, if so error
54
+ full_dir_name = dir_path + gem_name
55
+
56
+ if Dir.exist?(full_dir_name)
57
+ puts "ERROR: there is already a directory at path #{full_dir_name}... aborting"
58
+ else
59
+ puts "CREATING dir #{full_dir_name}"
60
+ Dir.mkdir full_dir_name
61
+ end
62
+
63
+ # copy file structure
64
+ FileUtils.cp('.gitignore', full_dir_name + '/.gitignore')
65
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), 'init_templates/template_gemfile.txt'), File.join(full_dir_name, 'Gemfile'))
66
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), 'doc_templates'), full_dir_name)
67
+
68
+ Dir.mkdir File.join(full_dir_name, 'lib')
69
+ Dir.mkdir File.join(full_dir_name, 'lib/measures')
70
+ Dir.mkdir File.join(full_dir_name, 'lib/files')
71
+
72
+ # Replacement tokens
73
+ gem_name_bare = gem_name.gsub('-gem', '')
74
+ gem_name_underscores_no_os = gem_name_bare.gsub('openstudio-', '').gsub('openstudio', '').tr('-', '_').tr(' ', '_')
75
+ gem_name_spaces = gem_name.split('-').map(&:capitalize).join(' ')
76
+ gem_class_name = gem_name_underscores_no_os.split('_').collect(&:capitalize).join
77
+
78
+ # Rewrite the rakefile template
79
+ text = File.read(File.join(File.dirname(__FILE__), 'init_templates/template_rakefile.txt'))
80
+ new_contents = text.gsub(/GEM_CLASS_NAME/, gem_class_name)
81
+ new_contents = new_contents.gsub(/GEM_NAME_UNDERSCORES/, gem_name_underscores_no_os)
82
+ File.open(File.join(full_dir_name, '/Rakefile'), 'w') { |file| file.puts new_contents }
83
+
84
+ # Rewrite README with gem-specific tokens and save
85
+ text = File.read(File.join(File.dirname(__FILE__), 'init_templates/README.md'))
86
+ new_contents = text.gsub(/GEM_NAME_SPACES/, gem_name_spaces)
87
+ new_contents = new_contents.gsub(/GEM_NAME_BARE/, gem_name_bare)
88
+ File.open(File.join(full_dir_name, '/README.md'), 'w') { |file| file.puts new_contents }
89
+
90
+ # Rewrite gemspec
91
+ text = File.read(File.join(File.dirname(__FILE__), 'init_templates/gemspec.txt'))
92
+ new_contents = text.gsub(/GEM_NAME_UNDERSCORES/, gem_name_underscores_no_os)
93
+ new_contents = new_contents.gsub(/GEM_NAME_BARE/, gem_name_bare)
94
+ new_contents = new_contents.gsub(/GEM_CLASS_NAME/, gem_class_name)
95
+ File.open(File.join(full_dir_name, "#{gem_name_bare}.gemspec"), 'w') { |file| file.puts new_contents }
96
+
97
+ # Rewrite spec and spec_helper with gem-specific tokens and save
98
+ Dir.mkdir File.join(full_dir_name, 'spec')
99
+ Dir.mkdir File.join(full_dir_name, 'spec/tests')
100
+ text = File.read(File.join(File.dirname(__FILE__), 'init_templates/spec.rb'))
101
+ new_contents = text.gsub(/GEM_CLASS_NAME/, gem_class_name)
102
+ File.open(File.join(full_dir_name, 'spec', 'tests', "#{gem_name_underscores_no_os}_spec.rb"), 'w') { |file| file.puts new_contents }
103
+
104
+ text = File.read(File.join(File.dirname(__FILE__), 'init_templates/spec_helper.rb'))
105
+ new_contents = text.gsub(/GEM_NAME_UNDERSCORES/, gem_name_underscores_no_os)
106
+ File.open(File.join(full_dir_name, 'spec', 'spec_helper.rb'), 'w') { |file| file.puts new_contents }
107
+
108
+ # Stub out OpenStudio directory
109
+ Dir.mkdir File.join(full_dir_name, 'lib/openstudio')
110
+ Dir.mkdir File.join(full_dir_name, 'lib/openstudio', gem_name_underscores_no_os)
111
+ text = File.read(File.join(File.dirname(__FILE__), 'init_templates/version.rb'))
112
+ new_contents = text.gsub(/GEM_CLASS_NAME/, gem_class_name)
113
+ File.open(File.join(full_dir_name, 'lib', 'openstudio', gem_name_underscores_no_os, 'version.rb'), 'w') { |file| file.puts new_contents }
114
+
115
+ text = File.read(File.join(File.dirname(__FILE__), 'init_templates/openstudio_module.rb'))
116
+ new_contents = text.gsub(/GEM_CLASS_NAME/, gem_class_name)
117
+ new_contents = new_contents.gsub(/GEM_NAME_UNDERSCORES/, gem_name_underscores_no_os)
118
+ File.open(File.join(full_dir_name, 'lib', 'openstudio', "#{gem_name_underscores_no_os}.rb"), 'w') { |file| file.puts new_contents }
119
+ end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "openstudio/extension"
3
+ require 'bundler/setup'
4
+ require 'openstudio/extension'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "openstudio/extension"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -0,0 +1,27 @@
1
+ OpenStudio(R), Copyright (c) 2008-2018, Alliance for Sustainable Energy, LLC. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted
4
+ provided that the following conditions are met:
5
+
6
+ (1) Redistributions of source code must retain the above copyright notice, this list of conditions
7
+ and the following disclaimer.
8
+
9
+ (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
+
12
+ (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse
13
+ or promote products derived from this software without specific prior written permission from the
14
+ respective party.
15
+
16
+ (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other
17
+ derivative works may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar
18
+ designation without specific prior written permission from Alliance for Sustainable Energy, LLC.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
21
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES GOVERNMENT,
23
+ OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
25
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.