ams_var_file 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +180 -0
- data/Rakefile +6 -0
- data/ams_var_file.gemspec +27 -0
- data/bin/console +7 -0
- data/bin/setup +7 -0
- data/lib/ams_var_file.rb +13 -0
- data/lib/ams_var_file/file.rb +289 -0
- data/lib/ams_var_file/version.rb +3 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 02c6e9779069f285e6889fb2fb7baf1253be2562
|
4
|
+
data.tar.gz: c3d4d6ef936ba2dcf05495b215fc3952147fa1fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd8e9bed2ca5ed7981759bc224d119f86b188d5ca0227de75961f75366af744b8402059fcb526c85a832cbd02931dba0da69ef8b7bb5b92b755e7d88c667a5c2
|
7
|
+
data.tar.gz: 88fa6404762bdeb8eafbcbc0ff45d8d0dd3c35e3102a59e400ce9eb4f96dfe3b23d4c9c32448c1569b839814c6a6ebbd900678e57d0414a883e58b4b463be578
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Jeff McAffee
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
# AmsVarFile
|
2
|
+
|
3
|
+
AmsVarFile generates DPM and DSM variable declaration files and provides for
|
4
|
+
adding and deleting variables programmatically.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'ams_var_file'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install ams_var_file
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
First, require the gem:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require "ams_var_file"
|
28
|
+
```
|
29
|
+
|
30
|
+
Note: AmsVarFile can output informative messages to `$stdout` and `$stderr`.
|
31
|
+
To have the messages output, set verbose to true (it's false by default).
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
AmsVarFile::File.verbose = true
|
35
|
+
```
|
36
|
+
|
37
|
+
### Generate a Var File
|
38
|
+
|
39
|
+
To generate a `DPM` var file:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
AmsVarFile::File.generate("dpm", "path/to/dpms.gdl")
|
43
|
+
```
|
44
|
+
|
45
|
+
To generate a `DSM` var file:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
AmsVarFile::File.generate("dsm", "path/to/dsms.gdl")
|
49
|
+
```
|
50
|
+
|
51
|
+
AmsVarFile will throw an `IOError` exception if the file already exists.
|
52
|
+
|
53
|
+
The generated files will contain markers that allow AmsVarFile to understand
|
54
|
+
where to insert/delete variables. Removing or modifying these markers will
|
55
|
+
result in a `InvalidFileFormat` exception being thrown.
|
56
|
+
|
57
|
+
The markers are:
|
58
|
+
|
59
|
+
// START DEFINITIONS
|
60
|
+
|
61
|
+
// END DEFINITIONS
|
62
|
+
|
63
|
+
// START INITS
|
64
|
+
|
65
|
+
// END INITS
|
66
|
+
|
67
|
+
The naming convention of the files are `dpms.gdl` for DPMs
|
68
|
+
and `dsms.gdl` for DSMs.
|
69
|
+
|
70
|
+
### Adding Variable Declarations
|
71
|
+
|
72
|
+
Before adding a variable to a file, the file must exist. See the `generation`
|
73
|
+
details above for information on generating a file.
|
74
|
+
|
75
|
+
To add a `DPM` variable:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
# var_type can be one of:
|
79
|
+
# boolean
|
80
|
+
# date
|
81
|
+
# datetime
|
82
|
+
# money
|
83
|
+
# numeric
|
84
|
+
# numeric(#) where '#' indicates precision
|
85
|
+
# percentage
|
86
|
+
# text
|
87
|
+
|
88
|
+
var_type = "text"
|
89
|
+
|
90
|
+
|
91
|
+
# var_id is a valid GDL identifier (ie, no spaces or special chars)
|
92
|
+
|
93
|
+
var_id = "myDummyVar"
|
94
|
+
|
95
|
+
|
96
|
+
# var_alias is the variable's actual name in the AMS system. It *can*
|
97
|
+
# contain spaces and such.
|
98
|
+
|
99
|
+
var_alias = "My Dummy Var"
|
100
|
+
|
101
|
+
|
102
|
+
# file_path is any valid path to the `.gdl` file to add the variable to.
|
103
|
+
|
104
|
+
file_path = "path/to/dpms.gdl"
|
105
|
+
|
106
|
+
|
107
|
+
AmsVarFile::File.add_dpm_var(var_type, var_id, var_alias, file_path)
|
108
|
+
```
|
109
|
+
|
110
|
+
Adding a `DSM` variable is virtually the same, except a different method
|
111
|
+
is called:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
var_type = "text"
|
115
|
+
var_id = "myDummyDSMVar"
|
116
|
+
var_alias = "My Dummy DSM Var"
|
117
|
+
file_path = "path/to/dsms.gdl"
|
118
|
+
|
119
|
+
|
120
|
+
AmsVarFile::File.add_dsm_var(var_type, var_id, var_alias, file_path)
|
121
|
+
```
|
122
|
+
|
123
|
+
### Deleting Variable Declarations
|
124
|
+
|
125
|
+
Obviously, deleting a variable from a non-existing file won't work.
|
126
|
+
|
127
|
+
To delete a `DPM` variable:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
var_id = "myDummyVar"
|
131
|
+
file_path = "path/to/dpms.gdl"
|
132
|
+
|
133
|
+
|
134
|
+
AmsVarFile::File.del_dpm_var(var_id, file_path)
|
135
|
+
```
|
136
|
+
|
137
|
+
Ditto for a `DSM` variable:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
var_id = "myDummyDSMVar"
|
141
|
+
file_path = "path/to/dsms.gdl"
|
142
|
+
|
143
|
+
|
144
|
+
AmsVarFile::File.del_dsm_var(var_id, file_path)
|
145
|
+
```
|
146
|
+
|
147
|
+
AmsVarFile will handle the deletion of a non-existing variable gracefully:
|
148
|
+
it will not throw an exception. If `verbose` is `true`, you will
|
149
|
+
see a message (output on `$stderr`) indicating the variable wasn't found.
|
150
|
+
|
151
|
+
## Development
|
152
|
+
|
153
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
154
|
+
run `rake rspec` to run the tests. You can also run `bin/console` for an
|
155
|
+
interactive prompt that will allow you to experiment.
|
156
|
+
|
157
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
158
|
+
To release a new version, update the version number in `version.rb`, and then
|
159
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
160
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
161
|
+
|
162
|
+
## Contributing
|
163
|
+
|
164
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jmcaffee/ams_var_file.
|
165
|
+
|
166
|
+
1. Fork it ( https://github.com/jmcaffee/ams_var_file/fork )
|
167
|
+
1. Clone it (`git clone git@github.com:[my-github-username]/ams_var_file.git`)
|
168
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
169
|
+
3. Create tests for your feature branch
|
170
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
171
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
172
|
+
6. Create a new Pull Request
|
173
|
+
|
174
|
+
## License
|
175
|
+
|
176
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
177
|
+
|
178
|
+
See [LICENSE.txt](https://github.com/jmcaffee/ams_var_file/blob/master/LICENSE.txt) for
|
179
|
+
details.
|
180
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ams_var_file/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ams_var_file"
|
8
|
+
spec.version = AmsVarFile::VERSION
|
9
|
+
spec.authors = ["Jeff McAffee"]
|
10
|
+
spec.email = ["jeff@ktechsystems.com"]
|
11
|
+
|
12
|
+
spec.description = %q{Generate AMS variable declaration files and provide for adding and deleting variables.}
|
13
|
+
spec.summary = spec.description
|
14
|
+
spec.homepage = "https://github.com/jmcaffee/ams_var_file"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
spec.add_development_dependency "pry-byebug"
|
27
|
+
end
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/ams_var_file.rb
ADDED
@@ -0,0 +1,289 @@
|
|
1
|
+
module AmsVarFile
|
2
|
+
class File
|
3
|
+
|
4
|
+
START_DEFS = 'START DEFINITIONS'
|
5
|
+
END_DEFS = 'END DEFINITIONS'
|
6
|
+
START_INITS = 'START INITS'
|
7
|
+
END_INITS = 'END INITS'
|
8
|
+
|
9
|
+
# Capture groups:
|
10
|
+
# :type = var type
|
11
|
+
# :id = identifier
|
12
|
+
# :name = name
|
13
|
+
DEF_PATTERN = /^[\s]*dpm (?<type>text|numeric|numeric\(\d+\)|date|percentage|datetime|boolean)[\s]*(?<id>\w+)[\s]*"(?<name>.+)";/
|
14
|
+
DEF_DSM_PATTERN = /^[\s]*decision[\s]*dpm (?<type>text|numeric|numeric\(\d+\)|date|percentage|datetime|boolean)[\s]*(?<id>\w+)[\s]*"(?<name>.+)";/
|
15
|
+
|
16
|
+
# Usage:
|
17
|
+
# ' dpm numeric(3) myVariable "My Variable";'.match(DEF_PATTERN)
|
18
|
+
# Regexp.last_match # Returns nil if no match found
|
19
|
+
# Regexp.last_match(:id) # Returns 'myVariable' or nil if no match found
|
20
|
+
#
|
21
|
+
INIT_PATTERN = /^[\s]*tempString[\s]*=[\s]*(?<id>\w+);/
|
22
|
+
|
23
|
+
|
24
|
+
def self.verbose= flag
|
25
|
+
@@verbose = flag
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.verbose
|
29
|
+
@@verbose ||= false
|
30
|
+
end
|
31
|
+
|
32
|
+
###
|
33
|
+
# Add a DPM variable declaration to the given file.
|
34
|
+
#
|
35
|
+
# type: one of
|
36
|
+
# boolean
|
37
|
+
# date
|
38
|
+
# datetime
|
39
|
+
# money
|
40
|
+
# numeric
|
41
|
+
# numeric(#) where '#' indicates precision
|
42
|
+
# percentage
|
43
|
+
# text
|
44
|
+
# id: valid GDL id (ie. no spaces or special chars)
|
45
|
+
# name: GDL alias/human readable name, visible in guidelines
|
46
|
+
# file: full path to declaration file to update
|
47
|
+
#
|
48
|
+
# Message indicating success or failure is output on $stdout/$stderr
|
49
|
+
#
|
50
|
+
|
51
|
+
def self.add_dpm_var type, id, name, file
|
52
|
+
add_variable(type, id, name, DEF_PATTERN, INIT_PATTERN, file, false)
|
53
|
+
end
|
54
|
+
|
55
|
+
###
|
56
|
+
# Delete a DPM variable declaration from the given file.
|
57
|
+
#
|
58
|
+
# id: valid GDL id (ie. no spaces or special chars) of variable to delete
|
59
|
+
# file: full path to declaration file to update
|
60
|
+
#
|
61
|
+
# Message indicating success or failure is output on $stdout/$stderr
|
62
|
+
#
|
63
|
+
|
64
|
+
def self.del_dpm_var id, file
|
65
|
+
del_variable(id, DEF_PATTERN, INIT_PATTERN, file)
|
66
|
+
end
|
67
|
+
|
68
|
+
###
|
69
|
+
# Add a DSM variable declaration to the given file.
|
70
|
+
#
|
71
|
+
# type: one of
|
72
|
+
# boolean
|
73
|
+
# date
|
74
|
+
# datetime
|
75
|
+
# money
|
76
|
+
# numeric
|
77
|
+
# numeric(#) where '#' indicates precision
|
78
|
+
# percentage
|
79
|
+
# text
|
80
|
+
# id: valid GDL id (ie. no spaces or special chars)
|
81
|
+
# name: GDL alias/human readable name, visible in guidelines
|
82
|
+
# file: full path to declaration file to update
|
83
|
+
#
|
84
|
+
# Message indicating success or failure is output on $stdout/$stderr
|
85
|
+
#
|
86
|
+
|
87
|
+
def self.add_dsm_var type, id, name, file
|
88
|
+
add_variable(type, id, name, DEF_DSM_PATTERN, INIT_PATTERN, file, true)
|
89
|
+
end
|
90
|
+
|
91
|
+
###
|
92
|
+
# Delete a DSM variable declaration from the given file.
|
93
|
+
#
|
94
|
+
# id: valid GDL id (ie. no spaces or special chars) of variable to delete
|
95
|
+
# file: full path to declaration file to update
|
96
|
+
#
|
97
|
+
# Message indicating success or failure is output on $stdout/$stderr
|
98
|
+
#
|
99
|
+
|
100
|
+
def self.del_dsm_var id, file
|
101
|
+
del_variable(id, DEF_DSM_PATTERN, INIT_PATTERN, file)
|
102
|
+
end
|
103
|
+
|
104
|
+
###
|
105
|
+
# Generate a new dpm/dsm declaration file.
|
106
|
+
#
|
107
|
+
# file_type: 'dpm' or 'dsm'
|
108
|
+
# file_path: full path to file to generate
|
109
|
+
# Ex: path/to/dpms.gdl
|
110
|
+
# path/to/dsms.gdl
|
111
|
+
#
|
112
|
+
# dpms.gdl and dsms.gdl are the standard name to be used.
|
113
|
+
#
|
114
|
+
# Message indicating success or failure is output on $stdout/$stderr
|
115
|
+
#
|
116
|
+
|
117
|
+
def self.generate(file_type, file_path)
|
118
|
+
|
119
|
+
text = <<FILE_TEXT
|
120
|
+
/* ***************************************************************************
|
121
|
+
File: #{file_type.downcase}s.gdl
|
122
|
+
Purpose: #{file_type.upcase} definitions
|
123
|
+
|
124
|
+
Author: Generated #{Date.today.month}/#{Date.today.day}/#{Date.today.year}
|
125
|
+
|
126
|
+
*************************************************************************** */
|
127
|
+
|
128
|
+
// #{START_DEFS}
|
129
|
+
|
130
|
+
// #{END_DEFS}
|
131
|
+
|
132
|
+
|
133
|
+
// ++++++++++++++++++++++++ Upload Rule Definitions +++++++++++++++++++++++++
|
134
|
+
|
135
|
+
ruleset z-#{file_type.downcase}-upload(continue)
|
136
|
+
rule z-#{file_type.downcase}-upload-#{file_type.downcase}s()
|
137
|
+
if(pLoanAmount != pLoanAmount)
|
138
|
+
then // #{START_INITS}
|
139
|
+
|
140
|
+
end // #{END_INITS}
|
141
|
+
end // rule
|
142
|
+
end // ruleset z-#{file_type.downcase}-upload
|
143
|
+
|
144
|
+
FILE_TEXT
|
145
|
+
|
146
|
+
raise IOError, "#{file_type.upcase} File already exists (#{file_path})" if ::File.exist?(file_path)
|
147
|
+
|
148
|
+
::File.open(file_path, 'w') do |f|
|
149
|
+
f << text
|
150
|
+
end
|
151
|
+
|
152
|
+
$stdout << "#{file_type.upcase} file generated (#{file_path})\n" if verbose
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
156
|
+
|
157
|
+
def self.generation_tags_found(lines)
|
158
|
+
start_def = false
|
159
|
+
end_def = false
|
160
|
+
start_init = false
|
161
|
+
end_init = false
|
162
|
+
|
163
|
+
lines.each do |line|
|
164
|
+
start_def = true if line.include? START_DEFS
|
165
|
+
end_def = true if line.include? END_DEFS
|
166
|
+
start_init = true if line.include? START_INITS
|
167
|
+
end_init = true if line.include? END_INITS
|
168
|
+
end
|
169
|
+
|
170
|
+
return (start_def && end_def && start_init && end_init)
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.id_exists_in_file?(id, lines, pattern)
|
174
|
+
lines.each do |line|
|
175
|
+
return true if match_found(id, line, pattern)
|
176
|
+
end
|
177
|
+
return false
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.match_found(id, line, pattern)
|
181
|
+
line.match(pattern)
|
182
|
+
return false if Regexp.last_match.nil?
|
183
|
+
return true if id.downcase == Regexp.last_match[:id].downcase
|
184
|
+
false
|
185
|
+
end
|
186
|
+
|
187
|
+
def self.location_found(id, line, pattern)
|
188
|
+
line.match(pattern)
|
189
|
+
return false if Regexp.last_match.nil?
|
190
|
+
return true if id.downcase < Regexp.last_match[:id].downcase
|
191
|
+
false
|
192
|
+
end
|
193
|
+
|
194
|
+
def self.find_def_insert_index(id, lines, pattern)
|
195
|
+
start_i = lines.index { |line| line.include? START_DEFS }
|
196
|
+
end_i = lines.index { |line| line.include? END_DEFS }
|
197
|
+
|
198
|
+
i = lines[start_i..end_i].index do |line|
|
199
|
+
location_found(id, line, pattern)
|
200
|
+
end
|
201
|
+
|
202
|
+
return end_i if i.nil?
|
203
|
+
i + start_i
|
204
|
+
end
|
205
|
+
|
206
|
+
def self.find_def_delete_index(id, lines, pattern)
|
207
|
+
start_i = lines.index { |line| line.include? START_DEFS }
|
208
|
+
end_i = lines.index { |line| line.include? END_DEFS }
|
209
|
+
|
210
|
+
i = lines[start_i..end_i].index do |line|
|
211
|
+
match_found(id, line, pattern)
|
212
|
+
end
|
213
|
+
|
214
|
+
return nil if i.nil?
|
215
|
+
i + start_i
|
216
|
+
end
|
217
|
+
|
218
|
+
def self.find_init_insert_index(id, lines, pattern)
|
219
|
+
start_i = lines.index { |line| line.include? START_INITS }
|
220
|
+
end_i = lines.index { |line| line.include? END_INITS }
|
221
|
+
|
222
|
+
i = lines[start_i..end_i].index do |line|
|
223
|
+
location_found(id, line, pattern)
|
224
|
+
end
|
225
|
+
|
226
|
+
return end_i if i.nil?
|
227
|
+
i + start_i
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.find_init_delete_index(id, lines, pattern)
|
231
|
+
start_i = lines.index { |line| line.include? START_INITS }
|
232
|
+
end_i = lines.index { |line| line.include? END_INITS }
|
233
|
+
|
234
|
+
i = lines[start_i..end_i].index do |line|
|
235
|
+
match_found(id, line, pattern)
|
236
|
+
end
|
237
|
+
|
238
|
+
return nil if i.nil?
|
239
|
+
i + start_i
|
240
|
+
end
|
241
|
+
|
242
|
+
def self.add_variable(type, id, name, def_pattern, init_pattern, var_file, dsm = false)
|
243
|
+
lines = ::File.new(var_file).readlines
|
244
|
+
raise InvalidFileFormat, "Missing generation tags (#{START_DEFS}, #{END_DEFS}, #{START_INITS}, #{END_INITS})" unless generation_tags_found(lines)
|
245
|
+
raise VariableExists, "ID '#{id}' already exists in file #{var_file}" if id_exists_in_file?(id, lines, def_pattern)
|
246
|
+
|
247
|
+
add_def = " dpm #{type.downcase.ljust(12)}#{id.ljust(52)}\"#{name}\";\n"
|
248
|
+
add_def = "decision" + add_def if dsm
|
249
|
+
add_init = " tempString = #{id};\n"
|
250
|
+
|
251
|
+
insert_index = find_def_insert_index(id, lines, def_pattern)
|
252
|
+
lines.insert(insert_index, add_def)
|
253
|
+
|
254
|
+
insert_index = find_init_insert_index(id, lines, init_pattern)
|
255
|
+
lines.insert(insert_index, add_init)
|
256
|
+
|
257
|
+
::File.open(var_file, 'w') do |f|
|
258
|
+
lines.each do |line|
|
259
|
+
f << line
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
$stdout << "'#{id}' successfully added to #{var_file}.\n" if verbose
|
264
|
+
end
|
265
|
+
|
266
|
+
def self.del_variable(id, def_pattern, init_pattern, var_file)
|
267
|
+
lines = ::File.new(var_file).readlines
|
268
|
+
raise InvalidFileFormat, "Missing generation tags (#{START_DEFS}, #{END_DEFS}, #{START_INITS}, #{END_INITS})" unless generation_tags_found(lines)
|
269
|
+
unless id_exists_in_file?(id, lines, def_pattern)
|
270
|
+
$stderr << "ID '#{id}' does not exist in file #{var_file}\n" if verbose
|
271
|
+
return
|
272
|
+
end
|
273
|
+
|
274
|
+
delete_index = find_def_delete_index(id, lines, def_pattern)
|
275
|
+
lines.delete_at(delete_index) unless delete_index.nil?
|
276
|
+
|
277
|
+
delete_index = find_init_delete_index(id, lines, init_pattern)
|
278
|
+
lines.delete_at(delete_index) unless delete_index.nil?
|
279
|
+
|
280
|
+
::File.open(var_file, 'w') do |f|
|
281
|
+
lines.each do |line|
|
282
|
+
f << line
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
$stdout << "'#{id}' successfully deleted from #{var_file}.\n" if verbose
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ams_var_file
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff McAffee
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Generate AMS variable declaration files and provide for adding and deleting
|
84
|
+
variables.
|
85
|
+
email:
|
86
|
+
- jeff@ktechsystems.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- ams_var_file.gemspec
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- lib/ams_var_file.rb
|
102
|
+
- lib/ams_var_file/file.rb
|
103
|
+
- lib/ams_var_file/version.rb
|
104
|
+
homepage: https://github.com/jmcaffee/ams_var_file
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.3.0
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Generate AMS variable declaration files and provide for adding and deleting
|
128
|
+
variables.
|
129
|
+
test_files: []
|
130
|
+
has_rdoc:
|