grimm 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +244 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +1 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/grimm.gemspec +41 -0
- data/lib/grimm.rb +35 -0
- data/lib/grimm/controller.rb +70 -0
- data/lib/grimm/dependencies.rb +6 -0
- data/lib/grimm/orm/database_connector.rb +14 -0
- data/lib/grimm/orm/grimm_record.rb +121 -0
- data/lib/grimm/routing.rb +84 -0
- data/lib/grimm/utilities.rb +13 -0
- data/lib/grimm/version.rb +3 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3f58e586470a83d61ac46c3ea655e9721d626549
|
4
|
+
data.tar.gz: 7cad1964e3f908a271f2b746c742166a9f6d59d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4623c42382e4616b198c09f68b879459a125c392aab262aa4a098f41b32941cfb55f0e1afe85f76f3b1f5544b8433fe045409a764d1eff5d13d96a2804240bc6
|
7
|
+
data.tar.gz: 7388e08deee9318fa8a6a88ce9491ab6988660e3bd155955de43143d0c9a2d8b19bdb74032cac22817f6e8035660bec9e3f475518432f7d2a3dd228045e27048
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "vendor/**/*"
|
4
|
+
- "db/schema.rb"
|
5
|
+
- "bin/*"
|
6
|
+
- "config/environments/*"
|
7
|
+
UseCache: false
|
8
|
+
Style/CollectionMethods:
|
9
|
+
Description: Preferred collection methods.
|
10
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
|
11
|
+
Enabled: true
|
12
|
+
PreferredMethods:
|
13
|
+
collect: map
|
14
|
+
collect!: map!
|
15
|
+
find: detect
|
16
|
+
find_all: select
|
17
|
+
reduce: inject
|
18
|
+
Style/DotPosition:
|
19
|
+
Description: Checks the position of the dot in multi-line method calls.
|
20
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
|
21
|
+
Enabled: true
|
22
|
+
EnforcedStyle: trailing
|
23
|
+
SupportedStyles:
|
24
|
+
- leading
|
25
|
+
- trailing
|
26
|
+
Style/FileName:
|
27
|
+
Description: Use snake_case for source file names.
|
28
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
|
29
|
+
Enabled: false
|
30
|
+
Exclude: []
|
31
|
+
Style/GuardClause:
|
32
|
+
Description: Check for conditionals that can be replaced with guard clauses
|
33
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
|
34
|
+
Enabled: false
|
35
|
+
MinBodyLength: 1
|
36
|
+
Style/IfUnlessModifier:
|
37
|
+
Description: Favor modifier if/unless usage when you have a single-line body.
|
38
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
|
39
|
+
Enabled: false
|
40
|
+
MaxLineLength: 80
|
41
|
+
Style/OptionHash:
|
42
|
+
Description: Don't use option hashes when you can use keyword arguments.
|
43
|
+
Enabled: false
|
44
|
+
Style/PercentLiteralDelimiters:
|
45
|
+
Description: Use `%`-literal delimiters consistently
|
46
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
|
47
|
+
Enabled: false
|
48
|
+
PreferredDelimiters:
|
49
|
+
"%": "()"
|
50
|
+
"%i": "()"
|
51
|
+
"%q": "()"
|
52
|
+
"%Q": "()"
|
53
|
+
"%r": "{}"
|
54
|
+
"%s": "()"
|
55
|
+
"%w": "()"
|
56
|
+
"%W": "()"
|
57
|
+
"%x": "()"
|
58
|
+
Style/PredicateName:
|
59
|
+
Description: Check the names of predicate methods.
|
60
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
|
61
|
+
Enabled: true
|
62
|
+
NamePrefix:
|
63
|
+
- is_
|
64
|
+
- has_
|
65
|
+
- have_
|
66
|
+
NamePrefixBlacklist:
|
67
|
+
- is_
|
68
|
+
Exclude:
|
69
|
+
- spec/**/*
|
70
|
+
Style/RaiseArgs:
|
71
|
+
Description: Checks the arguments passed to raise/fail.
|
72
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
|
73
|
+
Enabled: false
|
74
|
+
EnforcedStyle: exploded
|
75
|
+
SupportedStyles:
|
76
|
+
- compact
|
77
|
+
- exploded
|
78
|
+
Style/SignalException:
|
79
|
+
Description: Checks for proper usage of fail and raise.
|
80
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
|
81
|
+
Enabled: false
|
82
|
+
EnforcedStyle: semantic
|
83
|
+
SupportedStyles:
|
84
|
+
- only_raise
|
85
|
+
- only_fail
|
86
|
+
- semantic
|
87
|
+
Style/SingleLineBlockParams:
|
88
|
+
Description: Enforces the names of some block params.
|
89
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
|
90
|
+
Enabled: false
|
91
|
+
Methods:
|
92
|
+
- reduce:
|
93
|
+
- a
|
94
|
+
- e
|
95
|
+
- inject:
|
96
|
+
- a
|
97
|
+
- e
|
98
|
+
Style/SingleLineMethods:
|
99
|
+
Description: Avoid single-line methods.
|
100
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
|
101
|
+
Enabled: false
|
102
|
+
AllowIfMethodIsEmpty: true
|
103
|
+
Style/StringLiterals:
|
104
|
+
Description: Checks if uses of quotes match the configured preference.
|
105
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
|
106
|
+
Enabled: true
|
107
|
+
EnforcedStyle: double_quotes
|
108
|
+
SupportedStyles:
|
109
|
+
- single_quotes
|
110
|
+
- double_quotes
|
111
|
+
Style/StringLiteralsInInterpolation:
|
112
|
+
Description: Checks if uses of quotes inside expressions in interpolated strings
|
113
|
+
match the configured preference.
|
114
|
+
Enabled: true
|
115
|
+
EnforcedStyle: single_quotes
|
116
|
+
SupportedStyles:
|
117
|
+
- single_quotes
|
118
|
+
- double_quotes
|
119
|
+
Style/TrailingCommaInArguments:
|
120
|
+
# If `comma`, the cop requires a comma after the last argument, but only for
|
121
|
+
# parenthesized method calls where each argument is on its own line.
|
122
|
+
# If `consistent_comma`, the cop requires a comma after the last argument,
|
123
|
+
# for all parenthesized method calls with arguments.
|
124
|
+
EnforcedStyleForMultiline: no_comma
|
125
|
+
SupportedStyles:
|
126
|
+
- comma
|
127
|
+
- consistent_comma
|
128
|
+
- no_comma
|
129
|
+
|
130
|
+
Style/TrailingCommaInLiteral:
|
131
|
+
# If `comma`, the cop requires a comma after the last item in an array or
|
132
|
+
# hash, but only when each item is on its own line.
|
133
|
+
# If `consistent_comma`, the cop requires a comma after the last item of all
|
134
|
+
# non-empty array and hash literals.
|
135
|
+
|
136
|
+
Metrics/AbcSize:
|
137
|
+
Description: A calculated magnitude based on number of assignments, branches, and
|
138
|
+
conditions.
|
139
|
+
Enabled: false
|
140
|
+
Max: 15
|
141
|
+
Metrics/ClassLength:
|
142
|
+
Description: Avoid classes longer than 100 lines of code.
|
143
|
+
Enabled: false
|
144
|
+
CountComments: false
|
145
|
+
Max: 100
|
146
|
+
Metrics/ModuleLength:
|
147
|
+
CountComments: false
|
148
|
+
Max: 100
|
149
|
+
Description: Avoid modules longer than 100 lines of code.
|
150
|
+
Enabled: false
|
151
|
+
Metrics/CyclomaticComplexity:
|
152
|
+
Description: A complexity metric that is strongly correlated to the number of test
|
153
|
+
cases needed to validate a method.
|
154
|
+
Enabled: false
|
155
|
+
Max: 6
|
156
|
+
Metrics/MethodLength:
|
157
|
+
Description: Avoid methods longer than 10 lines of code.
|
158
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
|
159
|
+
Enabled: false
|
160
|
+
CountComments: false
|
161
|
+
Max: 10
|
162
|
+
Metrics/ParameterLists:
|
163
|
+
Description: Avoid parameter lists longer than three or four parameters.
|
164
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
|
165
|
+
Enabled: false
|
166
|
+
Max: 5
|
167
|
+
CountKeywordArgs: true
|
168
|
+
Metrics/PerceivedComplexity:
|
169
|
+
Description: A complexity metric geared towards measuring complexity for a human
|
170
|
+
reader.
|
171
|
+
Enabled: false
|
172
|
+
Max: 7
|
173
|
+
Lint/AssignmentInCondition:
|
174
|
+
Description: Don't use assignment in conditions.
|
175
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
|
176
|
+
Enabled: false
|
177
|
+
AllowSafeAssignment: true
|
178
|
+
Style/InlineComment:
|
179
|
+
Description: Avoid inline comments.
|
180
|
+
Enabled: false
|
181
|
+
Style/AccessorMethodName:
|
182
|
+
Description: Check the naming of accessor methods for get_/set_.
|
183
|
+
Enabled: false
|
184
|
+
Style/Alias:
|
185
|
+
Description: Use alias_method instead of alias.
|
186
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
|
187
|
+
Enabled: false
|
188
|
+
Style/Documentation:
|
189
|
+
Description: Document classes and non-namespace modules.
|
190
|
+
Enabled: false
|
191
|
+
Style/DoubleNegation:
|
192
|
+
Description: Checks for uses of double negation (!!).
|
193
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
194
|
+
Enabled: false
|
195
|
+
Style/EachWithObject:
|
196
|
+
Description: Prefer `each_with_object` over `inject` or `reduce`.
|
197
|
+
Enabled: false
|
198
|
+
Style/EmptyLiteral:
|
199
|
+
Description: Prefer literals to Array.new/Hash.new/String.new.
|
200
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
|
201
|
+
Enabled: false
|
202
|
+
Style/ModuleFunction:
|
203
|
+
Description: Checks for usage of `extend self` in modules.
|
204
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
|
205
|
+
Enabled: false
|
206
|
+
Style/OneLineConditional:
|
207
|
+
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
|
208
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
|
209
|
+
Enabled: false
|
210
|
+
Style/PerlBackrefs:
|
211
|
+
Description: Avoid Perl-style regex back references.
|
212
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
|
213
|
+
Enabled: false
|
214
|
+
Style/Send:
|
215
|
+
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
|
216
|
+
may overlap with existing methods.
|
217
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
|
218
|
+
Enabled: false
|
219
|
+
Style/SpecialGlobalVars:
|
220
|
+
Description: Avoid Perl-style global variables.
|
221
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
|
222
|
+
Enabled: false
|
223
|
+
Style/VariableInterpolation:
|
224
|
+
Description: Don't interpolate global, instance and class variables directly in
|
225
|
+
strings.
|
226
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
|
227
|
+
Enabled: false
|
228
|
+
Style/WhenThen:
|
229
|
+
Description: Use when x then ... for one-line cases.
|
230
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
|
231
|
+
Enabled: false
|
232
|
+
Lint/EachWithObjectArgument:
|
233
|
+
Description: Check for immutable argument given to each_with_object.
|
234
|
+
Enabled: true
|
235
|
+
Lint/HandleExceptions:
|
236
|
+
Description: Don't suppress exception.
|
237
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
|
238
|
+
Enabled: false
|
239
|
+
Lint/LiteralInCondition:
|
240
|
+
Description: Checks of literals used in conditions.
|
241
|
+
Enabled: false
|
242
|
+
Lint/LiteralInInterpolation:
|
243
|
+
Description: Checks for literals used in interpolation.
|
244
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at mradeybee@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 mradeybee
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# grimm
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "grimm"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/grimm.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "grimm/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "grimm"
|
8
|
+
spec.version = Grimm::VERSION
|
9
|
+
spec.authors = ["mradeybee"]
|
10
|
+
spec.email = ["mradeybee@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "A ruby framework"
|
13
|
+
spec.description = "This is a mini framework built with ruby."
|
14
|
+
spec.homepage = "https://github.com/andela-aadepoju/grimm"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting "allowed_push_host", or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to
|
23
|
+
protect against public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
36
|
+
spec.add_runtime_dependency "rack"
|
37
|
+
spec.add_runtime_dependency "tilt"
|
38
|
+
spec.add_runtime_dependency "pry"
|
39
|
+
spec.add_runtime_dependency "puma"
|
40
|
+
spec.add_runtime_dependency "sqlite3"
|
41
|
+
end
|
data/lib/grimm.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "grimm/version"
|
2
|
+
require "grimm/controller.rb"
|
3
|
+
require "grimm/utilities.rb"
|
4
|
+
require "grimm/dependencies.rb"
|
5
|
+
require "grimm/routing.rb"
|
6
|
+
require "pry"
|
7
|
+
require "grimm/orm/database_connector.rb"
|
8
|
+
require "grimm/orm/grimm_record.rb"
|
9
|
+
|
10
|
+
|
11
|
+
module Grimm
|
12
|
+
class Application
|
13
|
+
attr_reader :request
|
14
|
+
def call(env)
|
15
|
+
@request = Rack::Request.new(env)
|
16
|
+
if request.path_info == "/favicon.ico"
|
17
|
+
return [404,{}, []]
|
18
|
+
end
|
19
|
+
page = get_rack_app(env)
|
20
|
+
if page.nil?
|
21
|
+
return [404, {}, ["#{request.request_method.downcase} #{request.path} was not defined in the route. Check /config/routes.rb for defined routes"]]
|
22
|
+
else
|
23
|
+
page
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def route(&block)
|
28
|
+
@router ||= Grimm::Router.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_rack_app(env)
|
32
|
+
@router.check_url(request)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "tilt/erb"
|
2
|
+
|
3
|
+
module Grimm
|
4
|
+
class BaseController
|
5
|
+
attr_reader :request, :response
|
6
|
+
|
7
|
+
def initialize(request)
|
8
|
+
@request = request
|
9
|
+
end
|
10
|
+
|
11
|
+
def params
|
12
|
+
request.params
|
13
|
+
end
|
14
|
+
|
15
|
+
def render(*args)
|
16
|
+
response(render_template(*args))
|
17
|
+
end
|
18
|
+
|
19
|
+
def response(body, status = 200, header = {})
|
20
|
+
@response = Rack::Response.new(body, status, header)
|
21
|
+
end
|
22
|
+
|
23
|
+
def render_template(view_name, locals = {})
|
24
|
+
template = Tilt::ERBTemplate.new(File.join( "app", "views",
|
25
|
+
"layouts", "application.html.erb"))
|
26
|
+
title = view_name.to_s.tr("_", " ").capitalize
|
27
|
+
view = "#{view_name}.html.erb"
|
28
|
+
view_template = Tilt::ERBTemplate.new(File.join( "app", "views",
|
29
|
+
controller_name, view))
|
30
|
+
template.render(self, title: title) do
|
31
|
+
view_template.render(self, locals.merge!(get_vars))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_vars
|
36
|
+
vars = {}
|
37
|
+
instance_variables.each do |var|
|
38
|
+
key = var.to_s.gsub("@","").to_sym
|
39
|
+
vars[key] = instance_variable_get(var)
|
40
|
+
end
|
41
|
+
vars
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_response
|
45
|
+
@response
|
46
|
+
end
|
47
|
+
|
48
|
+
def controller_name
|
49
|
+
self.class.to_s.gsub(/Controller$/, "").snake_case
|
50
|
+
end
|
51
|
+
|
52
|
+
def redirect_to(url)
|
53
|
+
@response = Rack::Response.new(body = {}, status = 302, header = {"location" => url})
|
54
|
+
end
|
55
|
+
|
56
|
+
def dispatch(action)
|
57
|
+
self.send(action)
|
58
|
+
if get_response
|
59
|
+
get_response
|
60
|
+
else
|
61
|
+
render(action)
|
62
|
+
get_response
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.action(request, action_name)
|
67
|
+
self.new(request).dispatch(action_name)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Grimm
|
2
|
+
class DatabaseConnector
|
3
|
+
|
4
|
+
def self.connect_db
|
5
|
+
@@db = SQLite3::Database.new File.join "db", "grimm.db"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.execute(query, args = nil)
|
9
|
+
@@db ||= connect_db
|
10
|
+
return @@db.execute(query, args) if args
|
11
|
+
@@db.execute(query)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require "sqlite3"
|
2
|
+
|
3
|
+
module Grimm
|
4
|
+
class GrimmRecord
|
5
|
+
@@properties = {}
|
6
|
+
@@table = nil
|
7
|
+
|
8
|
+
def self.to_table(table_name)
|
9
|
+
@@table = table_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.property(column_name, args)
|
13
|
+
@@properties[column_name] = args
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.create_table
|
17
|
+
prop_array = []
|
18
|
+
@@properties.each do |key, value|
|
19
|
+
properties = []
|
20
|
+
properties << "#{key}"
|
21
|
+
value.each do |name, type|
|
22
|
+
name = name.to_s.downcase
|
23
|
+
if name == "primary_key" && type
|
24
|
+
properties << "PRIMARY KEY AUTOINCREMENT"
|
25
|
+
elsif name == "autoincrement" && type
|
26
|
+
properties << "AUTOINCREMENT"
|
27
|
+
elsif name == "nullable" && !type
|
28
|
+
properties << "NOT NULL"
|
29
|
+
elsif name == "type"
|
30
|
+
properties << type.to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
prop_array << properties.join(" ")
|
34
|
+
end
|
35
|
+
query = "CREATE TABLE IF NOT EXISTS #{@@table} (#{prop_array.join(", ")})"
|
36
|
+
DatabaseConnector.execute(query)
|
37
|
+
make_methods
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.make_methods
|
41
|
+
mtds = @@properties.keys.map { |mtd| mtd.to_sym }
|
42
|
+
instance_exec(mtds) do
|
43
|
+
mtds.each { |mtd| attr_accessor mtd }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def save
|
48
|
+
if self.id
|
49
|
+
DatabaseConnector.execute "UPDATE #{@@table} SET
|
50
|
+
#{update_records_placeholders} WHERE id = ?", update_records
|
51
|
+
else
|
52
|
+
DatabaseConnector.execute "INSERT INTO #{@@table} (#{get_columns})
|
53
|
+
VALUES (#{new_record_placeholders})", new_record_value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def save_records(obj_id)
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.find(id)
|
62
|
+
row = DatabaseConnector.execute("SELECT #{@@properties.keys.join(',')}
|
63
|
+
FROM #{@@table} WHERE id = ?", id).first
|
64
|
+
self.map_object(row)
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_values
|
68
|
+
attributes = @@properties.keys
|
69
|
+
attributes.delete(:id)
|
70
|
+
attributes.map { |method| self.send(method) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def update_records_placeholders
|
74
|
+
columns = @@properties.keys
|
75
|
+
columns.delete(:id)
|
76
|
+
columns.map { |col| "#{col}=?" }.join(",")
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_columns
|
80
|
+
columns = @@properties.keys
|
81
|
+
columns.delete(:id)
|
82
|
+
columns.join(",")
|
83
|
+
end
|
84
|
+
|
85
|
+
def update_records
|
86
|
+
get_values << self.send(:id)
|
87
|
+
end
|
88
|
+
|
89
|
+
def new_record_value
|
90
|
+
get_values
|
91
|
+
end
|
92
|
+
|
93
|
+
def new_record_placeholders
|
94
|
+
(["?"] * (@@properties.size - 1)).join(",")
|
95
|
+
end
|
96
|
+
|
97
|
+
def method_missing(method, *args)
|
98
|
+
@model.send(method)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.map_object(row)
|
102
|
+
model_name = self.new
|
103
|
+
@@properties.each_key.with_index do |value, index|
|
104
|
+
model_name.send("#{value}=", row[index])
|
105
|
+
end
|
106
|
+
model_name
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.findAll
|
110
|
+
data = DatabaseConnector.execute "SELECT #{@@properties.keys.join(',')}
|
111
|
+
FROM #{@@table}"
|
112
|
+
data.map do |row|
|
113
|
+
self.map_object(row)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.delete(id)
|
118
|
+
DatabaseConnector.execute "DELETE FROM #{@@table} WHERE id = ?", id
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Grimm
|
2
|
+
|
3
|
+
class Router
|
4
|
+
attr_reader :routes
|
5
|
+
def initialize
|
6
|
+
@routes = Hash.new { |hash, key| hash[key] = []}
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.match_verbs(*verbs)
|
10
|
+
verbs.each do |verb|
|
11
|
+
define_method(verb) do |url, options = {}|
|
12
|
+
url_parts = url.split("/")
|
13
|
+
url_parts.select! { |part| !part.empty? }
|
14
|
+
placeholder = []
|
15
|
+
regexp_parts = url_parts.map do |part|
|
16
|
+
if part[0] == ":"
|
17
|
+
placeholder << part[1..-1]
|
18
|
+
"([A-Za-z0-9_]+)"
|
19
|
+
else
|
20
|
+
part
|
21
|
+
end
|
22
|
+
end
|
23
|
+
regexp = regexp_parts.join("/")
|
24
|
+
routes[verb] << [Regexp.new("^/#{regexp}$"),
|
25
|
+
parse_to(options[:to]), placeholder]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
match_verbs :get, :post, :put, :patch, :delete
|
31
|
+
|
32
|
+
def draw(&block)
|
33
|
+
instance_eval(&block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def root(address)
|
37
|
+
get("/", to: address)
|
38
|
+
end
|
39
|
+
|
40
|
+
def resources(args)
|
41
|
+
args = args.to_s
|
42
|
+
get("/#{args}", to: "#{args}#index")
|
43
|
+
get("/#{args}/new", to: "#{args}#new")
|
44
|
+
get("/#{args}/:id", to: "#{args}#show")
|
45
|
+
get("/#{args}/edit/:id", to: "#{args}#edit")
|
46
|
+
get("/#{args}/delete/:id", to: "#{args}#destroy")
|
47
|
+
post("/#{args}/", to: "#{args}#create")
|
48
|
+
post("/#{args}/:id", to: "#{args}#update")
|
49
|
+
put("/#{args}/:id", to: "#{args}#update")
|
50
|
+
end
|
51
|
+
|
52
|
+
def check_url(request)
|
53
|
+
url = request.path_info
|
54
|
+
verb = request.request_method.downcase.to_sym
|
55
|
+
route_match = routes[verb].detect do |route|
|
56
|
+
(route.first).match(url)
|
57
|
+
end
|
58
|
+
if route_match
|
59
|
+
placeholder = {}
|
60
|
+
match = route_match.first.match(url)
|
61
|
+
held_value = route_match[2]
|
62
|
+
held_value.each_with_index do |value, index|
|
63
|
+
placeholder[value] = match.captures[index]
|
64
|
+
end
|
65
|
+
request.params.merge!(placeholder)
|
66
|
+
route_match << placeholder
|
67
|
+
return convert_target(request, route_match[1])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def convert_target(request, route)
|
72
|
+
controller_name = route[:controller].camelcase
|
73
|
+
controller = Object.const_missing("#{controller_name}Controller")
|
74
|
+
return controller.action(request, route[:target])
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def parse_to(option)
|
80
|
+
controller, target = option.split("#")
|
81
|
+
{ controller: controller.camelcase, target: target }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class String
|
2
|
+
def snake_case
|
3
|
+
self.gsub("::", "/")
|
4
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
5
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
6
|
+
tr("-", "_").downcase
|
7
|
+
end
|
8
|
+
|
9
|
+
def camelcase
|
10
|
+
return self if self !~ /_/ && self =~ /[A-Z]+.*/
|
11
|
+
split("_").map { |str|str.capitalize }.join
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grimm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mradeybee
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-25 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack
|
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: tilt
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: puma
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: This is a mini framework built with ruby.
|
126
|
+
email:
|
127
|
+
- mradeybee@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".rubocop.yml"
|
133
|
+
- ".travis.yml"
|
134
|
+
- CODE_OF_CONDUCT.md
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- bin/console
|
140
|
+
- bin/setup
|
141
|
+
- grimm.gemspec
|
142
|
+
- lib/grimm.rb
|
143
|
+
- lib/grimm/controller.rb
|
144
|
+
- lib/grimm/dependencies.rb
|
145
|
+
- lib/grimm/orm/database_connector.rb
|
146
|
+
- lib/grimm/orm/grimm_record.rb
|
147
|
+
- lib/grimm/routing.rb
|
148
|
+
- lib/grimm/utilities.rb
|
149
|
+
- lib/grimm/version.rb
|
150
|
+
homepage: https://github.com/andela-aadepoju/grimm
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
metadata:
|
154
|
+
allowed_push_host: https://rubygems.org
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.5.1
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: A ruby framework
|
175
|
+
test_files: []
|