shot_libs 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.md +0 -0
- data/README.md +63 -0
- data/lib/shot_libs/helper_load_exception.rb +14 -0
- data/lib/shot_libs/helper_loader.rb +44 -0
- data/lib/shot_libs/library_load_exception.rb +14 -0
- data/lib/shot_libs/library_loader.rb +44 -0
- data/lib/shot_libs.rb +4 -0
- metadata +101 -0
data/LICENSE.md
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
Introduction
|
2
|
+
------------
|
3
|
+
|
4
|
+
Shot Libs is a series of Loaders which allow you to utilize Helpers and Libraries to outsource controller and app logic.
|
5
|
+
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install shot_libs
|
12
|
+
```
|
13
|
+
|
14
|
+
|
15
|
+
Usage Example
|
16
|
+
-------------
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require 'shot'
|
20
|
+
require 'shot_libs'
|
21
|
+
|
22
|
+
app = Application.new
|
23
|
+
|
24
|
+
app.add_loader HelperLoader
|
25
|
+
app.add_loader LibraryLoader
|
26
|
+
|
27
|
+
app.run do
|
28
|
+
app.on 'load' do |instance|
|
29
|
+
instance.get 'library', 'SomeLibrary'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
app.start
|
34
|
+
```
|
35
|
+
|
36
|
+
Controller Example
|
37
|
+
------------------
|
38
|
+
|
39
|
+
**application/helpers/email.rb**
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
class Email
|
43
|
+
self.send_email(recipient, subject, body)
|
44
|
+
# Actually send an email here using the devil's magic of SMTP
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
**application/controllers/email.rb**
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require 'shot_mvc'
|
53
|
+
|
54
|
+
class EmailController < Controller
|
55
|
+
def setup
|
56
|
+
get 'helper', 'Email'
|
57
|
+
end
|
58
|
+
|
59
|
+
def send(message)
|
60
|
+
Email.send_email message['recipient'], message['subject'], message['body']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# HelperLoadException
|
2
|
+
#
|
3
|
+
# Thrown if an error occurs when loading a helper.
|
4
|
+
#
|
5
|
+
# Shot Framework - Copyright (c) Jesse Aaron Dunlap <me@jessedunlap.me>
|
6
|
+
# Licensed under the MIT License. For full licensing information, please
|
7
|
+
# see LICENSE.md. http://github.com/JesseDunlap/shot/
|
8
|
+
|
9
|
+
|
10
|
+
class HelperLoadException < Exception
|
11
|
+
def initialize(message)
|
12
|
+
super(message)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# HelperLoader
|
2
|
+
#
|
3
|
+
# Adds Helper loading capability to the Shot Framework. Helpers are simply outsourcing libraries
|
4
|
+
# for use in Controllers only.
|
5
|
+
#
|
6
|
+
# Shot Framework - Copyright (c) Jesse Aaron Dunlap <me@jessedunlap.me>
|
7
|
+
# Licensed under the MIT License. For full licensing information, please
|
8
|
+
# see LICENSE.md. http://github.com/JesseDunlap/shot/
|
9
|
+
|
10
|
+
require 'shot'
|
11
|
+
|
12
|
+
require_relative './library_load_exception'
|
13
|
+
|
14
|
+
class String
|
15
|
+
# Converts a CamelCased string to a underscore_string
|
16
|
+
def underscore
|
17
|
+
self.gsub(/::/, '/').
|
18
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
19
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
20
|
+
tr("-", "_").
|
21
|
+
downcase
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class HelperLoader < Loader
|
26
|
+
def initialize(client)
|
27
|
+
super(client)
|
28
|
+
@type = 'helper'
|
29
|
+
end
|
30
|
+
|
31
|
+
def get(helper_name)
|
32
|
+
if helper_exists? helper_name
|
33
|
+
load "./application/helpers/#{helper_name.underscore}.rb"
|
34
|
+
else
|
35
|
+
raise HelperLoadException "Could not find helper #{helper_name}. Please verify it exists at application/helpers/#{helper_name.underscore}.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def helper_exists?(helper)
|
42
|
+
Dir.exists? 'application/helpers' and File.exists? "application/helpers/#{helper.underscore}.rb"
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# LibraryLoadException
|
2
|
+
#
|
3
|
+
# Thrown if a Library doesn't exist.
|
4
|
+
#
|
5
|
+
# Shot Framework - Copyright (c) Jesse Aaron Dunlap <me@jessedunlap.me>
|
6
|
+
# Licensed under the MIT License. For full licensing information, please
|
7
|
+
# see LICENSE.md. http://github.com/JesseDunlap/shot/
|
8
|
+
|
9
|
+
|
10
|
+
class LibraryLoadException < Exception
|
11
|
+
def initialize(message)
|
12
|
+
super(message)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# LibraryLoader
|
2
|
+
#
|
3
|
+
# Adds Helper loading capability to the Shot Framework. Helpers are simply outsourcing libraries
|
4
|
+
# for use in Controllers only.
|
5
|
+
#
|
6
|
+
# Shot Framework - Copyright (c) Jesse Aaron Dunlap <me@jessedunlap.me>
|
7
|
+
# Licensed under the MIT License. For full licensing information, please
|
8
|
+
# see LICENSE.md. http://github.com/JesseDunlap/shot/
|
9
|
+
|
10
|
+
require 'shot'
|
11
|
+
|
12
|
+
require_relative './library_load_exception'
|
13
|
+
|
14
|
+
class String
|
15
|
+
# Converts a CamelCased string to a underscore_string
|
16
|
+
def underscore
|
17
|
+
self.gsub(/::/, '/').
|
18
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
19
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
20
|
+
tr("-", "_").
|
21
|
+
downcase
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class LibraryLoader < Loader
|
26
|
+
def initialize(client)
|
27
|
+
super(client)
|
28
|
+
@type = 'library'
|
29
|
+
end
|
30
|
+
|
31
|
+
def get(library_name)
|
32
|
+
if helper_exists helper
|
33
|
+
load "./application/libraries/#{library_name.underscore}.rb"
|
34
|
+
else
|
35
|
+
raise LibraryLoadException "Could not find library #{library_name}. Please verify it exists at application/libraries/#{library_name.underscore}.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def helper_exits(helper)
|
42
|
+
Dir.exists? 'application/libraries' and File.exists? "application/libraries/#{helper.underscore}.rb"
|
43
|
+
end
|
44
|
+
end
|
data/lib/shot_libs.rb
ADDED
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shot_libs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jesse A. Dunlap
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: shot
|
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
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: shot_mvc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: flexmock
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Shot Libs implements a series of Loaders, which can be used to obtain
|
63
|
+
instances of Helpers and Libraries, to extract business logic from your MVC application.
|
64
|
+
email: me@jessedunlap.me
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/shot_libs/helper_loader.rb
|
70
|
+
- lib/shot_libs/helper_load_exception.rb
|
71
|
+
- lib/shot_libs/library_loader.rb
|
72
|
+
- lib/shot_libs/library_load_exception.rb
|
73
|
+
- lib/shot_libs.rb
|
74
|
+
- LICENSE.md
|
75
|
+
- README.md
|
76
|
+
homepage: http://github.com/shot/
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.24
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Adds library loading ability to Shot, for better code organization.
|
101
|
+
test_files: []
|