slick 0.16.3 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -8
  3. data/.slick +0 -0
  4. data/.travis.yml +3 -5
  5. data/LICENSE +20 -0
  6. data/README.md +3 -32
  7. data/Rakefile +1 -0
  8. data/config.rb +8 -0
  9. data/config.ru +4 -0
  10. data/exe/slick +8 -0
  11. data/lib/slick.rb +50 -3
  12. data/lib/slick/command.rb +29 -0
  13. data/lib/slick/commands/create_database.rb +9 -0
  14. data/lib/slick/commands/drop_database.rb +9 -0
  15. data/lib/slick/commands/init_database.rb +9 -0
  16. data/lib/slick/commands/list_commands.rb +14 -0
  17. data/lib/slick/commands/migrate_database.rb +9 -0
  18. data/lib/slick/commands/reset_database.rb +10 -0
  19. data/lib/slick/commands/start_console.rb +14 -0
  20. data/lib/slick/commands/start_server.rb +14 -0
  21. data/lib/slick/concern.rb +19 -0
  22. data/lib/slick/database.rb +168 -0
  23. data/lib/slick/database/abstract_row.rb +13 -0
  24. data/lib/slick/database/column.rb +64 -0
  25. data/lib/slick/database/migration.rb +36 -0
  26. data/lib/slick/database/migrator.rb +67 -0
  27. data/lib/slick/database/row.rb +127 -0
  28. data/lib/slick/database/table.rb +381 -0
  29. data/lib/slick/database/union.rb +86 -0
  30. data/lib/slick/helper.rb +24 -0
  31. data/lib/slick/helpers.rb +4 -0
  32. data/lib/slick/helpers/dir.rb +6 -0
  33. data/lib/slick/helpers/echo.rb +6 -0
  34. data/lib/slick/helpers/grab.rb +10 -0
  35. data/lib/slick/helpers/html_builder.rb +180 -0
  36. data/lib/slick/helpers/text_builder.rb +22 -0
  37. data/lib/slick/monkey_patches/html_escape.rb +8 -0
  38. data/lib/slick/monkey_patches/html_unescape.rb +8 -0
  39. data/lib/slick/monkey_patches/paramify.rb +11 -0
  40. data/lib/slick/monkey_patches/pluralize.rb +8 -0
  41. data/lib/slick/monkey_patches/require_all.rb +18 -0
  42. data/lib/slick/monkey_patches/singularize.rb +8 -0
  43. data/lib/slick/monkey_patches/url_encode.rb +8 -0
  44. data/lib/slick/monkey_patches/url_escape.rb +8 -0
  45. data/lib/slick/monkey_patches/url_unescape.rb +8 -0
  46. data/lib/slick/project.rb +53 -0
  47. data/lib/slick/project_watcher.rb +36 -0
  48. data/lib/slick/registry.rb +39 -0
  49. data/lib/slick/request.rb +6 -0
  50. data/lib/slick/resource_factories/config.rb +14 -0
  51. data/lib/slick/resource_factories/database.rb +6 -0
  52. data/lib/slick/resource_factories/database_schema_cache.rb +6 -0
  53. data/lib/slick/resource_factories/database_session_cache.rb +6 -0
  54. data/lib/slick/resource_factories/env.rb +14 -0
  55. data/lib/slick/resource_factories/environment.rb +6 -0
  56. data/lib/slick/resource_factories/file.rb +6 -0
  57. data/lib/slick/resource_factories/params.rb +6 -0
  58. data/lib/slick/resource_factories/project.rb +6 -0
  59. data/lib/slick/resource_factories/request.rb +6 -0
  60. data/lib/slick/resource_factories/response.rb +6 -0
  61. data/lib/slick/resource_factories/web.rb +11 -0
  62. data/lib/slick/resource_factory.rb +35 -0
  63. data/lib/slick/resource_provider.rb +51 -0
  64. data/lib/slick/response.rb +14 -0
  65. data/lib/slick/util.rb +72 -0
  66. data/lib/slick/util/inflections.rb +122 -0
  67. data/lib/slick/util/params_hash.rb +38 -0
  68. data/lib/slick/version.rb +1 -1
  69. data/lib/slick/web.rb +4 -0
  70. data/lib/slick/web/dir.rb +92 -0
  71. data/lib/slick/web/file.rb +66 -0
  72. data/lib/slick/web/file_interpreter.rb +24 -0
  73. data/lib/slick/web/file_interpreters/erb.rb +33 -0
  74. data/lib/slick/web/file_interpreters/js.rb +17 -0
  75. data/lib/slick/web/file_interpreters/rb.rb +14 -0
  76. data/lib/slick/web/file_interpreters/sass.rb +30 -0
  77. data/lib/slick/web/node.rb +35 -0
  78. data/lib/slick/workspace.rb +8 -0
  79. data/slick.gemspec +15 -4
  80. data/web/_layout.erb +13 -0
  81. data/web/index.erb +7 -0
  82. data/web/javascripts/index.js +2 -0
  83. data/web/stylesheets/index.scss +2 -0
  84. metadata +127 -11
  85. data/Gemfile.lock +0 -22
  86. data/bin/console +0 -14
  87. data/bin/setup +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 181b5749cf9a5046fd4badc71feb732996a56a08cae6ecadafc9503214617660
4
- data.tar.gz: 87dee90bca9d5ffc14aba120aee64a30521673eddcef6495093d35dd8d13d39b
3
+ metadata.gz: 362f91bd15f9d273529c1ff20dac7958b8264e0a851d7daae500b6b19f351010
4
+ data.tar.gz: 421bb5ec00ddc73f9ccd2a72517828ecf67a577e31cf887fae9e8e1ad60e0540
5
5
  SHA512:
6
- metadata.gz: 58f57002fe4f6c0e3864e60ebe7e91cdffcb01375651f23320a07ed631e3148e58b2105e25eab1a40a7034d85dd4b3f2542a650c85b95d01e5366b9758a330ef
7
- data.tar.gz: 8455cd6ef6cfbf41870df289a4d8d7bfcdc845e66b6f01de5129645cd1b709fe6106646a66d6faad07953a18f5cf95ada33862efc85cb4be289febe696a2c831
6
+ metadata.gz: a519ba7ab7539a00ffe0969242ba735d8c0fc49d181f09e3f9ff506b0c796ea8e98fae165f2421a666678c672d69f8f82abb68e27b3d9d9ea336c2f4e920d8c2
7
+ data.tar.gz: 1b77d2bae6a222dea6abd2cd1c07c6cf1233ec5c40d33d6f06c3eb39561b511896c50037e9e2188242b51ba0e15a3405bb18d0511a423a88022e42fdd871bd53
data/.gitignore CHANGED
@@ -1,8 +1,7 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
1
+
2
+ node_modules/
3
+ pkg/
4
+ dist/
5
+ *-bundle.js*
6
+ .DS_Store
7
+ Gemfile.lock
data/.slick ADDED
File without changes
@@ -1,7 +1,5 @@
1
- ---
2
- sudo: false
3
1
  language: ruby
4
- cache: bundler
5
2
  rvm:
6
- - 2.5.5
7
- before_install: gem install bundler -v 2.0.2
3
+ - 2.5
4
+ before_install:
5
+ - gem install bundler
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+
2
+ Copyright (c) 2020 Jody Salt
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
data/README.md CHANGED
@@ -1,35 +1,6 @@
1
- # Slick
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/slick`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'slick'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
1
 
19
- Or install it yourself as:
20
-
21
- $ gem install slick
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
2
+ # Slick
32
3
 
33
- ## Contributing
4
+ An entrepreneurial web framework that allows small (or one-man) teams to be highly productive.
34
5
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/slick.
6
+ [![Build Status](https://travis-ci.com/blognami/slick.svg?branch=master)](https://travis-ci.com/blognami/slick)
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
7
  t.test_files = FileList["test/**/*_test.rb"]
8
+ t.warning = false
8
9
  end
9
10
 
10
11
  task :default => :test
@@ -0,0 +1,8 @@
1
+
2
+ {
3
+ "database" => {
4
+ "username" => "root",
5
+ "password" => "",
6
+ "name" => "slick_#{environment}"
7
+ }
8
+ }
@@ -0,0 +1,4 @@
1
+
2
+ require "slick"
3
+
4
+ run Slick
@@ -0,0 +1,8 @@
1
+
2
+ if ENV['BUNDLER_VERSION'].nil? && system('bundle info slick > /dev/null 2>&1')
3
+ exec "bundle exec slick #{ARGV.map{|a| "\"#{a.gsub(/\"/, '\"')}\""}.join(' ')}"
4
+ else
5
+ require "slick"
6
+
7
+ Slick::Command.run(*ARGV)
8
+ end
@@ -1,6 +1,53 @@
1
- require "slick/version"
1
+
2
+ require "slick/monkey_patches/require_all"
2
3
 
3
4
  module Slick
4
- class Error < StandardError; end
5
- # Your code goes here...
5
+
6
+ require_all("slick/monkey_patches")
7
+ require_all("slick")
8
+
9
+ class << self
10
+
11
+ include Slick::Helpers
12
+
13
+ def resource_provider
14
+ @resource_provider ||= ResourceProvider.new
15
+ end
16
+
17
+ def call(env)
18
+ resource_provider.reset do
19
+ resource_provider["env"] = env
20
+
21
+ if file = web.find_file(request.path)
22
+ file.render(params)
23
+ else
24
+ response.status = 404
25
+ response.set_header("Content-Type", "text/plain")
26
+ response.body = ["Not found"]
27
+ end
28
+
29
+ response.to_a
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ require "bundler"
38
+
39
+ begin
40
+ Bundler.require(:default, Slick.resource_provider["environment"].to_sym)
41
+ rescue Bundler::GemfileNotFound
42
+ # do nothing
43
+ end
44
+
45
+ project = Slick.resource_provider["project"]
46
+
47
+ if project.exist? && ENV['WATCH_PROJECT'] == 'true'
48
+ Slick::ProjectWatcher.watch
49
+ end
50
+
51
+ project.lib_names.reverse.each do |lib_name|
52
+ require_all(lib_name)
6
53
  end
@@ -0,0 +1,29 @@
1
+
2
+ require "slick/registry"
3
+ require "slick/helpers"
4
+
5
+ class Slick::Command
6
+
7
+ class << self
8
+
9
+ include Slick::Registry
10
+
11
+ def run(name = 'list-commands', *args)
12
+ create(name, *args).run
13
+ end
14
+
15
+ end
16
+
17
+ include Slick::Helpers
18
+
19
+ attr_accessor :args
20
+
21
+ def initialize(*args)
22
+ @args = args
23
+ end
24
+
25
+ def run
26
+ puts "No such command \"#{self.class.name}\""
27
+ end
28
+
29
+ end
@@ -0,0 +1,9 @@
1
+
2
+ require "slick/command"
3
+
4
+ Class.new(Slick::Command){ register "create-database" }.define_method "run" do
5
+
6
+ database.create()
7
+
8
+ end
9
+
@@ -0,0 +1,9 @@
1
+
2
+ require "slick/command"
3
+
4
+ Class.new(Slick::Command){ register "drop-database" }.define_method "run" do
5
+
6
+ database.drop()
7
+
8
+ end
9
+
@@ -0,0 +1,9 @@
1
+
2
+ require "slick/command"
3
+
4
+ Class.new(Slick::Command){ register "init-database" }.define_method "run" do
5
+
6
+ database.create()
7
+ database.migrate()
8
+
9
+ end
@@ -0,0 +1,14 @@
1
+
2
+ require "slick/command"
3
+
4
+ Class.new(Slick::Command){ register "list-commands" }.define_method "run" do
5
+
6
+ puts ""
7
+ puts "The following commands are available:"
8
+ puts ""
9
+ Slick::Command.registered_classes.keys.sort.each do |name|
10
+ puts " * #{name}"
11
+ end
12
+ puts ""
13
+
14
+ end
@@ -0,0 +1,9 @@
1
+
2
+ require "slick/command"
3
+
4
+ Class.new(Slick::Command){ register "migrate-database" }.define_method "run" do
5
+
6
+ database.migrate()
7
+
8
+ end
9
+
@@ -0,0 +1,10 @@
1
+
2
+ require "slick/command"
3
+
4
+ Class.new(Slick::Command){ register "reset-database" }.define_method "run" do
5
+
6
+ database.drop()
7
+ database.create()
8
+ database.migrate()
9
+
10
+ end
@@ -0,0 +1,14 @@
1
+
2
+ require "slick/command"
3
+
4
+ Class.new(Slick::Command){ register "start-console" }.define_method "run" do
5
+
6
+ require "irb"
7
+ IRB.setup nil
8
+ IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
9
+ require "irb/ext/multi-irb"
10
+ workspace = Slick::Workspace.new
11
+ workspace.instance_eval{ undef :source }
12
+ IRB.irb nil, workspace
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+
2
+ require "slick/command"
3
+ require "rack"
4
+
5
+ Class.new(Slick::Command){ register "start-server" }.define_method "run" do
6
+ if ENV['WATCH_PROJECT'] == 'true'
7
+ Rack::Server.start({
8
+ :app => Slick,
9
+ :Port => 3000
10
+ })
11
+ else
12
+ system("WATCH_PROJECT=true bundle exec slick start-server")
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+
2
+ module Slick::Concern
3
+
4
+ def missing_method_calls
5
+ @missing_method_calls ||= []
6
+ end
7
+
8
+ def included(_module)
9
+ missing_method_calls.each do |missing_method_call|
10
+ args, block = missing_method_call
11
+ _module.send *args, &block
12
+ end
13
+ end
14
+
15
+ def method_missing(*args, &block)
16
+ missing_method_calls << [args, block]
17
+ end
18
+
19
+ end
@@ -0,0 +1,168 @@
1
+
2
+ require "mysql2"
3
+
4
+ class Slick::Database
5
+
6
+ def initialize(config = {})
7
+ @config = config.paramify
8
+ run("use ?", @config.name.to_sym) if exist?
9
+ end
10
+
11
+ def run(*args)
12
+ options = (args.last.kind_of?(Hash) ? args.pop : {}).paramify
13
+ query = _prepare(args)
14
+
15
+ Slick.resource_provider["database_schema_cache"].clear if query.match(/\A\s*(create|drop|alter)/i)
16
+ Slick.resource_provider["database_session_cache"].clear if query.match(/\A\s*(create|drop|alter|insert|update)/i)
17
+
18
+ rows = if options.cache
19
+ Slick.resource_provider["database_#{options.cache}_cache"]["query:#{query}"] ||= _fetch_rows(query)
20
+ else
21
+ _fetch_rows(query)
22
+ end
23
+
24
+ rows.map do |row|
25
+ out = row.clone
26
+ if out['_type']
27
+ out = Slick::Database::Row.create(out.delete('_type'), self, out)
28
+ end
29
+ out
30
+ end
31
+ end
32
+
33
+ def exist?
34
+ run("show databases", :cache => "schema").map{|row| row["Database"]}.include?(@config.name)
35
+ end
36
+
37
+ def create
38
+ if !exist?
39
+ run("create database ?", @config.name.to_sym)
40
+ run("use ?", @config.name.to_sym)
41
+ end
42
+ end
43
+
44
+ def drop
45
+ run("drop database ?", @config.name.to_sym) if exist?
46
+ @using = nil
47
+ end
48
+
49
+ def tables
50
+ if exist?
51
+ out = {}
52
+ run("show tables", :cache => "schema").each do |row|
53
+ name = row.values[0]
54
+ out[name] = send(name)
55
+ end
56
+ out
57
+ else
58
+ {}
59
+ end
60
+ end
61
+
62
+ def add_table(name)
63
+ send(name).create
64
+ end
65
+
66
+ def remove_table(name)
67
+ send(name).drop
68
+ end
69
+
70
+ def current_schema_version
71
+ Migrator.new(self).current_schema_version
72
+ end
73
+
74
+ def latest_schema_version
75
+ Migrator.new(self).latest_schema_version
76
+ end
77
+
78
+ def migrate(*args)
79
+ Migrator.new(self).migrate(*args)
80
+ end
81
+
82
+ def method_missing(name, *args, &block)
83
+ if args.length == 0
84
+ if Union.registered_classes[name.to_s]
85
+ out = Union.create(name, self)
86
+ else
87
+ out = Table.create(name, self)
88
+ end
89
+
90
+ if block
91
+ if block.arity > 0
92
+ block.call(out)
93
+ else
94
+ out.instance_eval(&block)
95
+ end
96
+ end
97
+
98
+ out
99
+ else
100
+ super
101
+ end
102
+ end
103
+
104
+ private
105
+
106
+ def _prepare(*args)
107
+ out = []
108
+ args = _flatten(args)
109
+ while(args.length > 0)
110
+ out << args.shift.to_s.gsub(/\?/) { |match| _escape(args.shift) }
111
+ end
112
+ out.join(' ')
113
+ end
114
+
115
+ def _flatten(items, out = [])
116
+ items.each do |item|
117
+ if item.kind_of? Array
118
+ _flatten(item, out)
119
+ else
120
+ out << item
121
+ end
122
+ end
123
+ out
124
+ end
125
+
126
+ def _escape(value)
127
+ if value.kind_of?(Slick::Database::Table)
128
+ _escape_identifier(value.instance_eval{ @alias })
129
+ elsif value.kind_of?(Slick::Database::Column)
130
+ alias_identifier = value.instance_eval{ @table }.instance_eval{ @alias }
131
+ column_identifier = value.instance_eval{ @name }
132
+ "#{_escape_identifier(alias_identifier)}.#{_escape_identifier(column_identifier)}"
133
+ elsif value.kind_of?(Symbol)
134
+ _escape_identifier(value)
135
+ elsif value.kind_of?(Numeric)
136
+ value
137
+ elsif value.kind_of?(NilClass)
138
+ "null"
139
+ else
140
+ "'#{_client.escape(value)}'"
141
+ end
142
+ end
143
+
144
+ def _escape_identifier(value)
145
+ "`#{value.to_s.gsub(/`/, '')}`"
146
+ end
147
+
148
+ def _fetch_rows(query)
149
+ puts ""
150
+ puts "Query: #{query}"
151
+ puts ""
152
+
153
+ out = []
154
+ result = _client.query(query)
155
+ result.each{|row| out << row} if result
156
+ out
157
+ end
158
+
159
+ def _client
160
+ @_client ||= Mysql2::Client.new({
161
+ :host => @config.host || '127.0.0.1',
162
+ :port => @config.port || 3306,
163
+ :username => @config.username || 'root',
164
+ :password => @config.password || ''
165
+ })
166
+ end
167
+
168
+ end