bin_script 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ log
2
2
  TODO
3
3
  locks
4
4
  *.gem
5
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,11 +1,3 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
- # Will automatically pull in this gem and all its
4
- # dependencies specified in the gemspec
5
- gem "bin_script", :path => File.expand_path("..", __FILE__)
6
-
7
- gem 'rails'
8
- gem 'activesupport'
9
- # These are development dependencies
10
- gem "rspec"
11
- gem 'rake'
3
+ gemspec
@@ -16,25 +16,24 @@ Rails 2.3 and 3 compatible
16
16
  gem 'bin_script'
17
17
  ```
18
18
 
19
- rails g bin:bin bla
20
- (for 2.3 copy generator into lib/generators and run: ./script/generate bin bla)
19
+ rails generate bin:bin bla
21
20
 
22
21
  Call like:
23
22
 
24
- $ cd project && ./bin/bla.rb -e production --test -d "2012-04-07" -u "asdf"
23
+ $ cd project && ./bin/bla -e production --test -d "2012-04-07" -u "asdf"
25
24
 
26
25
  Features by default:
27
26
 
28
- $ ./bin/bla.rb -h
29
- $ ./bin/bla.rb -e production
30
- $ ./bin/bla.rb -e production -L ./locks/bla.lock
31
- $ ./bin/bla.rb -e production -l ./log/bla.log
32
- $ ./bin/bla.rb -e production --daemonize --pidfile=./tmp/bla.pid
27
+ $ ./bin/bla -h
28
+ $ ./bin/bla -e production
29
+ $ ./bin/bla -e production -L ./locks/bla.lock
30
+ $ ./bin/bla -e production -l ./log/bla.log
31
+ $ ./bin/bla -e production --daemonize --pidfile ./tmp/bla.pid
33
32
 
34
33
 
35
34
  Example Bin
36
35
  -----------
37
- app/models/bin/bla_script.rb
36
+ app/bins/bla_script.rb
38
37
 
39
38
  ``` ruby
40
39
  class BlaScript < BinScript
@@ -58,36 +57,24 @@ class BlaScript < BinScript
58
57
  end
59
58
  ```
60
59
 
61
- ### Custom exception notifier (create initializer with:)
60
+ ### Options
62
61
 
63
62
  ``` ruby
64
- class BinScript
65
- def notify_about_error(exception)
66
- Mailter.some_notification(exception)...
67
- end
63
+ class BlaScript < BinScript
64
+ self.log_level = Logger::DEBUG
65
+ self.enable_locking = false
66
+ self.enable_logging = false
68
67
  end
69
68
  ```
70
69
 
71
-
72
- ### Create bin script without loading Rails Environment
73
- add into file ./bin/bla.rb
74
-
75
- NO_RAILS=true
76
-
77
- example:
70
+ ### Custom exception notifier (create initializer with:)
78
71
 
79
72
  ``` ruby
80
- NO_RAILS = true
81
- load Gem.bin_path('bin_script', 'bin_helper')
73
+ class BinScript
74
+ def notify_about_error(exception)
75
+ Mailter.some_notification(exception)...
76
+ end
77
+ end
82
78
  ```
83
79
 
84
-
85
- ### Options
86
-
87
- ``` ruby
88
- class BlaScript < BinScript
89
- self.log_level = Logger::DEBUG
90
- self.enable_locking = false
91
- self.enable_logging = false
92
- end
93
- ```
80
+
data/Rakefile CHANGED
@@ -1,17 +1,8 @@
1
1
  require 'rubygems'
2
- require "bundler"
3
- Bundler.setup
2
+ require 'bundler/setup'
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
4
5
 
5
6
  require 'rspec/core/rake_task'
6
-
7
7
  task :default => :spec
8
8
  RSpec::Core::RakeTask.new(:spec)
9
-
10
- require 'rubygems/package_task'
11
- require 'rubygems/specification'
12
-
13
- spec = eval(File.read('bin_script.gemspec'))
14
-
15
- Gem::PackageTask.new(spec) do |pkg|
16
- pkg.gem_spec = spec
17
- end
data/bin_script.gemspec CHANGED
@@ -21,7 +21,9 @@ For my purposes much better than Rake, Thor and Rails Runner.}
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_dependency 'activesupport', ">=2.3.2"
24
+ s.add_dependency 'activesupport'
25
+ s.add_dependency 'rails'
25
26
  s.add_development_dependency "rspec"
26
-
27
+ s.add_development_dependency "rake"
28
+
27
29
  end
@@ -85,6 +85,10 @@ class BinScript
85
85
  def script_name
86
86
  self.to_s.underscore.gsub('/','__')
87
87
  end
88
+
89
+ def bin_name
90
+ script_name.gsub('_script', '')
91
+ end
88
92
 
89
93
  # Parse script filename. Extract important path parts
90
94
  def parse_script_file_name(filename)
@@ -118,7 +122,7 @@ class BinScript
118
122
  files = []
119
123
 
120
124
  # Calculate and add to list file with script class itself
121
- class_file = File.join(%w{app models bin}, parts)
125
+ class_file = File.join(%w{app bins}, parts)
122
126
  class_file += '_nagios' if(parts.length > 1)
123
127
  class_file += '_script.rb'
124
128
  files << class_file
@@ -180,7 +184,7 @@ class BinScript
180
184
  def usage(message = nil)
181
185
  usage_msg = ''
182
186
  usage_msg += "Error: #{message}\n\n" unless message.nil?
183
- usage_msg += "Use: ./bin/#{script_name}.rb [OPTIONS]\n\n"
187
+ usage_msg += "Use: ./bin/#{bin_name}.rb [OPTIONS]\n\n"
184
188
  usage_msg += "\"#{self.description}\"\n\n" if message.nil? && self.description.present?
185
189
  usage_msg += "Availible options:\n\n"
186
190
 
@@ -258,24 +262,28 @@ class BinScript
258
262
 
259
263
  check_required_params
260
264
 
261
- info "====================="
262
-
263
265
  # Create and check lock file if enabled
264
266
  if self.class.enable_locking
265
267
  @lock = LockFile.new(lock_filename)
266
268
  @lock.quiet = true # Don't write errors to STDERR
267
- info "Use lock file: #{@lock.path}"
269
+
268
270
  if(@lock.lock)
269
- warn "Lock file '#{@lock.path}' already open in exclusive mode. Exit!"
271
+ msg = "--- Try start. Buy lock file '#{@lock.path}' already open in exclusive mode. Exit! ---"
272
+ # puts msg # puts is not good idea, because cron will mail it, but this is not error
273
+ warn msg
270
274
  exit
271
275
  end
272
276
  end
273
-
277
+
274
278
  begin
275
279
  # Log important info and call script job
276
- info "Log level = #{@logger.level}" if self.class.enable_logging
277
- info "Parameters: #{@params_values.inspect}"
278
- info "Starting script #{self.class.script_name}..."
280
+ info ""
281
+
282
+ log_params = {:env => RailsStub.env, :log_level => (self.class.enable_logging ? @logger.level : nil), :lock_file => (self.class.enable_locking ? @lock.path : nil)}
283
+
284
+ info "> Script #{self.class.script_name} started! (#{log_params.inspect})"
285
+ info "- Parameters: #{@params_values.inspect}"
286
+
279
287
  start = Time.now
280
288
 
281
289
  # Инкрементируем счетчик запусков этого скрипта
@@ -283,8 +291,7 @@ class BinScript
283
291
 
284
292
  do!
285
293
  duration = Time.now - start
286
- info "Script #{self.class.script_name} finished!"
287
- info "Script job duration: #{duration}"
294
+ info "< Script #{self.class.script_name} finished! (#{"%.4f" % duration.to_f} sec)"
288
295
  info "Exit status: #{@exit_status}" if @exit_status
289
296
 
290
297
  # Инкрементируем время работы э
@@ -311,7 +318,7 @@ class BinScript
311
318
 
312
319
  # Print usage message and exit
313
320
  def usage_exit(message = nil)
314
- error "Exit with error message: #{message}"
321
+ error "Exit with error message: #{message}" if message.present?
315
322
  Kernel.puts(self.class.usage(message))
316
323
  exit
317
324
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  class BinScript
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.7"
4
4
  end
@@ -6,10 +6,10 @@ if Rails::VERSION::MAJOR >= 3
6
6
  source_root File.expand_path("../templates", __FILE__)
7
7
 
8
8
  def add_files
9
- template "script.rb", "bin/#{file_path}.rb"
10
- template "script_class.rb", "app/models/bin/#{file_path}_script.rb"
11
- template "spec.rb", "spec/models/bin/#{file_path}_script_spec.rb"
12
- chmod "bin/#{file_path}.rb", 0755
9
+ template "script.rb", "bin/#{file_path}"
10
+ template "script_class.rb", "app/bins/#{file_path}_script.rb"
11
+ template "spec.rb", "spec/bins/#{file_path}_script_spec.rb"
12
+ chmod "bin/#{file_path}", 0755
13
13
  end
14
14
  end
15
15
  end
@@ -22,10 +22,10 @@ if Rails::VERSION::MAJOR == 2
22
22
  class BinGenerator < Rails::Generator::NamedBase
23
23
  def manifest
24
24
  record do |m|
25
- m.template "script.rb", "bin/#{file_path}.rb", :chmod => 0755
26
- m.template "script_class.rb", "app/models/bin/#{file_path}_script.rb"
27
- m.directory "spec/models/bin"
28
- m.template "spec.rb", "spec/models/bin/#{file_path}_script_spec.rb"
25
+ m.template "script.rb", "bin/#{file_path}", :chmod => 0755
26
+ m.template "script_class.rb", "app/bins/#{file_path}_script.rb"
27
+ m.directory "spec/bins"
28
+ m.template "spec.rb", "spec/bins/#{file_path}_script_spec.rb"
29
29
  end
30
30
  end
31
31
  end
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by BinScript gem.
4
+ #
5
+ # This bin '<%= file_path %>' is a runner for app/bins/<%= file_path %>_script.rb
6
+ #
2
7
 
3
8
  require 'pathname'
4
9
  path = File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
@@ -15,8 +15,8 @@ describe BinScript do
15
15
  describe "class name detection" do
16
16
  before(:all) do
17
17
  @test_date = [
18
- {:filename => "/prj/bin/nagios/some.rb", :parts => ['nagios','some'], :class => "Nagios::SomeNagiosScript", :files => ["app/models/nagios_script.rb", "app/models/bin/nagios/some_nagios_script.rb"]},
19
- {:filename => "/prj/bin/another.rb", :parts => ['another'], :class => "AnotherScript", :files => ["app/models/bin/another_script.rb"]}
18
+ {:filename => "/prj/bin/nagios/some.rb", :parts => ['nagios','some'], :class => "Nagios::SomeNagiosScript", :files => ["app/models/nagios_script.rb", "app/bins/nagios/some_nagios_script.rb"]},
19
+ {:filename => "/prj/bin/another.rb", :parts => ['another'], :class => "AnotherScript", :files => ["app/bins/another_script.rb"]}
20
20
  ]
21
21
  @test_keys = [:parts, :class, :files]
22
22
  end
@@ -107,7 +107,7 @@ describe BinScript do
107
107
  describe "usage" do
108
108
  it "should generate usage message" do
109
109
  USAGE = <<USAGE
110
- Use: ./bin/test_script.rb [OPTIONS]
110
+ Use: ./bin/test.rb [OPTIONS]
111
111
 
112
112
  Availible options:
113
113
 
@@ -181,4 +181,4 @@ USAGE
181
181
  end
182
182
  end
183
183
 
184
- end
184
+ end
metadata CHANGED
@@ -1,68 +1,93 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bin_script
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 6
10
- version: 0.1.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.7
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Makarchev Konstantin
14
9
  - Lifshits Dmitry
15
10
  autorequire: init
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2012-04-08 00:00:00 +04:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
13
+ date: 2012-08-25 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
23
16
  name: activesupport
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
24
  prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
26
26
  none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 7
31
- segments:
32
- - 2
33
- - 3
34
- - 2
35
- version: 2.3.2
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rails
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
36
39
  type: :runtime
37
- version_requirements: *id001
38
- - !ruby/object:Gem::Dependency
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
39
48
  name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
40
56
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ requirement: !ruby/object:Gem::Requirement
42
66
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 3
47
- segments:
48
- - 0
49
- version: "0"
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
50
71
  type: :development
51
- version_requirements: *id002
52
- description: Easy writing and executing bins(executable scripts) in Rails Application (especially for crontab or god)
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ description: Easy writing and executing bins(executable scripts) in Rails Application
80
+ (especially for crontab or god)
53
81
  email: kostya27@gmail.com
54
- executables:
82
+ executables:
55
83
  - bin_helper
56
84
  extensions: []
57
-
58
85
  extra_rdoc_files: []
59
-
60
- files:
86
+ files:
61
87
  - .gitignore
62
88
  - Gemfile
63
- - Gemfile.lock
64
89
  - LICENSE
65
- - README.markdown
90
+ - README.md
66
91
  - Rakefile
67
92
  - bin/bin_helper
68
93
  - bin_script.gemspec
@@ -80,39 +105,36 @@ files:
80
105
  - lib/generators/bin/templates/spec.rb
81
106
  - spec/bin_script_spec.rb
82
107
  - spec/spec_helper.rb
83
- has_rdoc: true
84
108
  homepage: http://github.com/kostya/bin_script
85
109
  licenses: []
86
-
87
110
  post_install_message:
88
111
  rdoc_options: []
89
-
90
- require_paths:
112
+ require_paths:
91
113
  - lib
92
- required_ruby_version: !ruby/object:Gem::Requirement
114
+ required_ruby_version: !ruby/object:Gem::Requirement
93
115
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- hash: 3
98
- segments:
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ segments:
99
121
  - 0
100
- version: "0"
101
- required_rubygems_version: !ruby/object:Gem::Requirement
122
+ hash: 319463119
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
124
  none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- hash: 3
107
- segments:
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ segments:
108
130
  - 0
109
- version: "0"
131
+ hash: 319463119
110
132
  requirements: []
111
-
112
133
  rubyforge_project:
113
- rubygems_version: 1.3.7
134
+ rubygems_version: 1.8.24
114
135
  signing_key:
115
136
  specification_version: 3
116
- summary: Easy writing and executing bins(executable scripts) in Rails Application (especially for crontab or god). For my purposes much better than Rake, Thor and Rails Runner.
137
+ summary: Easy writing and executing bins(executable scripts) in Rails Application
138
+ (especially for crontab or god). For my purposes much better than Rake, Thor and
139
+ Rails Runner.
117
140
  test_files: []
118
-
data/Gemfile.lock DELETED
@@ -1,104 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- bin_script (0.1.6)
5
- activesupport (>= 2.3.2)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- actionmailer (3.2.3)
11
- actionpack (= 3.2.3)
12
- mail (~> 2.4.4)
13
- actionpack (3.2.3)
14
- activemodel (= 3.2.3)
15
- activesupport (= 3.2.3)
16
- builder (~> 3.0.0)
17
- erubis (~> 2.7.0)
18
- journey (~> 1.0.1)
19
- rack (~> 1.4.0)
20
- rack-cache (~> 1.2)
21
- rack-test (~> 0.6.1)
22
- sprockets (~> 2.1.2)
23
- activemodel (3.2.3)
24
- activesupport (= 3.2.3)
25
- builder (~> 3.0.0)
26
- activerecord (3.2.3)
27
- activemodel (= 3.2.3)
28
- activesupport (= 3.2.3)
29
- arel (~> 3.0.2)
30
- tzinfo (~> 0.3.29)
31
- activeresource (3.2.3)
32
- activemodel (= 3.2.3)
33
- activesupport (= 3.2.3)
34
- activesupport (3.2.3)
35
- i18n (~> 0.6)
36
- multi_json (~> 1.0)
37
- arel (3.0.2)
38
- builder (3.0.0)
39
- diff-lcs (1.1.3)
40
- erubis (2.7.0)
41
- hike (1.2.1)
42
- i18n (0.6.0)
43
- journey (1.0.3)
44
- json (1.6.6)
45
- mail (2.4.4)
46
- i18n (>= 0.4.0)
47
- mime-types (~> 1.16)
48
- treetop (~> 1.4.8)
49
- mime-types (1.18)
50
- multi_json (1.2.0)
51
- polyglot (0.3.3)
52
- rack (1.4.1)
53
- rack-cache (1.2)
54
- rack (>= 0.4)
55
- rack-ssl (1.3.2)
56
- rack
57
- rack-test (0.6.1)
58
- rack (>= 1.0)
59
- rails (3.2.3)
60
- actionmailer (= 3.2.3)
61
- actionpack (= 3.2.3)
62
- activerecord (= 3.2.3)
63
- activeresource (= 3.2.3)
64
- activesupport (= 3.2.3)
65
- bundler (~> 1.0)
66
- railties (= 3.2.3)
67
- railties (3.2.3)
68
- actionpack (= 3.2.3)
69
- activesupport (= 3.2.3)
70
- rack-ssl (~> 1.3.2)
71
- rake (>= 0.8.7)
72
- rdoc (~> 3.4)
73
- thor (~> 0.14.6)
74
- rake (0.9.2.2)
75
- rdoc (3.12)
76
- json (~> 1.4)
77
- rspec (2.9.0)
78
- rspec-core (~> 2.9.0)
79
- rspec-expectations (~> 2.9.0)
80
- rspec-mocks (~> 2.9.0)
81
- rspec-core (2.9.0)
82
- rspec-expectations (2.9.1)
83
- diff-lcs (~> 1.1.3)
84
- rspec-mocks (2.9.0)
85
- sprockets (2.1.2)
86
- hike (~> 1.2)
87
- rack (~> 1.0)
88
- tilt (~> 1.1, != 1.3.0)
89
- thor (0.14.6)
90
- tilt (1.3.3)
91
- treetop (1.4.10)
92
- polyglot
93
- polyglot (>= 0.3.1)
94
- tzinfo (0.3.32)
95
-
96
- PLATFORMS
97
- ruby
98
-
99
- DEPENDENCIES
100
- activesupport
101
- bin_script!
102
- rails
103
- rake
104
- rspec