runter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rake'
data/Gemfile.lock ADDED
@@ -0,0 +1,10 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ rake (10.3.1)
5
+
6
+ PLATFORMS
7
+ ruby
8
+
9
+ DEPENDENCIES
10
+ rake
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Karl Stoney
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ ## IMPORTANT
2
+ This project is in early, early stages.
3
+ Don't expect anything reliable just yet.
4
+ Even though the instructions state it, it isn't currently uploaded to Rubygems and won't be until I'm happy with it.
5
+
6
+ ## Runter
7
+ Runter is a task runner for Ruby.
8
+ The general idea is it exposes a modular way of performing tasks when a file or file(s) in your project are modified.
9
+
10
+ # Usage
11
+ ```
12
+ gem install runter
13
+ ```
14
+
15
+ From there, you need to create a Runtfile in the root of your project, something like this:
16
+ ```
17
+ {
18
+ "watchers":[
19
+ {
20
+ "name": "libwatch",
21
+ "src": ["lib/**/*"],
22
+ "singleFileActions": [
23
+ "echo 'Single Action: $1 was modified'"
24
+ ],
25
+ "bulkActions": [
26
+ "echo 'Bulk Action: Runter detected some changes'"
27
+ ]
28
+ }
29
+ ]
30
+ }
31
+ ```
32
+
33
+ To start the monitor, type
34
+ ```
35
+ runter
36
+ ```
37
+
38
+ And that's it. From there your actions will be executed as defined in your Runtfile!
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ namespace "gem" do
2
+
3
+ desc "Cleans any old .gem files"
4
+ task :clean do
5
+ Dir["*.gem"].each {|item|
6
+ puts "Removing: #{item}"
7
+ File.delete(item)
8
+ }
9
+ end
10
+
11
+ desc "Builds the gem package"
12
+ task :build do
13
+ puts "Building gem file..."
14
+ puts %x[gem build #{Dir["*.gemspec"].first()}]
15
+ end
16
+
17
+ desc "Installs the gem package"
18
+ task :install do
19
+ puts "Installing gem file..."
20
+ puts %x[gem install #{Dir["*.gem"].first()} --no-document]
21
+ end
22
+
23
+ desc "Cleans, Builds and Installs the gem"
24
+ task :cbi => ["gem:clean", "gem:build", "gem:install"] do
25
+ puts "Done."
26
+ end
27
+ end
data/Runtfile ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "watchers":[
3
+ {
4
+ "name": "libwatch",
5
+ "src": ["lib/**/*"],
6
+ "singleFileActions": [
7
+ "echo '$1 was modified'"
8
+ ],
9
+ "bulkActions": [
10
+ "echo 'Runter detected some changes'"
11
+ ]
12
+ }
13
+ ]
14
+ }
data/bin/runter ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'rubygems'
5
+ gem 'runter'
6
+ rescue LoadError
7
+ end
8
+
9
+ require 'runter'
10
+
11
+ Runter.application.run
data/lib/runter.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Runter
2
+ VERSION = '0.1.0'
3
+ end
4
+
5
+ require 'filewatcher'
6
+ require 'json'
7
+
8
+ require 'runter/shell'
9
+ require 'runter/watcher'
10
+ require 'runter/runtfile'
11
+ require 'runter/application'
@@ -0,0 +1,42 @@
1
+ # Handles the read and write of the runt file
2
+ require 'filewatcher'
3
+ module Runter
4
+
5
+ class Application
6
+ def initialize
7
+ @name = "runter"
8
+ @runtFile = Runter::Runtfile.new
9
+ end
10
+
11
+ def run
12
+ puts "Runter started..."
13
+ start_watch()
14
+ end
15
+
16
+ def start_watch()
17
+ filesToWatch = []
18
+ @runtFile.get_watchers().each{|watcher|
19
+ filesToWatch.push(*watcher.get_watch_files())
20
+ }
21
+ FileWatcher.new(filesToWatch).watch() do |filename, event|
22
+ handle_change(filename)
23
+ end
24
+ end
25
+
26
+ def handle_change(file)
27
+ @runtFile.get_watchers().each{|watcher|
28
+ watcher.handle_change(file)
29
+ }
30
+ end
31
+ end
32
+
33
+ class << self
34
+ def application
35
+ @application ||= Runter::Application.new
36
+ end
37
+ def application=(app)
38
+ @application = app
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,23 @@
1
+ # Handles the read and write of the runt file
2
+ module Runter
3
+
4
+ class Runtfile
5
+ def initialize()
6
+ @watchers = []
7
+ load_settings()
8
+ end
9
+
10
+ def load_settings()
11
+ if !File.file?('Runtfile')
12
+ raise 'You must created a Runtfile before running runter!'
13
+ end
14
+ JSON.parse(IO.read('Runtfile'))["watchers"].each {|watch|
15
+ @watchers << Runter::Watcher.new(watch)
16
+ }
17
+ end
18
+ def get_watchers()
19
+ return @watchers
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'pty'
2
+ module Runter
3
+ module Shell
4
+ def execute(command)
5
+ begin
6
+ PTY.spawn(command) do |stdin, stdout, pid|
7
+ begin
8
+ stdin.each { |line| print line }
9
+ rescue Errno::EIO
10
+ end
11
+ end
12
+ rescue PTY::ChildExited
13
+ puts "The child process exited!"
14
+ end
15
+ end
16
+ module_function :execute
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ # Handles versioning of the application
2
+ module Runter
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,41 @@
1
+ module Runter
2
+ class Watcher
3
+ def initialize(json)
4
+ @files = []
5
+ @name = json["name"]
6
+ @singleActions = json["singleFileActions"]
7
+ @bulkActions = json["bulkActions"]
8
+ @files = []
9
+ load_files(json["src"])
10
+ end
11
+ def load_files(watchPaths)
12
+ watchPaths.each{|path|
13
+ Dir[path].each{|file|
14
+ @files.push("./#{file}")
15
+ }
16
+ }
17
+ end
18
+ def get_watch_files()
19
+ return @files
20
+ end
21
+ def handle_change(file)
22
+ if(@files.include?(file))
23
+ perform_single_actions(file)
24
+ perform_bulk_actions(file)
25
+ end
26
+ end
27
+ def perform_single_actions(file)
28
+ @singleActions.each{|action|
29
+ action.gsub! "$1", file
30
+ Runter::Shell.execute(action)
31
+ }
32
+ end
33
+ def perform_bulk_actions(file)
34
+ return if @bulkActions == nil
35
+ @bulkActions.each{|action|
36
+ action.gsub! "$1", file
37
+ Runter::Shell.execute(action)
38
+ }
39
+ end
40
+ end
41
+ end
data/runter.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ lib = File.expand_path('../lib/', __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ require 'runter/version'
5
+ Gem::Specification.new do |s|
6
+ s.name = "runter"
7
+ s.version = Runter::VERSION
8
+ s.licenses = ['MIT']
9
+ s.summary = "Runter Task Runner"
10
+ s.date = "2014-04-27"
11
+ s.description = "Runter is a ruby task runner based on file modifications"
12
+ s.authors = ["Karl Stoney"]
13
+ s.email = ["karlstoney@googlemail.com"]
14
+ s.homepage = "http://www.jambr.co.uk/"
15
+ s.files = `git ls-files -z`.split("\x0")
16
+ s.add_runtime_dependency "filewatcher"
17
+ s.executables = %w(runter)
18
+ s.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: runter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Karl Stoney
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: filewatcher
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Runter is a ruby task runner based on file modifications
31
+ email:
32
+ - karlstoney@googlemail.com
33
+ executables:
34
+ - runter
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE
42
+ - README.md
43
+ - Rakefile
44
+ - Runtfile
45
+ - bin/runter
46
+ - lib/runter.rb
47
+ - lib/runter/application.rb
48
+ - lib/runter/runtfile.rb
49
+ - lib/runter/shell.rb
50
+ - lib/runter/version.rb
51
+ - lib/runter/watcher.rb
52
+ - runter.gemspec
53
+ homepage: http://www.jambr.co.uk/
54
+ licenses:
55
+ - MIT
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.23
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Runter Task Runner
78
+ test_files: []