filegen 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rdebugrc +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +10 -0
- data/.simplecov +9 -0
- data/.travis.yml +7 -0
- data/.yardopts +6 -0
- data/Gemfile +30 -0
- data/{LICENSE.txt → LICENSE.md} +1 -1
- data/README.DEVELOPER.md +28 -0
- data/README.md +106 -7
- data/Rakefile +60 -1
- data/bin/filegen +1 -1
- data/config/rubocop-disabled.yml +0 -0
- data/config/rubocop-enabled.yml +140 -0
- data/cucumber.yml +2 -0
- data/features/evaluate_template.feature +134 -0
- data/features/output_meta_data.feature +20 -0
- data/features/step_definitions.rb +9 -0
- data/features/support/env.rb +20 -0
- data/filegen.gemspec +8 -9
- data/lib/filegen.rb +11 -1
- data/lib/filegen/data.rb +48 -0
- data/lib/filegen/data_source_builder.rb +49 -0
- data/lib/filegen/data_sources.rb +5 -0
- data/lib/filegen/data_sources/environment.rb +21 -0
- data/lib/filegen/data_sources/yaml.rb +18 -0
- data/lib/filegen/erb_generator.rb +21 -6
- data/lib/filegen/exceptions.rb +8 -0
- data/lib/filegen/options.rb +77 -6
- data/lib/filegen/runner.rb +29 -9
- data/lib/filegen/version.rb +2 -1
- data/rubocop-todo.yml +144 -0
- data/scripts/terminal +12 -0
- data/spec/data_source_builder_spec.rb +53 -0
- data/spec/data_sources/environment_spec.rb +20 -0
- data/spec/data_sources/yaml_spec.rb +31 -0
- data/spec/data_spec.rb +60 -0
- data/spec/erb_generator_spec.rb +31 -0
- data/spec/options_spec.rb +32 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/config.rb +6 -0
- data/spec/support/debugging.rb +5 -0
- data/spec/support/environment.rb +7 -0
- data/spec/support/filesystem.rb +11 -0
- data/spec/support/here_doc.rb +2 -0
- metadata +58 -25
- data/lib/filegen/env.rb +0 -14
data/.gitignore
CHANGED
data/.rdebugrc
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.simplecov
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
CHANGED
@@ -2,3 +2,33 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in filegen.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'aruba', git: 'https://github.com/cucumber/aruba.git'
|
8
|
+
gem 'cucumber'
|
9
|
+
gem 'fuubar'
|
10
|
+
gem 'rspec'
|
11
|
+
gem 'simplecov'
|
12
|
+
gem 'rubocop'
|
13
|
+
gem 'coveralls'
|
14
|
+
end
|
15
|
+
|
16
|
+
group :development do
|
17
|
+
gem 'debugger'
|
18
|
+
gem 'awesome_print'
|
19
|
+
gem 'debugger-completion'
|
20
|
+
gem 'pry'
|
21
|
+
gem 'pry-debugger'
|
22
|
+
gem 'pry-doc'
|
23
|
+
gem 'tmrb'
|
24
|
+
gem 'yard'
|
25
|
+
gem 'github-markup'
|
26
|
+
gem 'redcarpet'
|
27
|
+
end
|
28
|
+
|
29
|
+
gem 'rake', group: [:development, :test]
|
30
|
+
gem 'fedux_org-stdlib', group: [:development, :test]
|
31
|
+
gem 'bundler', '~> 1.3', group: [:development, :test]
|
32
|
+
gem 'erubis', group: [:development, :test]
|
33
|
+
gem 'versionomy', group: [:development, :test]
|
34
|
+
gem 'activesupport', group: [:development, :test]
|
data/{LICENSE.txt → LICENSE.md}
RENAMED
data/README.DEVELOPER.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Filegen (Developer Readme)
|
2
|
+
|
3
|
+
## Utilities
|
4
|
+
|
5
|
+
* Code coverage: simplecov
|
6
|
+
* Code quality: rubocop
|
7
|
+
* Documentation: yard
|
8
|
+
* Tasks: rake
|
9
|
+
* Testing: rspec, cucumber + aruba
|
10
|
+
* Testing-Helper: fedux_org-stdlib
|
11
|
+
|
12
|
+
## Contributing
|
13
|
+
|
14
|
+
1. Fork it
|
15
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
16
|
+
3. Write your tests
|
17
|
+
4. Commit your changes (`git commit -am 'Add some tests for feature'`)
|
18
|
+
5. Write your code
|
19
|
+
6. Commit your changes (`git commit -am 'Add some feature'`)
|
20
|
+
7. Make sure all tests pass (`bundle exec rspec && bundle exec cucumber`)
|
21
|
+
8. Make sure rubocop does not find any offences (`rubocop`)
|
22
|
+
9. Push to the branch (`git push origin my-new-feature`)
|
23
|
+
10. Create new Pull Request
|
24
|
+
11. Make sure all tests pass on travis
|
25
|
+
|
26
|
+
Commits must not...
|
27
|
+
* change the version-number
|
28
|
+
* contain rubocop:disable-comments
|
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Filegen
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/dg-vrnetze/filegen.png?branch=master)](https://travis-ci.org/dg-vrnetze/filegen)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/dg-vrnetze/filegen.png)](https://codeclimate.com/github/dg-vrnetze/filegen)
|
5
|
+
|
6
|
+
Have you ever felt the need to generate files based on environment variables or
|
7
|
+
yaml files? If your answer is yes, then `filegen` can be quite helpful for
|
8
|
+
you. If your answer is no, than sorry Ma'am, this gem is not for you.
|
4
9
|
|
5
10
|
## Installation
|
6
11
|
|
@@ -16,14 +21,108 @@ Or install it yourself as:
|
|
16
21
|
|
17
22
|
$ gem install filegen
|
18
23
|
|
24
|
+
This gem ships with an executable called `filegen`. It makes the power of ERB
|
25
|
+
available on the commandline.
|
26
|
+
|
19
27
|
## Usage
|
20
28
|
|
21
|
-
|
29
|
+
### General advice
|
30
|
+
|
31
|
+
Please make sure you have an ERB-template available. It needs to end with
|
32
|
+
`.erb`! Place in anywhere you like. It's important that the name of variable in
|
33
|
+
the template matches the name of environment variable or yaml-key: wording,
|
34
|
+
case. The lookup is case-sensitive. If you want to get access to the variable,
|
35
|
+
you need to use the `lookup`-method.
|
36
|
+
|
37
|
+
```
|
38
|
+
lookup(<variable>)
|
39
|
+
```
|
40
|
+
|
41
|
+
If you want to write the output to a file you need
|
42
|
+
to redirect stdout with `>`. Otherwise it will output the content on `$stdout`.
|
43
|
+
|
44
|
+
### Variable lookup
|
45
|
+
|
46
|
+
The default order of data sources to lookup a variable, is: 1st environment
|
47
|
+
variable and 2nd yaml file. The yaml file needs be given as command line argument
|
48
|
+
see below at [Generate a file based on YAML file](#yaml).
|
49
|
+
|
50
|
+
The order of data sources can be changed by using:
|
51
|
+
|
52
|
+
```
|
53
|
+
--data-sources env,yaml
|
54
|
+
--data-sources yaml,env
|
55
|
+
```
|
56
|
+
|
57
|
+
A short cut for `--data-sources` is `-d`. This option can also be used to ommit
|
58
|
+
a data source. But it makes sense only for the enviroment data source today,
|
59
|
+
because the yaml data source is only added if a yaml file name is given on the
|
60
|
+
commandline
|
61
|
+
|
62
|
+
```
|
63
|
+
--data-sources yaml
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
### Generate a file based on Environment Variables
|
70
|
+
|
71
|
+
The content of `template.erb`:
|
72
|
+
|
73
|
+
```erb
|
74
|
+
Hello my name is: <%= lookup('NAME') %>
|
75
|
+
```
|
76
|
+
|
77
|
+
After that you can use it with filegen.
|
78
|
+
|
79
|
+
```bash
|
80
|
+
NAME=Karl filegen template.erb > file
|
81
|
+
```
|
82
|
+
|
83
|
+
And get the following result.
|
84
|
+
|
85
|
+
```text
|
86
|
+
Hello my name is: Karl
|
87
|
+
```
|
88
|
+
|
89
|
+
### Generate a file based on YAML file
|
90
|
+
<a id="yaml"></a>
|
91
|
+
|
92
|
+
The content of `template.erb`:
|
93
|
+
|
94
|
+
```erb
|
95
|
+
Hello my name is: <%= lookup('NAME') %>
|
96
|
+
```
|
97
|
+
|
98
|
+
Additionally you need to create a `YAML`-file - e.g. `names.yaml`.
|
99
|
+
|
100
|
+
```yaml
|
101
|
+
---
|
102
|
+
NAME: Karl
|
103
|
+
```
|
104
|
+
|
105
|
+
After that you can use it with filegen.
|
106
|
+
|
107
|
+
```bash
|
108
|
+
#short format
|
109
|
+
filegen -y names.yaml template.erb > file
|
110
|
+
|
111
|
+
#long format
|
112
|
+
filegen --yaml-file names.yaml template.erb > file
|
113
|
+
```
|
114
|
+
|
115
|
+
And get the following result.
|
116
|
+
|
117
|
+
```text
|
118
|
+
Hello my name is: Karl
|
119
|
+
```
|
120
|
+
|
121
|
+
## Future
|
122
|
+
|
123
|
+
* Maybe I will add additional data sources. Please see the
|
124
|
+
[Moneta](https://github.com/minad/moneta)-gem for possible candidates.
|
22
125
|
|
23
126
|
## Contributing
|
24
127
|
|
25
|
-
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
128
|
+
Please have a look at the {file:README.DEVELOPER.md developer readme}
|
data/Rakefile
CHANGED
@@ -1 +1,60 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'fedux_org/stdlib/rake'
|
4
|
+
|
5
|
+
require 'filegen/version'
|
6
|
+
|
7
|
+
def software
|
8
|
+
'filegen'
|
9
|
+
end
|
10
|
+
|
11
|
+
def version
|
12
|
+
Filegen::VERSION
|
13
|
+
end
|
14
|
+
|
15
|
+
def root_directory
|
16
|
+
File.expand_path('../', __FILE__)
|
17
|
+
end
|
18
|
+
|
19
|
+
def tar_file
|
20
|
+
File.join(pkg_directory, "#{software}-#{version}.tar.gz")
|
21
|
+
end
|
22
|
+
|
23
|
+
def tmp_directory
|
24
|
+
File.join(root_directory, 'tmp', "#{software}-#{version}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def gem_file
|
28
|
+
File.join(root_directory, 'pkg', "#{software}-#{version}.gem")
|
29
|
+
end
|
30
|
+
|
31
|
+
def pkg_directory
|
32
|
+
File.join(root_directory, 'pkg')
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => 'gem:build'
|
36
|
+
|
37
|
+
file gem_file => 'gem:build'
|
38
|
+
|
39
|
+
file tmp_directory do
|
40
|
+
FileUtils.mkdir_p tmp_directory
|
41
|
+
end
|
42
|
+
|
43
|
+
namespace :gem do
|
44
|
+
desc 'build tar file'
|
45
|
+
task :package => [gem_file, tmp_directory] do
|
46
|
+
FileUtils.mv File.join(pkg_directory,"#{software}-#{version}.gem"), tmp_directory
|
47
|
+
|
48
|
+
Dir.chdir('tmp') do
|
49
|
+
sh "tar -czf #{tar_file} #{File.basename tmp_directory}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
require 'coveralls/rake/task'
|
55
|
+
Coveralls::RakeTask.new
|
56
|
+
|
57
|
+
namespace :test do
|
58
|
+
desc 'Test with coveralls'
|
59
|
+
task :coveralls => ['test:rspec', 'test:cucumber', 'coveralls:push']
|
60
|
+
end
|
data/bin/filegen
CHANGED
File without changes
|
@@ -0,0 +1,140 @@
|
|
1
|
+
AccessModifierIndentation:
|
2
|
+
Enabled: true
|
3
|
+
|
4
|
+
Alias:
|
5
|
+
Enabled: true
|
6
|
+
|
7
|
+
AlignParameters:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Blocks:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
BracesAroundHashParameters:
|
14
|
+
Enabled: true
|
15
|
+
|
16
|
+
CharacterLiteral:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
ClassVars:
|
20
|
+
Enabled: true
|
21
|
+
|
22
|
+
CollectionMethods:
|
23
|
+
Enabled: true
|
24
|
+
|
25
|
+
ColonMethodCall:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
Documentation:
|
29
|
+
Enabled: true
|
30
|
+
|
31
|
+
EmptyLinesAroundAccessModifier:
|
32
|
+
Enabled: true
|
33
|
+
|
34
|
+
CaseEquality:
|
35
|
+
Enabled: true
|
36
|
+
|
37
|
+
EmptyLinesAroundBody:
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
Encoding:
|
41
|
+
Enabled: true
|
42
|
+
|
43
|
+
Eval:
|
44
|
+
Enabled: true
|
45
|
+
|
46
|
+
FinalNewline:
|
47
|
+
Enabled: true
|
48
|
+
|
49
|
+
HashSyntax:
|
50
|
+
Enabled: true
|
51
|
+
|
52
|
+
IfUnlessModifier:
|
53
|
+
Enabled: true
|
54
|
+
|
55
|
+
IndentationWidth:
|
56
|
+
Enabled: true
|
57
|
+
|
58
|
+
Lambda:
|
59
|
+
Enabled: true
|
60
|
+
|
61
|
+
LeadingCommentSpace:
|
62
|
+
Enabled: true
|
63
|
+
|
64
|
+
LineLength:
|
65
|
+
Max: 188
|
66
|
+
|
67
|
+
MethodLength:
|
68
|
+
Max: 23
|
69
|
+
|
70
|
+
ParenthesesAroundCondition:
|
71
|
+
Enabled: true
|
72
|
+
|
73
|
+
PerlBackrefs:
|
74
|
+
Enabled: true
|
75
|
+
|
76
|
+
RaiseArgs:
|
77
|
+
Enabled: true
|
78
|
+
|
79
|
+
RedundantSelf:
|
80
|
+
Enabled: true
|
81
|
+
|
82
|
+
RegexpLiteral:
|
83
|
+
Enabled: true
|
84
|
+
|
85
|
+
Semicolon:
|
86
|
+
Enabled: true
|
87
|
+
|
88
|
+
SignalException:
|
89
|
+
Enabled: true
|
90
|
+
|
91
|
+
SingleLineBlockParams:
|
92
|
+
Enabled: true
|
93
|
+
|
94
|
+
SpaceAfterComma:
|
95
|
+
Enabled: true
|
96
|
+
|
97
|
+
SpaceAfterControlKeyword:
|
98
|
+
Enabled: true
|
99
|
+
|
100
|
+
SpaceAfterNot:
|
101
|
+
Enabled: true
|
102
|
+
|
103
|
+
SpaceAroundBlockBraces:
|
104
|
+
Enabled: true
|
105
|
+
|
106
|
+
SpaceAroundEqualsInParameterDefault:
|
107
|
+
Enabled: true
|
108
|
+
|
109
|
+
SpaceAroundOperators:
|
110
|
+
Enabled: true
|
111
|
+
|
112
|
+
SpaceInsideBrackets:
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
SpaceInsideHashLiteralBraces:
|
116
|
+
Enabled: true
|
117
|
+
|
118
|
+
SpaceInsideParens:
|
119
|
+
Enabled: true
|
120
|
+
|
121
|
+
SpecialGlobalVars:
|
122
|
+
Enabled: true
|
123
|
+
|
124
|
+
StringLiterals:
|
125
|
+
Enabled: true
|
126
|
+
|
127
|
+
TrailingBlankLines:
|
128
|
+
Enabled: true
|
129
|
+
|
130
|
+
TrailingWhitespace:
|
131
|
+
Enabled: true
|
132
|
+
|
133
|
+
TrivialAccessors:
|
134
|
+
Enabled: true
|
135
|
+
|
136
|
+
UselessAssignment:
|
137
|
+
Enabled: true
|
138
|
+
|
139
|
+
WordArray:
|
140
|
+
Enabled: true
|