frankly 0.2.0 → 0.2.2
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 +4 -4
- data/bin/console +11 -11
- data/frankly.gemspec +12 -0
- data/lib/frankly/version.rb +1 -1
- data/templates/Gemfile.tt +1 -0
- data/templates/Rakefile +178 -0
- data/templates/config/database.rb +22 -13
- metadata +12 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 93bc4a74b8e4c574817e4e8cd0de16112b5c6d152fcc39dfbb641d34c9cb9f6f
|
|
4
|
+
data.tar.gz: 58589529b0b9450e534e1018fe75ef07bc708c095abca661d832fb7e7c84d4dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 95420fbfd186664fc392594e6ea60a4a460aaed358678f08ac86af854818524c22eae51830df580309e2a437370c70feb3dd8f935fd65e7b66e66fb877254e32
|
|
7
|
+
data.tar.gz: a96eb3ff588b6cb6e8a111f7c634d0d4ceafb64856c86cd459f6ab78ac590f60ac8ac032fdbf896c8127dc4a4167e5f417147ac7b762ab20115dc56a06b1fa4c
|
data/bin/console
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
4
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
3
5
|
require "bundler/setup"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
require "irb"
|
|
14
|
-
IRB.start
|
|
6
|
+
require_relative "../config/environment"
|
|
7
|
+
|
|
8
|
+
begin
|
|
9
|
+
require "pry"
|
|
10
|
+
Pry.start
|
|
11
|
+
rescue LoadError
|
|
12
|
+
require "irb"
|
|
13
|
+
IRB.start(__FILE__)
|
|
14
|
+
end
|
data/frankly.gemspec
CHANGED
|
@@ -15,6 +15,18 @@ Gem::Specification.new do |spec|
|
|
|
15
15
|
spec.homepage = "https://github.com/kenrett/frankly"
|
|
16
16
|
spec.license = "MIT"
|
|
17
17
|
spec.required_ruby_version = ">= 3.1"
|
|
18
|
+
spec.post_install_message = <<-PIC
|
|
19
|
+
.
|
|
20
|
+
.---------.'---.
|
|
21
|
+
'. : .'
|
|
22
|
+
'. .::: .' The Chairman
|
|
23
|
+
'.'::'.' of the Board
|
|
24
|
+
'||' has arrived.
|
|
25
|
+
||
|
|
26
|
+
||
|
|
27
|
+
||
|
|
28
|
+
---====---
|
|
29
|
+
PIC
|
|
18
30
|
|
|
19
31
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
32
|
spec.metadata["source_code_uri"] = spec.homepage
|
data/lib/frankly/version.rb
CHANGED
data/templates/Gemfile.tt
CHANGED
data/templates/Rakefile
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require "active_support/inflector"
|
|
6
|
+
|
|
7
|
+
unless defined?(Rails)
|
|
8
|
+
module Rails
|
|
9
|
+
class AppConfig
|
|
10
|
+
def load_database_yaml
|
|
11
|
+
{}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def paths
|
|
15
|
+
{ "db" => ["db"] }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class AppShim
|
|
20
|
+
def config
|
|
21
|
+
@config ||= AppConfig.new
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def paths
|
|
25
|
+
{ "db/migrate" => ["db/migrate"] }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def migration_railties
|
|
29
|
+
[]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
module_function
|
|
34
|
+
|
|
35
|
+
def env
|
|
36
|
+
ENV.fetch("RACK_ENV", "development")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def application
|
|
40
|
+
@application ||= AppShim.new
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def root
|
|
44
|
+
Dir.pwd
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
3
49
|
require "sinatra/activerecord/rake"
|
|
4
50
|
require_relative "app"
|
|
5
51
|
|
|
@@ -10,3 +56,135 @@ rescue LoadError
|
|
|
10
56
|
end
|
|
11
57
|
|
|
12
58
|
task default: :spec
|
|
59
|
+
|
|
60
|
+
if ARGV.first.to_s.start_with?("generate:")
|
|
61
|
+
ARGV[1..].to_a.each do |arg|
|
|
62
|
+
task(arg.to_sym) unless Rake::Task.task_defined?(arg)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def positional_arg_for(task_name, index = 0)
|
|
67
|
+
tasks = Rake.application.top_level_tasks
|
|
68
|
+
position = tasks.index(task_name)
|
|
69
|
+
return nil unless position
|
|
70
|
+
|
|
71
|
+
tasks[position + 1 + index]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def positional_args_for(task_name, from_index: 0)
|
|
75
|
+
tasks = Rake.application.top_level_tasks
|
|
76
|
+
position = tasks.index(task_name)
|
|
77
|
+
return [] unless position
|
|
78
|
+
|
|
79
|
+
tasks[(position + 1 + from_index)..].to_a
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
namespace :generate do
|
|
83
|
+
desc "Generate a model Usage: rake generate:model User name:string age:integer"
|
|
84
|
+
task :model, [:name] do |_task, args|
|
|
85
|
+
model_name = args[:name].presence || positional_arg_for("generate:model")
|
|
86
|
+
model_name = model_name.to_s.strip
|
|
87
|
+
abort "Model name is required. Example: rake generate:model User" if model_name.empty?
|
|
88
|
+
|
|
89
|
+
class_name = model_name.camelize
|
|
90
|
+
file_name = model_name.underscore
|
|
91
|
+
model_path = File.join("app", "models", "#{file_name}.rb")
|
|
92
|
+
|
|
93
|
+
if File.exist?(model_path)
|
|
94
|
+
puts "Model exists: #{model_path}"
|
|
95
|
+
else
|
|
96
|
+
FileUtils.mkdir_p(File.dirname(model_path))
|
|
97
|
+
File.write(model_path, <<~RUBY)
|
|
98
|
+
# frozen_string_literal: true
|
|
99
|
+
|
|
100
|
+
class #{class_name} < ActiveRecord::Base
|
|
101
|
+
end
|
|
102
|
+
RUBY
|
|
103
|
+
puts "Created #{model_path}"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
attrs = positional_args_for("generate:model", from_index: 1).map(&:strip).reject(&:empty?)
|
|
107
|
+
next if attrs.empty?
|
|
108
|
+
|
|
109
|
+
migration_name = "create_#{class_name.tableize}"
|
|
110
|
+
migration_class = migration_name.camelize
|
|
111
|
+
timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
112
|
+
migration_path = File.join("db", "migrate", "#{timestamp}_#{migration_name}.rb")
|
|
113
|
+
|
|
114
|
+
columns = attrs.map do |attr|
|
|
115
|
+
column_name, column_type = attr.split(":", 2)
|
|
116
|
+
next if column_name.to_s.strip.empty? || column_type.to_s.strip.empty?
|
|
117
|
+
" t.#{column_type} :#{column_name}"
|
|
118
|
+
end.compact
|
|
119
|
+
|
|
120
|
+
migration_version = "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
|
121
|
+
FileUtils.mkdir_p(File.dirname(migration_path))
|
|
122
|
+
File.write(migration_path, <<~RUBY)
|
|
123
|
+
class #{migration_class} < ActiveRecord::Migration[#{migration_version}]
|
|
124
|
+
def change
|
|
125
|
+
create_table :#{class_name.tableize} do |t|
|
|
126
|
+
#{columns.join("\n")}
|
|
127
|
+
|
|
128
|
+
t.timestamps
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
RUBY
|
|
133
|
+
|
|
134
|
+
puts "Created #{migration_path}"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
desc "Generate a controller + index view Usage: rake generate:controller Users"
|
|
138
|
+
task :controller, [:name] do |_task, args|
|
|
139
|
+
controller_name = args[:name].presence || positional_arg_for("generate:controller")
|
|
140
|
+
controller_name = controller_name.to_s.strip
|
|
141
|
+
abort "Controller name is required. Example: rake generate:controller Users" if controller_name.empty?
|
|
142
|
+
|
|
143
|
+
base_name = controller_name.underscore
|
|
144
|
+
base_name = base_name.delete_suffix("_controller")
|
|
145
|
+
plural_name = base_name.pluralize
|
|
146
|
+
|
|
147
|
+
controller_path = File.join("app", "controllers", "#{plural_name}_controller.rb")
|
|
148
|
+
view_dir = File.join("app", "views", plural_name)
|
|
149
|
+
view_path = File.join(view_dir, "index.erb")
|
|
150
|
+
|
|
151
|
+
if File.exist?(controller_path)
|
|
152
|
+
puts "Controller exists: #{controller_path}"
|
|
153
|
+
else
|
|
154
|
+
FileUtils.mkdir_p(File.dirname(controller_path))
|
|
155
|
+
File.write(controller_path, <<~RUBY)
|
|
156
|
+
# frozen_string_literal: true
|
|
157
|
+
|
|
158
|
+
class App < Sinatra::Base
|
|
159
|
+
get "/#{plural_name}" do
|
|
160
|
+
erb :\"#{plural_name}/index\"
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
RUBY
|
|
164
|
+
puts "Created #{controller_path}"
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
if File.exist?(view_path)
|
|
168
|
+
puts "View exists: #{view_path}"
|
|
169
|
+
else
|
|
170
|
+
FileUtils.mkdir_p(view_dir)
|
|
171
|
+
File.write(view_path, "<h1>#{plural_name.humanize}</h1>\n")
|
|
172
|
+
puts "Created #{view_path}"
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
desc "Generate model + controller Usage: rake generate:resource User name:string"
|
|
177
|
+
task :resource, [:name] do |_task, args|
|
|
178
|
+
resource_name = args[:name].presence || positional_arg_for("generate:resource")
|
|
179
|
+
resource_name = resource_name.to_s.strip
|
|
180
|
+
abort "Resource name is required. Example: rake generate:resource User" if resource_name.empty?
|
|
181
|
+
|
|
182
|
+
attrs = positional_args_for("generate:resource", from_index: 1).map(&:strip).reject(&:empty?)
|
|
183
|
+
original_tasks = Rake.application.top_level_tasks.dup
|
|
184
|
+
Rake.application.instance_variable_set(:@top_level_tasks, ["generate:model", resource_name, *attrs])
|
|
185
|
+
Rake::Task["generate:model"].invoke(resource_name)
|
|
186
|
+
Rake::Task["generate:controller"].invoke(resource_name.pluralize)
|
|
187
|
+
ensure
|
|
188
|
+
Rake.application.instance_variable_set(:@top_level_tasks, original_tasks) if defined?(original_tasks)
|
|
189
|
+
end
|
|
190
|
+
end
|
|
@@ -6,18 +6,27 @@ require "uri"
|
|
|
6
6
|
rack_env = ENV.fetch("RACK_ENV", "development")
|
|
7
7
|
ActiveRecord::Base.logger = Logger.new($stdout) if rack_env == "development"
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
build_db_config = lambda do |env_name|
|
|
10
|
+
database_url = ENV.fetch("DATABASE_URL", "postgres://localhost/#{APP_NAME}_#{env_name}")
|
|
11
|
+
uri = URI.parse(database_url)
|
|
12
|
+
database_name = uri.path.sub(%r{^/}, "")
|
|
13
|
+
adapter = uri.scheme == "postgres" ? "postgresql" : uri.scheme
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
adapter
|
|
15
|
+
{
|
|
16
|
+
adapter: adapter,
|
|
17
|
+
host: uri.host,
|
|
18
|
+
port: uri.port,
|
|
19
|
+
username: uri.user,
|
|
20
|
+
password: uri.password,
|
|
21
|
+
database: database_name,
|
|
22
|
+
encoding: "utf8"
|
|
23
|
+
}.compact
|
|
24
|
+
end
|
|
14
25
|
|
|
15
|
-
ActiveRecord::Base.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
encoding: "utf8"
|
|
23
|
-
)
|
|
26
|
+
ActiveRecord::Base.configurations = {
|
|
27
|
+
"development" => build_db_config.call("development"),
|
|
28
|
+
"test" => build_db_config.call("test"),
|
|
29
|
+
"production" => build_db_config.call("production")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
ActiveRecord::Base.establish_connection(rack_env.to_sym)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: frankly
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ken Rettberg
|
|
@@ -135,6 +135,17 @@ licenses:
|
|
|
135
135
|
metadata:
|
|
136
136
|
homepage_uri: https://github.com/kenrett/frankly
|
|
137
137
|
source_code_uri: https://github.com/kenrett/frankly
|
|
138
|
+
post_install_message: |2
|
|
139
|
+
.
|
|
140
|
+
.---------.'---.
|
|
141
|
+
'. : .'
|
|
142
|
+
'. .::: .' The Chairman
|
|
143
|
+
'.'::'.' of the Board
|
|
144
|
+
'||' has arrived.
|
|
145
|
+
||
|
|
146
|
+
||
|
|
147
|
+
||
|
|
148
|
+
---====---
|
|
138
149
|
rdoc_options: []
|
|
139
150
|
require_paths:
|
|
140
151
|
- lib
|