rulers_seanfred 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +9 -0
- data/lib/rulers.rb +29 -0
- data/lib/rulers/array.rb +5 -0
- data/lib/rulers/controller.rb +31 -0
- data/lib/rulers/dependencies.rb +12 -0
- data/lib/rulers/file_model.rb +63 -0
- data/lib/rulers/routing.rb +12 -0
- data/lib/rulers/util.rb +9 -0
- data/lib/rulers/version.rb +3 -0
- data/rulers.gemspec +27 -0
- data/test/test_application.rb +29 -0
- data/test/test_helper.rb +8 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6abcafdc1fae4fbf7572930d44a537817b146dda
|
4
|
+
data.tar.gz: 9bf9d7aca4172096a4306d7a62b5ab1602dda10b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d5d4951a77c67a7d6cebd7fcb80b7ef92c6ec9885d1fbcfe22c861fed291f767f89b57d15d2508d144c41dc9e4b7ed424c119fe124d55571402f5450b82f174
|
7
|
+
data.tar.gz: aebfae3b2d382eeade4111065234a9a579d7e76adcc838639ae89d3a00bdb333a27146b7184e4dae828ef72b52858043d806ef518321e6c78dfe88c51a60e49e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 seanfred
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rulers
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rulers'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rulers
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/rulers.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "rulers/version"
|
2
|
+
require "rulers/array"
|
3
|
+
require "rulers/routing"
|
4
|
+
require "rulers/util"
|
5
|
+
require "rulers/dependencies"
|
6
|
+
require "rulers/controller"
|
7
|
+
require "rulers/file_model"
|
8
|
+
|
9
|
+
module Rulers
|
10
|
+
class Application
|
11
|
+
def call(env)
|
12
|
+
if env['PATH_INFO'] == 'favicon.ico'
|
13
|
+
return [404,
|
14
|
+
{'Content-Type' => 'text/html'}, []]
|
15
|
+
end
|
16
|
+
if env['PATH_INFO'] == '/'
|
17
|
+
return [302,
|
18
|
+
{"Location" => "/home/index"}, []]
|
19
|
+
end
|
20
|
+
klass, act = get_controller_and_action(env)
|
21
|
+
controller = klass.new(env)
|
22
|
+
text = controller.send(act)
|
23
|
+
[200, {'Content-Type' => 'text/html'},
|
24
|
+
[text]]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
data/lib/rulers/array.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "erubis"
|
2
|
+
require "rulers/file_model"
|
3
|
+
|
4
|
+
module Rulers
|
5
|
+
class Controller
|
6
|
+
include Rulers::Model
|
7
|
+
def initialize(env)
|
8
|
+
@env = env
|
9
|
+
end
|
10
|
+
|
11
|
+
def env
|
12
|
+
@env
|
13
|
+
end
|
14
|
+
|
15
|
+
def render(view_name, locals = {})
|
16
|
+
filename = File.join "app", "views",
|
17
|
+
controller_name, "#{view_name}.html.erb"
|
18
|
+
template = File.read filename
|
19
|
+
eruby = Erubis::Eruby.new(template)
|
20
|
+
eruby.result locals.merge(:env => env)
|
21
|
+
end
|
22
|
+
|
23
|
+
def controller_name
|
24
|
+
klass = self.class
|
25
|
+
klass = klass.to_s.gsub /Controller$/, ""
|
26
|
+
Rulers.to_underscore klass
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "multi_json"
|
2
|
+
module Rulers
|
3
|
+
module Model
|
4
|
+
class FileModel
|
5
|
+
def initialize(filename)
|
6
|
+
@filename = filename
|
7
|
+
|
8
|
+
# If filename is "dir/37.json", @id is 37
|
9
|
+
basename = File.split(filename)[-1]
|
10
|
+
@id = File.basename(basename, ".json").to_i
|
11
|
+
|
12
|
+
obj = File.read(filename)
|
13
|
+
@hash = MultiJson.decode(obj)
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](name)
|
17
|
+
@hash[name.to_s]
|
18
|
+
end
|
19
|
+
|
20
|
+
def []=(name, value)
|
21
|
+
@hash[name.to_s] = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find(id)
|
25
|
+
begin
|
26
|
+
FileModel.new("db/quotes/#{id}.json")
|
27
|
+
rescue
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.all
|
33
|
+
files = Dir["db/quotes/*.json"]
|
34
|
+
files.map { |f| FileModel.new f }
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.create(attrs)
|
38
|
+
hash = {}
|
39
|
+
hash["submitter"] = attrs["submitter"] || ""
|
40
|
+
hash["quote"] = attrs["quote"] || ""
|
41
|
+
hash["attribution"] = attrs["attribution"] || ""
|
42
|
+
|
43
|
+
files = Dir["db/quotes/*.json"]
|
44
|
+
names = files.map { |f| f.split("/")[-1] }
|
45
|
+
highest = names.map { |b| b[0...-5].to_i }.max
|
46
|
+
id = highest + 1
|
47
|
+
|
48
|
+
File.open("db/quotes/#{id}.json", "w") do |f|
|
49
|
+
f.write <<TEMPLATE
|
50
|
+
{
|
51
|
+
"submitter": "#{hash["submitter"]}",
|
52
|
+
"quote": "#{hash["quote"]}",
|
53
|
+
"attribution": "#{hash["attribution"]}"
|
54
|
+
}
|
55
|
+
TEMPLATE
|
56
|
+
end
|
57
|
+
|
58
|
+
FileModel.new "db/quotes/#{id}.json"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Rulers
|
2
|
+
class Application
|
3
|
+
def get_controller_and_action(env)
|
4
|
+
_, cont, action, after =
|
5
|
+
env["PATH_INFO"].split('/', 4)
|
6
|
+
cont = cont.capitalize # "People"
|
7
|
+
cont += "Controller" # "PeopleController"
|
8
|
+
|
9
|
+
[Object.const_get(cont), action]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/rulers/util.rb
ADDED
data/rulers.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rulers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "rulers_seanfred"
|
8
|
+
s.version = Rulers::VERSION
|
9
|
+
s.authors = ["seanfred"]
|
10
|
+
s.email = ["sean.frederick.1@gmail.com"]
|
11
|
+
s.description = %q{description}
|
12
|
+
s.summary = %q{summary}
|
13
|
+
s.homepage = ""
|
14
|
+
s.license = "MIT"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split($/)
|
17
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
s.test_files = s.files.grep(%r{^(test|s|features)/})
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
s.add_runtime_dependency "rack"
|
23
|
+
s.add_development_dependency "rack-test"
|
24
|
+
s.add_runtime_dependency "erubis"
|
25
|
+
s.add_runtime_dependency "multi_json"
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class TestApp < Rulers::Application
|
4
|
+
def index
|
5
|
+
"Hello!" #Not rendering a view
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestApp < Rulers::Application
|
10
|
+
def get_controller_and_action(env)
|
11
|
+
[TestController, "index"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class RulersAppTest < Test::Unit::TestCase
|
16
|
+
include Rack::Test::Methods
|
17
|
+
|
18
|
+
def app
|
19
|
+
TestApp.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_request
|
23
|
+
get "/example/route"
|
24
|
+
|
25
|
+
assert last_response.ok?
|
26
|
+
body = last_response.body
|
27
|
+
assert body["Hello"]
|
28
|
+
end
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rulers_seanfred
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- seanfred
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
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: rack-test
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: erubis
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: multi_json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: description
|
84
|
+
email:
|
85
|
+
- sean.frederick.1@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/rulers.rb
|
96
|
+
- lib/rulers/array.rb
|
97
|
+
- lib/rulers/controller.rb
|
98
|
+
- lib/rulers/dependencies.rb
|
99
|
+
- lib/rulers/file_model.rb
|
100
|
+
- lib/rulers/routing.rb
|
101
|
+
- lib/rulers/util.rb
|
102
|
+
- lib/rulers/version.rb
|
103
|
+
- rulers.gemspec
|
104
|
+
- test/test_application.rb
|
105
|
+
- test/test_helper.rb
|
106
|
+
homepage: ''
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.0.6
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: summary
|
130
|
+
test_files:
|
131
|
+
- test/test_application.rb
|
132
|
+
- test/test_helper.rb
|
133
|
+
has_rdoc:
|