easy_app_helper 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/README.md +65 -3
- data/Rakefile +5 -0
- data/easy_app_helper.gemspec +2 -1
- data/lib/easy_app_helper/version.rb +1 -1
- data/lib/tasks/easy_app_helper_tasks.rake +31 -0
- data/lib/tasks/template.rb.erb +69 -0
- data/lib/tasks/template_manager.rb +57 -0
- data/test/foo/Gemfile +6 -0
- data/test/foo/LICENSE.txt +22 -0
- data/test/foo/README.md +29 -0
- data/test/foo/Rakefile +8 -0
- data/test/foo/foo.gemspec +26 -0
- data/test/foo/lib/foo/version.rb +3 -0
- data/test/foo/lib/foo.rb +5 -0
- metadata +36 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0352ee0a8fcd905f3078f99d49ec0d0f1e760b4f
|
4
|
+
data.tar.gz: aa425b6c080f4b007e0b8eb21aa2d4871008a2ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fd9cd9cbc19b33177d7d26f89670bff03ee4fa5317adec804e5c7144230ee7d64e6fa854d165dfedee49fd149218e8b806eeb292ca7e968adb94ee8931be35f
|
7
|
+
data.tar.gz: 1cad685afd543aecab65bb53b24befd86af6d3c632e21a6ea23a36c3fa2968a92e214a9221af9bdc7a36bc75aaf0033e4cc752376bfc8022ffbbbc306efdba3b
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -174,11 +174,72 @@ nevertheless be the case.
|
|
174
174
|
There is a (not perfect) compatibility mode that you can trigger by setting the `easy_app_helper_compatibility_mode`
|
175
175
|
property to true in one of your config files.
|
176
176
|
|
177
|
-
##
|
177
|
+
## Generate scripts using rake task
|
178
|
+
|
179
|
+
### Including easy_app_helper tasks in your own gems.
|
180
|
+
|
181
|
+
For this you just need to include in your own gem `Rakefile`:
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
spec = Gem::Specification.find_by_name 'easy_app_helper'
|
185
|
+
load "#{spec.gem_dir}/Rakefile"
|
186
|
+
```
|
187
|
+
This will add two extra rake tasks to your gem. Normally if you created correctly your gem (`bundle gem my_gem`), you
|
188
|
+
already have 3 tasks existing coming from the `require "bundler/gem_tasks"` that you probably have in your default
|
189
|
+
Rakefile. Now will get something like this instead:
|
190
|
+
|
191
|
+
```shell
|
192
|
+
$ bundle exec rake -T
|
193
|
+
rake build # Build your_gem-0.0.1.gem into the pkg directory
|
194
|
+
rake easy_app_helper:create_executable[executable_name] # create automatically a new executable in "bin" from a template
|
195
|
+
rake easy_app_helper:show_template # Displays the template used
|
196
|
+
rake install # Build and install your_gem-0.0.1.gem into system gems
|
197
|
+
rake release # Create tag v0.0.1 and build and push your_gem-0.0.1.gem to Rubygems
|
198
|
+
```
|
199
|
+
The two [easy_app_helper][EAH] tasks are quite self-explanatory.
|
200
|
+
|
201
|
+
### Generating script templates for your project
|
202
|
+
|
203
|
+
Basically you will do a:
|
204
|
+
|
205
|
+
$ bundle rake easy_app_helper:create_executable
|
206
|
+
|
207
|
+
And it will reply something like:
|
208
|
+
|
209
|
+
```
|
210
|
+
File '/home/you/devel/ruby/gems/your_gem/bin/your_gem' created with execution rights.
|
211
|
+
-> Try: "bundle exec '/home/you/devel/ruby/gems/your_gem/bin/your_gem' --help"
|
212
|
+
```
|
178
213
|
|
179
|
-
|
214
|
+
It means that by default, the rake task will create a executable with the name of the gem you are currently developing.
|
215
|
+
__This task is safe and will never overwrite an existing file__. Instead, if the file already exists, you would get:
|
216
|
+
|
217
|
+
```
|
218
|
+
File '/home/you/devel/ruby/gems/your_gem/bin/your_gem' already exists !
|
219
|
+
-> Aborted.
|
220
|
+
```
|
221
|
+
|
222
|
+
You can, of course, specify your own file name to the rake task. Depending on your shell, and due to different
|
223
|
+
variable expansion mechanisms, you have to do it differently:
|
224
|
+
|
225
|
+
* __zsh__ should be something like: `bundle rake easy_app_helper:create_executable\[my_executable\]`
|
226
|
+
* whereas in __bash__ more probably: `bundle rake easy_app_helper:create_executable[my_executable]`
|
227
|
+
|
228
|
+
Check the documentation of your shell for further information.
|
229
|
+
You should nevertheless have this kind of answer from the task:
|
230
|
+
|
231
|
+
```
|
232
|
+
File '/home/you/devel/ruby/gems/your_gem/bin/my_executable' created with execution rights.
|
233
|
+
-> Try: "bundle exec '/home/you/devel/ruby/gems/your_gem/bin/my_executable' --help"
|
234
|
+
```
|
235
|
+
|
236
|
+
You can notice the slight changes in terms of code in the two generated scripts ;-). Check the template with
|
237
|
+
`bundle rake easy_app_helper:show_template` to understand how the template adapts.
|
238
|
+
|
239
|
+
|
240
|
+
## Complete example of a script based on `easy_app_helper`
|
180
241
|
|
181
|
-
|
242
|
+
This is not exactly what is generated by the rake task (which is more up-to-date), but gives an overall idea:
|
182
243
|
|
183
244
|
```ruby
|
184
245
|
#!/usr/bin/env ruby
|
@@ -194,6 +255,7 @@ class MyApp
|
|
194
255
|
DESCRIPTION = 'Best app ever'
|
195
256
|
|
196
257
|
def initialize
|
258
|
+
config.config_file_base_name = 'basename_for_my_config_files' # Default is the name of this script (w/o extensions)
|
197
259
|
config.describes_application app_name: NAME,
|
198
260
|
app_version: VERSION,
|
199
261
|
app_description: DESCRIPTION
|
data/Rakefile
CHANGED
data/easy_app_helper.gemspec
CHANGED
@@ -23,5 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'pry'
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
25
|
|
26
|
-
spec.
|
26
|
+
spec.add_dependency 'activesupport'
|
27
|
+
spec.add_runtime_dependency 'stacked_config', '~> 0.3'
|
27
28
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require File.expand_path '../template_manager.rb', __FILE__
|
5
|
+
|
6
|
+
namespace :easy_app_helper do
|
7
|
+
|
8
|
+
include EasyAppHelper::Tasks::TemplateManager
|
9
|
+
|
10
|
+
desc 'create automatically a new executable in "bin" from a template. Default name is Gem name'
|
11
|
+
task :create_executable, [:executable_name] do |tsk, args|
|
12
|
+
@task = tsk
|
13
|
+
script_content = build_executable args[:executable_name]
|
14
|
+
bin_dir = check_bin_dir
|
15
|
+
script_name = File.join bin_dir, executable_name
|
16
|
+
if File.exists? script_name
|
17
|
+
STDERR.puts "File '#{script_name}' already exists !\n -> Aborted."
|
18
|
+
next
|
19
|
+
end
|
20
|
+
File.write script_name, script_content
|
21
|
+
FileUtils.chmod 'u=wrx,go=rx', script_name
|
22
|
+
puts "File '#{script_name}' created with execution rights.\n -> Try: \"bundle exec '#{script_name}' --help\" to test it."
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Displays the template used.'
|
26
|
+
task :show_template do
|
27
|
+
puts get_template
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This file has been generated by easy_app_helper Gem on the <%= current_date %>
|
3
|
+
# See 'https://rubygems.org/gems/easy_app_helper'
|
4
|
+
|
5
|
+
require 'easy_app_helper'
|
6
|
+
require '<%= gem_name %>'
|
7
|
+
|
8
|
+
module <%= gem_module %>
|
9
|
+
class <%= script_class %>
|
10
|
+
|
11
|
+
# Inserted here, but you may probably have already defined this somewhere else...
|
12
|
+
NAME = '<%= executable_name.titleize %>'
|
13
|
+
DESCRIPTION = 'Description of <%= executable_name %>'
|
14
|
+
|
15
|
+
include EasyAppHelper
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
<% unless executable_name == gem_name -%>config.config_file_base_name = '<%= executable_name %>'
|
19
|
+
<% end -%>config.describes_application app_name: NAME,
|
20
|
+
app_version: <%= gem_module %>::VERSION,
|
21
|
+
app_description: DESCRIPTION
|
22
|
+
add_script_options
|
23
|
+
end
|
24
|
+
|
25
|
+
def run
|
26
|
+
# logging startup configuration
|
27
|
+
logger.debug "Config layers ->\n#{config.detailed_layers_info}"
|
28
|
+
logger.debug "Merged config -> #{config[].to_yaml}"
|
29
|
+
# Displaying (and exiting) command line help
|
30
|
+
if config[:help]
|
31
|
+
puts config.command_line_help
|
32
|
+
exit 0
|
33
|
+
end
|
34
|
+
check_config
|
35
|
+
logger.info 'Application is starting...'
|
36
|
+
do_process
|
37
|
+
rescue => e
|
38
|
+
puts "Program aborted with message: '#{e.message}'."
|
39
|
+
if config[:debug]
|
40
|
+
logger.fatal "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
|
41
|
+
else
|
42
|
+
puts ' Use --debug option for more detail (see --help).'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def add_script_options
|
49
|
+
## Create here your extra command-line options
|
50
|
+
## Here under are examples using potentially gem config layer to display default option value...
|
51
|
+
## Check Slop documentation for further info.
|
52
|
+
# config.add_command_line_section do |slop|
|
53
|
+
# slop.on :p, :port, "Specify port to bind to. Default #{config.gem_layer[:port]}.", argument: true, as: Integer
|
54
|
+
# slop.on :b, :bind, "Specify address to bind to. Default #{config.gem_layer[:bind]}.", argument: true, as: String
|
55
|
+
# end
|
56
|
+
end
|
57
|
+
|
58
|
+
def do_process
|
59
|
+
# Your code here.
|
60
|
+
end
|
61
|
+
|
62
|
+
def check_config
|
63
|
+
# Check the config and raise an exception if incorrect.
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
<%= gem_module %>::<%= script_class %>.new.run
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'active_support/core_ext/string/inflections'
|
3
|
+
|
4
|
+
module EasyAppHelper
|
5
|
+
module Tasks
|
6
|
+
|
7
|
+
module TemplateManager
|
8
|
+
|
9
|
+
attr_reader :executable_name, :gem_module, :gem_name, :current_date, :script_class, :task
|
10
|
+
|
11
|
+
TEMPLATE = File.expand_path '../template.rb.erb', __FILE__
|
12
|
+
|
13
|
+
def get_template
|
14
|
+
File.read TEMPLATE
|
15
|
+
end
|
16
|
+
|
17
|
+
def check_bin_dir
|
18
|
+
spec = current_gem_spec
|
19
|
+
rel_bin_dir = spec.bindir.empty? ? 'bin' : spec.bindir
|
20
|
+
bin_dir = File.join task.application.original_dir, rel_bin_dir
|
21
|
+
FileUtils.mkdir bin_dir unless Dir.exists? bin_dir
|
22
|
+
bin_dir
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_executable(executable_name=current_gem_name)
|
26
|
+
executable_name ||= current_gem_spec.name
|
27
|
+
@executable_name = executable_name
|
28
|
+
@gem_name = current_gem_spec.name
|
29
|
+
@gem_module = @gem_name.camelize
|
30
|
+
@current_date = Time.now.strftime('%c')
|
31
|
+
@script_class = executable_name == current_gem_spec.name ? '' : executable_name.camelize
|
32
|
+
@script_class << 'Script'
|
33
|
+
renderer = ERB.new(File.read(TEMPLATE), nil, '-')
|
34
|
+
renderer.result binding
|
35
|
+
end
|
36
|
+
|
37
|
+
def current_gem_spec
|
38
|
+
searcher = if Gem::Specification.respond_to? :find
|
39
|
+
# ruby 2.0
|
40
|
+
Gem::Specification
|
41
|
+
elsif Gem.respond_to? :searcher
|
42
|
+
# ruby 1.8/1.9
|
43
|
+
Gem.searcher.init_gemspecs
|
44
|
+
end
|
45
|
+
unless searcher.nil?
|
46
|
+
searcher.find do |spec|
|
47
|
+
original_file = task ? File.join(task.application.original_dir, task.application.rakefile) : __FILE__
|
48
|
+
File.fnmatch(File.join(spec.full_gem_path,'*'), original_file)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/test/foo/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 L.Briais
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/test/foo/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Foo
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'foo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install foo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/foo/fork )
|
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
|
data/test/foo/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'foo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'foo'
|
8
|
+
spec.version = Foo::VERSION
|
9
|
+
spec.authors = ['bar']
|
10
|
+
spec.email = ['bar@nowhere.org']
|
11
|
+
spec.summary = %q{Does Nothing.}
|
12
|
+
spec.description = %q{Does nothing, no more.}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'easy_app_helper'
|
25
|
+
|
26
|
+
end
|
data/test/foo/lib/foo.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_app_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- L.Briais
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,25 +67,33 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: activesupport
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0.1'
|
76
73
|
- - '>='
|
77
74
|
- !ruby/object:Gem::Version
|
78
|
-
version: 0
|
75
|
+
version: '0'
|
79
76
|
type: :runtime
|
80
77
|
prerelease: false
|
81
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: stacked_config
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
82
86
|
requirements:
|
83
87
|
- - ~>
|
84
88
|
- !ruby/object:Gem::Version
|
85
|
-
version: '0.
|
86
|
-
|
89
|
+
version: '0.3'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
87
95
|
- !ruby/object:Gem::Version
|
88
|
-
version: 0.
|
96
|
+
version: '0.3'
|
89
97
|
description: Easy Application Helpers framework
|
90
98
|
email:
|
91
99
|
- lbnetid+rb@gmail.com
|
@@ -109,10 +117,20 @@ files:
|
|
109
117
|
- lib/easy_app_helper/logger/wrapper.rb
|
110
118
|
- lib/easy_app_helper/managed_logger.rb
|
111
119
|
- lib/easy_app_helper/version.rb
|
120
|
+
- lib/tasks/easy_app_helper_tasks.rake
|
121
|
+
- lib/tasks/template.rb.erb
|
122
|
+
- lib/tasks/template_manager.rb
|
112
123
|
- spec/config_spec.rb
|
113
124
|
- spec/easy_app_helper_spec.rb
|
114
125
|
- spec/logger_spec.rb
|
115
126
|
- spec/spec_helper.rb
|
127
|
+
- test/foo/Gemfile
|
128
|
+
- test/foo/LICENSE.txt
|
129
|
+
- test/foo/README.md
|
130
|
+
- test/foo/Rakefile
|
131
|
+
- test/foo/foo.gemspec
|
132
|
+
- test/foo/lib/foo.rb
|
133
|
+
- test/foo/lib/foo/version.rb
|
116
134
|
homepage: https://github.com/lbriais/easy_app_helper
|
117
135
|
licenses:
|
118
136
|
- MIT
|
@@ -133,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
151
|
version: '0'
|
134
152
|
requirements: []
|
135
153
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.0.
|
154
|
+
rubygems_version: 2.0.0
|
137
155
|
signing_key:
|
138
156
|
specification_version: 4
|
139
157
|
summary: Provides cool helpers to your application, including configuration and logging
|
@@ -143,3 +161,10 @@ test_files:
|
|
143
161
|
- spec/easy_app_helper_spec.rb
|
144
162
|
- spec/logger_spec.rb
|
145
163
|
- spec/spec_helper.rb
|
164
|
+
- test/foo/Gemfile
|
165
|
+
- test/foo/LICENSE.txt
|
166
|
+
- test/foo/README.md
|
167
|
+
- test/foo/Rakefile
|
168
|
+
- test/foo/foo.gemspec
|
169
|
+
- test/foo/lib/foo.rb
|
170
|
+
- test/foo/lib/foo/version.rb
|