sinatralive 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ecb90039f27f0597839380ee98953509a2bcf40
4
+ data.tar.gz: 2132d234097536503b4bfa6f28208e9a2c07c976
5
+ SHA512:
6
+ metadata.gz: 4cac841d1f43fe48de99154476fc3938bed6525512def91d34afd1aa88f88215f7ea14288f4167b6bf11070fe4ab64035ea7dc754ce2a1644f972d4086fa59cd
7
+ data.tar.gz: 665837314bc33f7e89b57aa2be995d1e2e0f8bd296f2ab097004df26c7f92600ccdc2f995083f70de45922f7122b11ada392ecdd6c59f1e060cfe3019c8ece65
@@ -0,0 +1,5 @@
1
+ Copyright (c) 2014, Alma Media Suomi Oyj
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
+
5
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,35 @@
1
+ Sinatra (live)
2
+ ==============
3
+
4
+ Watches for changes in your Sinatra-app and reloads Puma daemon with the new app.
5
+
6
+ ## Usage
7
+
8
+ First, create a Livefile on your Sinatra-app -root.
9
+
10
+ ```
11
+ $: sinatra-live init
12
+ Livefile created
13
+ ```
14
+
15
+ Edit the Livefile to match your own settings.
16
+
17
+ ```
18
+ ---
19
+ folders:
20
+ - lib
21
+ - conf
22
+
23
+ puma:
24
+ control: http://127.0.0.1:3001
25
+ token: c68e108c4ae2755ab1e93bc3fc956845033ab8b0
26
+ ```
27
+
28
+ Start sinatra-live.
29
+
30
+ ```
31
+ $: sinatra-live
32
+ Watching for changes in:
33
+ lib/
34
+ config/
35
+ ```
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sinatra_live'
@@ -0,0 +1,8 @@
1
+ ---
2
+ folders:
3
+ - lib
4
+ - conf
5
+
6
+ puma:
7
+ control:
8
+ token:
@@ -0,0 +1,64 @@
1
+ require_relative "utils"
2
+ require 'colorize'
3
+ require 'clamp'
4
+ require 'filewatcher'
5
+ require 'net/http'
6
+
7
+ class InitCommand < Clamp::Command
8
+
9
+ def execute
10
+ # check for existing Livefile
11
+ unless File.exists?('Livefile')
12
+ # load template
13
+ template = get_livefile_template
14
+
15
+ # save the template to a Livefile
16
+ File.open('Livefile', 'w') { |file|
17
+ file.write(template)
18
+ }
19
+
20
+ log "Livefile created"
21
+ else
22
+ log_error 'Livefile already exists!'
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ class WatchCommand < Clamp::Command
29
+
30
+ def execute
31
+ # read Livefile
32
+ livefile = load_livefile
33
+ # start watching folders
34
+ log "Watching folders for changes"
35
+ livefile['folders'].each do |folder|
36
+ log "\t#{folder}"
37
+ end
38
+ puts
39
+
40
+ FileWatcher.new(livefile['folders']).watch do |filename|
41
+ log "Updated " + filename
42
+ # call control url to reload on changes
43
+ puma_control_url = livefile['puma']['control'] + "/restart?token=" + livefile['puma']['token']
44
+
45
+ result = Net::HTTP.get(URI.parse(puma_control_url))
46
+ log "\tserver restart"
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ class SinatraLiveCommand < Clamp::Command
54
+
55
+ puts "\nSinatra (live)\n".light_blue
56
+
57
+ self.default_subcommand = 'watch'
58
+
59
+ subcommand 'watch', 'Start watching for changes (default)', WatchCommand
60
+ subcommand 'init', 'Create default Livefile.', InitCommand
61
+
62
+ end
63
+
64
+ SinatraLiveCommand.run
@@ -0,0 +1,23 @@
1
+ require 'colorize'
2
+ require 'yaml'
3
+
4
+ def log_error(msg)
5
+ puts "#{msg}".red
6
+ end
7
+
8
+ def log(msg, sender='')
9
+ unless sender.empty?
10
+ puts sender.green
11
+ end
12
+ puts "#{msg}".light_green
13
+ end
14
+
15
+ def get_livefile_template
16
+ file_path = File.join(File.dirname(File.expand_path(__FILE__)), 'Livefile.template')
17
+
18
+ File.open(file_path, 'rb').read
19
+ end
20
+
21
+ def load_livefile
22
+ YAML.load_file('Livefile')
23
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatralive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kai Kousa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: filewatcher
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: clamp
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Watches for changes in your Sinatra-app and reloads Puma daemon with
56
+ the new app code.
57
+ email: kai.kousa@almamedia.fi
58
+ executables:
59
+ - sinatra-live
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - lib/Livefile.template
64
+ - lib/sinatra_live.rb
65
+ - lib/utils.rb
66
+ - LICENSE.md
67
+ - README.md
68
+ - bin/sinatra-live
69
+ homepage: https://github.com/almamedia/sinatra-live
70
+ licenses:
71
+ - ISC
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.0.14
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Puma reloader for Sinatra-apps.
93
+ test_files: []