gk-application 0.0.1
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.
- checksums.yaml +7 -0
- data/LICENSE +13 -0
- data/README.md +74 -0
- data/lib/gk-application.rb +101 -0
- data/my_app.rb +29 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7e1e95fd9d6a2ab960a110027bf8f682a4ec305
|
4
|
+
data.tar.gz: 5aabedda707c4ab64a11aede7a2abf3a4d3b6046
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29d51509399af2a3315f37225915382cfe81a1eaf5f33313b26fadfeef0763283e53b8d3406897cee56fe2e573edf354e18c2f7ccf6d16cb5b5f006e8f90bae9
|
7
|
+
data.tar.gz: a68da36b2373ec89b55da2cf9e43d490d946cb8a125d3efe20105ffd61494bf48246e5b98abb0c482147248d6a45470eca3665d2555bf2307c78438cfe4f231f
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2014 Greg M. Krsak (greg.krsak@gmail.com)
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
Gem: gk-application
|
2
|
+
===================
|
3
|
+
|
4
|
+
A simple framework for creating applications in Ruby
|
5
|
+
----------------------------------------------------
|
6
|
+
|
7
|
+
An instance of ```GK::Application``` allows you to easily mange your Ruby application's state, with minimal fuss. Supported states are ```:starting```, ```:running```, ```:stopping``` and ```:stopped```.
|
8
|
+
|
9
|
+
Install with gem
|
10
|
+
----------------
|
11
|
+
|
12
|
+
Quick installation with ```gem```:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
gem install gk-application
|
16
|
+
```
|
17
|
+
|
18
|
+
Get started with a new project
|
19
|
+
------------------------------
|
20
|
+
|
21
|
+
Need a project template? No problem:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
ruby -e 'require "gk-application"' -e 'GK::Application.new.project'
|
25
|
+
```
|
26
|
+
|
27
|
+
Or using ```irb```:
|
28
|
+
|
29
|
+
```
|
30
|
+
$ irb
|
31
|
+
irb(main):001:0> require 'gk-application'
|
32
|
+
=> true
|
33
|
+
irb(main):002:0> GK::Application.new.project
|
34
|
+
=> nil
|
35
|
+
irb(main):003:0> quit
|
36
|
+
```
|
37
|
+
|
38
|
+
And you'll have a brand-new ```my_app.rb``` ready to go in the current folder!
|
39
|
+
|
40
|
+
Here's what an application looks like
|
41
|
+
-------------------------------------
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
#!/usr/bin/env ruby
|
45
|
+
|
46
|
+
require 'gk-application'
|
47
|
+
|
48
|
+
|
49
|
+
my_app = GK::Application.new
|
50
|
+
|
51
|
+
|
52
|
+
my_app.on_starting = Proc.new do
|
53
|
+
puts 'Starting.'
|
54
|
+
my_app.state = :running
|
55
|
+
end
|
56
|
+
|
57
|
+
my_app.on_running = Proc.new do
|
58
|
+
puts 'Running.'
|
59
|
+
my_app.state = :stopping
|
60
|
+
end
|
61
|
+
|
62
|
+
my_app.on_stopping = Proc.new do
|
63
|
+
puts 'Stopping.'
|
64
|
+
my_app.state = :stopped
|
65
|
+
end
|
66
|
+
|
67
|
+
my_app.on_stopped = Proc.new do
|
68
|
+
puts 'Stopped.'
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
my_app.state = :starting
|
73
|
+
|
74
|
+
```
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# gk-application.rb
|
2
|
+
# GK::Application
|
3
|
+
#
|
4
|
+
# A simple framework for creating applications in Ruby
|
5
|
+
#
|
6
|
+
# Copyright 2014 Greg M. Krsak (greg.krsak@gmail.com)
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'fileutils'
|
22
|
+
|
23
|
+
|
24
|
+
module GK
|
25
|
+
|
26
|
+
class Application
|
27
|
+
|
28
|
+
# The name of this gem
|
29
|
+
GEM_NAME = 'gk-application'
|
30
|
+
# The name of the project template
|
31
|
+
TEMPLATE_PROJECT = 'my_app.rb'
|
32
|
+
# Custom exception messages
|
33
|
+
MSG_INVALID_STATE = 'This application does not support the requested state.'
|
34
|
+
|
35
|
+
# An Application instance's state may be one of
|
36
|
+
# :starting
|
37
|
+
# :running
|
38
|
+
# :stopping
|
39
|
+
# :stopped
|
40
|
+
def state
|
41
|
+
@state
|
42
|
+
end
|
43
|
+
def state=(new_state)
|
44
|
+
case new_state
|
45
|
+
when :starting
|
46
|
+
@on_starting.call
|
47
|
+
when :running
|
48
|
+
@on_running.call
|
49
|
+
when :stopping
|
50
|
+
@on_stopping.call
|
51
|
+
when :stopped
|
52
|
+
@on_stopped.call
|
53
|
+
else
|
54
|
+
raise MSG_INVALID_STATE
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# State change event handlers
|
59
|
+
attr_accessor :on_starting
|
60
|
+
attr_accessor :on_running
|
61
|
+
attr_accessor :on_stopping
|
62
|
+
attr_accessor :on_stopped
|
63
|
+
|
64
|
+
# This is run once every time an Application instance is created
|
65
|
+
def initialize
|
66
|
+
# Initialize event handlers
|
67
|
+
@on_starting = Proc.new do
|
68
|
+
state = :running
|
69
|
+
end
|
70
|
+
@on_running = Proc.new do
|
71
|
+
state = :stopping
|
72
|
+
end
|
73
|
+
@on_stopping = Proc.new do
|
74
|
+
state = :stopped
|
75
|
+
end
|
76
|
+
@on_stopped = Proc.new { }
|
77
|
+
# Always create the Application instance in the stopped state
|
78
|
+
state = :stopped
|
79
|
+
end
|
80
|
+
|
81
|
+
# This creates a new GK::Application project.
|
82
|
+
# The new application will be called "my_app.rb" and be placed in the
|
83
|
+
# current directory unless otherwise specified.
|
84
|
+
def project(name: TEMPLATE_PROJECT)
|
85
|
+
# Get the path for the gk-application gem
|
86
|
+
spec = Gem::Specification.find_by_name(GEM_NAME)
|
87
|
+
gem_root = spec.gem_dir
|
88
|
+
source_file = File.join(gem_root, TEMPLATE_PROJECT);
|
89
|
+
# Create the target folder if it doesn't exist
|
90
|
+
target_dir = File.dirname(name)
|
91
|
+
FileUtils.mkdir_p(target_dir)
|
92
|
+
# Copy the my_app.rb file (in the gem directory) to the target
|
93
|
+
target_file = File.join(target_dir, name)
|
94
|
+
FileUtils.cp(source_file, target_file)
|
95
|
+
end
|
96
|
+
|
97
|
+
end # Class
|
98
|
+
|
99
|
+
end # Module
|
100
|
+
|
101
|
+
# End of gk-application.rb
|
data/my_app.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'gk-application'
|
4
|
+
|
5
|
+
|
6
|
+
my_app = GK::Application.new
|
7
|
+
|
8
|
+
|
9
|
+
my_app.on_starting = Proc.new do
|
10
|
+
puts 'Starting.'
|
11
|
+
my_app.state = :running
|
12
|
+
end
|
13
|
+
|
14
|
+
my_app.on_running = Proc.new do
|
15
|
+
puts 'Running.'
|
16
|
+
my_app.state = :stopping
|
17
|
+
end
|
18
|
+
|
19
|
+
my_app.on_stopping = Proc.new do
|
20
|
+
puts 'Stopping.'
|
21
|
+
my_app.state = :stopped
|
22
|
+
end
|
23
|
+
|
24
|
+
my_app.on_stopped = Proc.new do
|
25
|
+
puts 'Stopped.'
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
my_app.state = :starting
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gk-application
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Greg M. Krsak
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: An instance of GK::Application allows you to easily mange your Ruby application's
|
14
|
+
state, with minimal fuss. Supported states are :starting, :running, :stopping and
|
15
|
+
:stopped.
|
16
|
+
email:
|
17
|
+
- greg.krsak@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- LICENSE
|
23
|
+
- README.md
|
24
|
+
- lib/gk-application.rb
|
25
|
+
- my_app.rb
|
26
|
+
homepage: http://github.com/gregkrsak/gk-application
|
27
|
+
licenses:
|
28
|
+
- Apache-2
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.0.0
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 2.2.2
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: A simple framework for creating applications in Ruby
|
50
|
+
test_files: []
|