lux-fw 0.1.17
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 +7 -0
- data/.version +1 -0
- data/bin/cli/am +250 -0
- data/bin/cli/assets +37 -0
- data/bin/cli/console +50 -0
- data/bin/cli/dev +1 -0
- data/bin/cli/eval +15 -0
- data/bin/cli/exceptions +62 -0
- data/bin/cli/generate +82 -0
- data/bin/cli/get +5 -0
- data/bin/cli/nginx +28 -0
- data/bin/cli/production +1 -0
- data/bin/cli/routes +12 -0
- data/bin/cli/server +1 -0
- data/bin/cli/stat +1 -0
- data/bin/forever +65 -0
- data/bin/job_que +39 -0
- data/bin/lux +87 -0
- data/bin/txt/nginx.conf +29 -0
- data/bin/txt/siege-and-puma.txt +3 -0
- data/lib/common/base32.rb +47 -0
- data/lib/common/before_and_after.rb +71 -0
- data/lib/common/class_attributes.rb +66 -0
- data/lib/common/class_method_params.rb +94 -0
- data/lib/common/crypt.rb +66 -0
- data/lib/common/folder_model.rb +50 -0
- data/lib/common/generic_model.rb +62 -0
- data/lib/common/policy.rb +54 -0
- data/lib/common/string_base.rb +49 -0
- data/lib/common/url.rb +171 -0
- data/lib/lux/api/api.rb +150 -0
- data/lib/lux/api/lib/application_api.rb +19 -0
- data/lib/lux/api/lib/doc_builder.rb +18 -0
- data/lib/lux/api/lib/dsl.rb +73 -0
- data/lib/lux/api/lib/model_api.rb +145 -0
- data/lib/lux/api/lib/rescue.rb +18 -0
- data/lib/lux/cache/cache.rb +71 -0
- data/lib/lux/cache/lib/memcached.rb +3 -0
- data/lib/lux/cache/lib/null.rb +23 -0
- data/lib/lux/cache/lib/ram.rb +38 -0
- data/lib/lux/cell/cell.rb +260 -0
- data/lib/lux/config/config.rb +88 -0
- data/lib/lux/controller/controller.rb +185 -0
- data/lib/lux/controller/lib/nav.rb +77 -0
- data/lib/lux/controller/lib/plugs.rb +10 -0
- data/lib/lux/delayed_job/delayed_job.rb +44 -0
- data/lib/lux/delayed_job/lib/memory.rb +14 -0
- data/lib/lux/delayed_job/lib/nsq.rb +3 -0
- data/lib/lux/delayed_job/lib/postgre.rb +6 -0
- data/lib/lux/delayed_job/lib/redis.rb +19 -0
- data/lib/lux/error/error.rb +75 -0
- data/lib/lux/helper/helper.rb +109 -0
- data/lib/lux/html/html.rb +3 -0
- data/lib/lux/html/lib/form.rb +81 -0
- data/lib/lux/html/lib/input.rb +71 -0
- data/lib/lux/html/lib/input_types.rb +277 -0
- data/lib/lux/lux.rb +164 -0
- data/lib/lux/mailer/mailer.rb +73 -0
- data/lib/lux/page/lib/encrypt_params.rb +44 -0
- data/lib/lux/page/lib/flash.rb +49 -0
- data/lib/lux/page/lib/static_file.rb +97 -0
- data/lib/lux/page/page.rb +271 -0
- data/lib/lux/rescue_from/rescue_from.rb +61 -0
- data/lib/lux/template/template.rb +95 -0
- data/lib/lux-fw.rb +48 -0
- data/lib/overload/array.rb +52 -0
- data/lib/overload/blank.rb +62 -0
- data/lib/overload/date.rb +58 -0
- data/lib/overload/file.rb +14 -0
- data/lib/overload/hash.rb +86 -0
- data/lib/overload/hash_wia.rb +282 -0
- data/lib/overload/inflections.rb +199 -0
- data/lib/overload/integer.rb +19 -0
- data/lib/overload/module.rb +10 -0
- data/lib/overload/nil.rb +8 -0
- data/lib/overload/object.rb +77 -0
- data/lib/overload/string.rb +89 -0
- data/lib/overload/string_inflections.rb +7 -0
- data/lib/overload/struct.rb +5 -0
- data/lib/plugins/assets/assets_plug.rb +26 -0
- data/lib/plugins/assets/helper_module_adapter.rb +49 -0
- data/lib/plugins/assets/init.rb +4 -0
- data/lib/plugins/db_helpers/array_and_hstore.rb +64 -0
- data/lib/plugins/db_helpers/arrays_and_tags.rb +23 -0
- data/lib/plugins/db_helpers/before_save.rb +44 -0
- data/lib/plugins/db_helpers/cached_find_by.rb +45 -0
- data/lib/plugins/db_helpers/class_and_instance.rb +120 -0
- data/lib/plugins/db_helpers/dataset_plugin.rb +101 -0
- data/lib/plugins/db_helpers/filter_wrappers.rb +21 -0
- data/lib/plugins/db_helpers/link_plugin.rb +95 -0
- data/lib/plugins/db_helpers/localize_plugin.rb +57 -0
- data/lib/plugins/db_helpers/primary_keys.rb +36 -0
- data/lib/plugins/db_helpers/typero_attributes.rb +69 -0
- data/lib/plugins/db_logger/init.rb +18 -0
- data/lib/plugins/db_logger/lux_response_adapter.rb +9 -0
- data/lib/plugins/paginate/helper.rb +32 -0
- data/lib/plugins/paginate/sequel_adapter.rb +18 -0
- data/lib/vendor/mini_assets/mini_asset/base.rb +167 -0
- data/lib/vendor/mini_assets/mini_asset/css.rb +38 -0
- data/lib/vendor/mini_assets/mini_asset/js.rb +38 -0
- data/lib/vendor/mini_assets/mini_asset.rb +31 -0
- data/lib/vendor/oauth/lib/facebook.rb +35 -0
- data/lib/vendor/oauth/lib/github.rb +37 -0
- data/lib/vendor/oauth/lib/google.rb +41 -0
- data/lib/vendor/oauth/lib/linkedin.rb +41 -0
- data/lib/vendor/oauth/lib/stackexchange.rb +37 -0
- data/lib/vendor/oauth/lib/twitter.rb +41 -0
- data/lib/vendor/oauth/oauth.rb +46 -0
- metadata +334 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 5cf39a83b84a57cdc4523101a880a856a274723a
|
|
4
|
+
data.tar.gz: 850600181673ff261e0180dd862993060d153b26
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d47ecd1b0aac507cb33613bcdb2b2aaa1d8ff11952a5ae8a2bd40d54c8c60108d3b176a7db79c2108bbcb2cf74e1aaf52bc7b3a54139e15f09c44eab454df864
|
|
7
|
+
data.tar.gz: 5eb42b08476252ea35d45d06f7cc40702f9626e8f26a44b155c815b65417030ca68ddb05b93d493c66ae650208b1ddb2c9a9038fdd81500cd5f2588e3434870d
|
data/.version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.17
|
data/bin/cli/am
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
ENV['DB_NAME'] = ARGV[0] if ARGV[0]
|
|
4
|
+
|
|
5
|
+
require './config/application'
|
|
6
|
+
|
|
7
|
+
class AutoMigrate
|
|
8
|
+
attr_accessor :fields
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
def table(table_name)
|
|
12
|
+
die "table [#{table_name}] not in plural -> expected [#{table_name.to_s.pluralize}]" unless table_name.to_s.pluralize == table_name.to_s
|
|
13
|
+
klass = table_name.to_s.classify
|
|
14
|
+
unless Object.const_defined?(klass)
|
|
15
|
+
puts "model #{klass} not defiend for table #{table_name}".red
|
|
16
|
+
exit
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
unless DB.table_exists?(table_name.to_s)
|
|
20
|
+
# http://sequel.jeremyevans.net/rdoc/files/doc/schema_modification_rdoc.html
|
|
21
|
+
DB.create_table table_name do
|
|
22
|
+
primary_key :id, Integer
|
|
23
|
+
index :id, :unique=>true
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
t = new(table_name)
|
|
28
|
+
yield(t)
|
|
29
|
+
t.fix_fields
|
|
30
|
+
t.update
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def migrate(&block)
|
|
34
|
+
instance_eval(&block)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def enable_extension(name)
|
|
38
|
+
DB.run "CREATE EXTENSION IF NOT EXISTS #{name};"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def transaction_do text
|
|
42
|
+
begin
|
|
43
|
+
DB.run 'BEGIN; %s ;COMMIT;' % text
|
|
44
|
+
rescue
|
|
45
|
+
puts caller[1].red
|
|
46
|
+
puts text.yellow
|
|
47
|
+
raise $!
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
###
|
|
53
|
+
|
|
54
|
+
def initialize(table_name)
|
|
55
|
+
@table_name = table_name
|
|
56
|
+
@fields = {}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def log_run(what)
|
|
60
|
+
puts " #{what.green}"
|
|
61
|
+
self.class.transaction_do what
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def fix_fields
|
|
65
|
+
for vals in @fields.values
|
|
66
|
+
type = vals[0]
|
|
67
|
+
opts = vals[1]
|
|
68
|
+
|
|
69
|
+
opts[:limit] ||= 255 if type == :string
|
|
70
|
+
opts[:default] ||= false if type == :boolean
|
|
71
|
+
|
|
72
|
+
opts[:null] = true unless opts[:null].class.name == 'FalseClass'
|
|
73
|
+
opts[:array] ||= false
|
|
74
|
+
opts[:unique] ||= false
|
|
75
|
+
opts[:default] = [] if opts[:array]
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def get_db_column_type(field)
|
|
80
|
+
type, opts = @fields[field]
|
|
81
|
+
db_type = type
|
|
82
|
+
db_type = :varchar if type == :string
|
|
83
|
+
db_type = Time if type == :datetime
|
|
84
|
+
if opts[:array]
|
|
85
|
+
db_type = "#{db_type}(#{opts[:limit]})" if type == :string
|
|
86
|
+
db_type = "#{db_type}[]"
|
|
87
|
+
else
|
|
88
|
+
db_type = "varchar(#{opts[:limit]})" if opts[:limit]
|
|
89
|
+
end
|
|
90
|
+
db_type
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def update
|
|
94
|
+
begin
|
|
95
|
+
obj = @table_name.to_s.classify.constantize
|
|
96
|
+
o = obj.new
|
|
97
|
+
rescue
|
|
98
|
+
puts "Object #{@table_name.to_s.classify.red} does not exist, yet table #{@table_name.to_s.red} exists!"
|
|
99
|
+
# puts $!.message
|
|
100
|
+
return
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# remove extra fields
|
|
104
|
+
existing_fields = o.attributes.keys - ['id']
|
|
105
|
+
for field in (existing_fields - @fields.keys.map(&:to_s))
|
|
106
|
+
print "Remove colum #{@table_name}.#{field} (y/N): ".blue
|
|
107
|
+
if STDIN.gets.chomp.downcase.index('y')
|
|
108
|
+
DB.drop_column @table_name, field
|
|
109
|
+
puts " drop_column #{field}".green
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
puts "Table #{@table_name.to_s.yellow}, #{@fields.keys.length} fields"
|
|
114
|
+
|
|
115
|
+
for field, opts_in in @fields
|
|
116
|
+
type = opts_in[0]
|
|
117
|
+
opts = opts_in[1]
|
|
118
|
+
|
|
119
|
+
db_type = get_db_column_type(field)
|
|
120
|
+
|
|
121
|
+
# create missing columns
|
|
122
|
+
unless obj.columns.index(field.to_sym)
|
|
123
|
+
DB.add_column @table_name, field, db_type, opts
|
|
124
|
+
|
|
125
|
+
if opts[:array]
|
|
126
|
+
default = type == :string ? "ARRAY[]::character varying[]" : "ARRAY[]::integer[]"
|
|
127
|
+
|
|
128
|
+
self.class.transaction_do "ALTER TABLE #{@table_name} ALTER COLUMN #{field} SET DEFAULT #{default};"
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
puts " add_column #{field}, #{db_type}, #{opts.to_json}".green
|
|
132
|
+
next
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
if current = obj.db_schema[field.to_sym]
|
|
136
|
+
# limit changed
|
|
137
|
+
|
|
138
|
+
# if we have type set as array and in db it is not array, fix that
|
|
139
|
+
if opts[:array] && !current[:db_type].include?('[]')
|
|
140
|
+
|
|
141
|
+
self.class.transaction_do %[
|
|
142
|
+
alter table #{@table_name} alter #{field} drop default;
|
|
143
|
+
alter table #{@table_name} alter #{field} type #{current[:db_type]}[] using array[#{field}];
|
|
144
|
+
alter table #{@table_name} alter #{field} set default '{}';
|
|
145
|
+
]
|
|
146
|
+
|
|
147
|
+
puts " Coverted #{@table_name}.#{field} to array type".green
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# if we have array but scema says no array
|
|
151
|
+
if !opts[:array] && current[:db_type].include?('[]')
|
|
152
|
+
m = current[:type] == :integer ? "#{field}[0]" : "array_to_string(#{field}, ',')"
|
|
153
|
+
|
|
154
|
+
self.class.transaction_do %[
|
|
155
|
+
alter table #{@table_name} alter #{field} drop default;
|
|
156
|
+
alter table #{@table_name} alter #{field} type #{current[:db_type].sub('[]','')} using #{m};
|
|
157
|
+
]
|
|
158
|
+
|
|
159
|
+
puts " Coverted #{@table_name}.#{field}[] to non array type".red
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# ap "#{@table_name}, #{field}, #{db_type}, #{current[:max_length]}, #{opts[:limit]}" if field == 'description'
|
|
163
|
+
if type == :string && current[:max_length] != opts[:limit]
|
|
164
|
+
self.class.transaction_do "ALTER TABLE #{@table_name} ALTER COLUMN #{field} TYPE varchar(#{opts[:limit]});"
|
|
165
|
+
puts " #{field} limit, #{current[:max_length]}-> #{opts[:limit]}".green
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
if type == :text && current[:max_length]
|
|
169
|
+
self.class.transaction_do "ALTER TABLE #{@table_name} ALTER COLUMN #{field} SET DATA TYPE text"
|
|
170
|
+
puts " #{field} limit from #{current[:max_length]} to no limit (text type)".green
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# null true or false
|
|
174
|
+
if current[:allow_null] != opts[:null]
|
|
175
|
+
to_run = " #{field} #{opts[:null] ? 'DROP' : 'SET'} NOT NULL"
|
|
176
|
+
log_run "ALTER TABLE #{@table_name} ALTER COLUMN #{to_run}"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# field default changed
|
|
180
|
+
if current[:default].to_s != opts[:default].to_s
|
|
181
|
+
# skip for arrays
|
|
182
|
+
next if opts[:array]
|
|
183
|
+
next if current[:default].to_s.index('{}') and opts[:default] == []
|
|
184
|
+
next if current[:default].to_s.starts_with?("'#{opts[:default]}':")
|
|
185
|
+
|
|
186
|
+
if opts[:default].to_s.blank?
|
|
187
|
+
log_run "ALTER TABLE #{@table_name} ALTER COLUMN #{field} drop default"
|
|
188
|
+
else
|
|
189
|
+
log_run "ALTER TABLE #{@table_name} ALTER COLUMN #{field} SET DEFAULT '#{opts[:default]}'; update #{@table_name} set #{field}='#{opts[:default]}' where #{field} is null;"
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
if opts[:index]
|
|
194
|
+
add_index(field)
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def add_index(field)
|
|
202
|
+
type = @table_name.to_s.classify.constantize.new.db_schema[field][:db_type] rescue nil
|
|
203
|
+
# puts "#{field.to_s.yellow} (#{type})"
|
|
204
|
+
|
|
205
|
+
begin
|
|
206
|
+
if type.index('[]')
|
|
207
|
+
DB.run %[CREATE INDEX #{@table_name}_#{field}_gin_index on "#{@table_name}" USING GIN ("#{field}");]
|
|
208
|
+
puts " * added array GIN index on #{field}".green
|
|
209
|
+
else
|
|
210
|
+
DB.add_index(@table_name, field)
|
|
211
|
+
puts " * added index on #{field}".green
|
|
212
|
+
end
|
|
213
|
+
rescue; end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def rename(field_old, field_new)
|
|
217
|
+
existing_fields = @table_name.to_s.classify.constantize.new.attributes.keys.map(&:to_sym)
|
|
218
|
+
if existing_fields.index(field_old) && ! existing_fields.index(field_new)
|
|
219
|
+
DB.rename_column(@table_name, field_old, field_new)
|
|
220
|
+
puts " * renamed #{@table_name}.#{field_old} to #{@table_name}.#{field_new}"
|
|
221
|
+
puts ' * please run auto migration again'
|
|
222
|
+
exit
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def method_missing(type, *args)
|
|
227
|
+
name = args[0]
|
|
228
|
+
opts = args[1] || {}
|
|
229
|
+
if [:string, :integer, :text, :boolean, :datetime, :date, :jsonb].index(type)
|
|
230
|
+
@fields[name] = [type, opts]
|
|
231
|
+
elsif [:decimal].index(type)
|
|
232
|
+
opts[:precision] ||= 8
|
|
233
|
+
opts[:scale] ||= 2
|
|
234
|
+
@fields[name] = [:decimal, opts]
|
|
235
|
+
elsif type == :timestamps
|
|
236
|
+
opts[:null] ||= false
|
|
237
|
+
@fields[:created_at] = [:datetime, opts]
|
|
238
|
+
@fields[:created_by] = [:integer, opts.merge(index: true)]
|
|
239
|
+
@fields[:updated_at] = [:datetime, opts]
|
|
240
|
+
@fields[:updated_by] = [:integer, opts]
|
|
241
|
+
elsif type == :polymorphic
|
|
242
|
+
@fields["#{name}_id".to_sym] = [:integer, opts.merge(index: true) ]
|
|
243
|
+
@fields["#{name}_type".to_sym] = [:string, opts.merge(limit: 100, index: "#{name}_id")]
|
|
244
|
+
else
|
|
245
|
+
puts "Unknown #{type.to_s.red}"
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
require './config/schema.rb'
|
data/bin/cli/assets
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
if ARGV[0] == 'help'
|
|
4
|
+
puts 'lux assets rm gzip s3://assets'
|
|
5
|
+
puts ' rm - remove local cached folder for assets'
|
|
6
|
+
puts ' gzip - gzip files (for nginx)'
|
|
7
|
+
puts ' s3://path - copy files to bucket (must be last argument)'
|
|
8
|
+
exit
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
if ARGV.include?('rm')
|
|
12
|
+
system 'rm -rf ./tmp/assets'
|
|
13
|
+
system 'rm -rf ./public/assets'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
require './config/application'
|
|
17
|
+
|
|
18
|
+
assets = Dir['./app/assets/*/index.*'].map { |el| el.sub('./app/assets/','') }
|
|
19
|
+
|
|
20
|
+
Lux.config.assets_precompile = true
|
|
21
|
+
|
|
22
|
+
speed = Lux.speed do
|
|
23
|
+
# tpool is not showing compile errors
|
|
24
|
+
# tpool(assets) do |file|
|
|
25
|
+
for file in assets
|
|
26
|
+
asset = MiniAsset.create file
|
|
27
|
+
asset.compile ARGV
|
|
28
|
+
puts "Generated #{file.green} -> #{asset.production_file}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
puts "Asset precomlile done in #{speed}"
|
|
33
|
+
|
|
34
|
+
if ARGV.last && ARGV.last[0,5] == 's3://'
|
|
35
|
+
puts 'Copy to %s'.green % ARGV.last
|
|
36
|
+
system 'aws s3 sync ./public %s --cache-control "max-age=31536000, no-transform, public"' % ARGV.last
|
|
37
|
+
end
|
data/bin/cli/console
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
ENV['LUX_VERBOSE'] ||= 'true'
|
|
4
|
+
|
|
5
|
+
load_start = Time.now
|
|
6
|
+
|
|
7
|
+
require 'awesome_print'
|
|
8
|
+
require 'clipboard'
|
|
9
|
+
require './config/application'
|
|
10
|
+
|
|
11
|
+
if File.exist?('./config/console.rb')
|
|
12
|
+
puts '* loading ./config/console.rb'
|
|
13
|
+
require './config/console'
|
|
14
|
+
else
|
|
15
|
+
puts '* ./config/console.rb not found'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
Lux::Config.live_require_check! if Lux.config(:auto_code_reload)
|
|
19
|
+
|
|
20
|
+
puts Lux::Config.show_load_speed load_start
|
|
21
|
+
|
|
22
|
+
class Object
|
|
23
|
+
def cp data
|
|
24
|
+
data = JSON.pretty_generate(data.to_hash) if data.respond_to?(:to_hash)
|
|
25
|
+
Clipboard.copy data
|
|
26
|
+
'copied'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
begin
|
|
31
|
+
require 'pry'
|
|
32
|
+
|
|
33
|
+
# AwesomePrint.pry!
|
|
34
|
+
# nice object dump in console
|
|
35
|
+
Pry.print = proc { |output, data|
|
|
36
|
+
out = if data.is_a?(Hash)
|
|
37
|
+
data.class.to_s+"\n"+JSON.pretty_generate(data).gsub(/"(\w+)":/) { '"%s":' % $1.yellow }
|
|
38
|
+
else
|
|
39
|
+
data.ai
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
output.puts out
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Pry
|
|
46
|
+
rescue LoadError
|
|
47
|
+
puts 'pry not found, starting irb'.red
|
|
48
|
+
require 'irb'
|
|
49
|
+
IRB
|
|
50
|
+
end.start
|
data/bin/cli/dev
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
LuxCli.run "rerun -p '**/*.{rb,ru}' 'puma -p %s'" % @port
|
data/bin/cli/eval
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require './config/application'
|
|
4
|
+
|
|
5
|
+
puts '* loading ./config/console.rb' if File.exist?('./config/console.rb')
|
|
6
|
+
|
|
7
|
+
command = ARGV.join('; ')
|
|
8
|
+
|
|
9
|
+
puts 'Command : %s' % command.light_blue
|
|
10
|
+
|
|
11
|
+
data = eval command
|
|
12
|
+
puts '-'
|
|
13
|
+
puts 'Class : %s' % data.class
|
|
14
|
+
puts '-'
|
|
15
|
+
ap data
|
data/bin/cli/exceptions
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'colorize'
|
|
4
|
+
|
|
5
|
+
ERROR_FOLDER = './log/exceptions'
|
|
6
|
+
|
|
7
|
+
case ARGV[0]
|
|
8
|
+
when 'help'
|
|
9
|
+
puts ' lux exceptions - show all exceptions'
|
|
10
|
+
puts ' lux exceptions clear - to clear error folder'
|
|
11
|
+
puts ' lux exceptions NUMBER - to show error on specific number'
|
|
12
|
+
exit
|
|
13
|
+
when 'clear'
|
|
14
|
+
LuxCli.run 'rm -rf "%s"' % ERROR_FOLDER
|
|
15
|
+
puts '%s removed' % ERROR_FOLDER
|
|
16
|
+
exit
|
|
17
|
+
else
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
show = ARGV[0] ? ARGV[0].to_i : nil
|
|
21
|
+
|
|
22
|
+
error_folders = Dir['%s/*' % ERROR_FOLDER].sort_by { |x| File.mtime(x) }
|
|
23
|
+
|
|
24
|
+
if error_folders.length == 0
|
|
25
|
+
puts 'Nothing found in %s'.blue % ERROR_FOLDER
|
|
26
|
+
exit
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
cnt = 0
|
|
30
|
+
|
|
31
|
+
puts 'Add error number as last argument to show full erros'.blue
|
|
32
|
+
|
|
33
|
+
error_folders.each do |error_folder|
|
|
34
|
+
cnt += 1
|
|
35
|
+
next if show && show != cnt
|
|
36
|
+
|
|
37
|
+
print '%s. %s - ' % [cnt.to_s.rjust(2), error_folder.split('/').last.yellow]
|
|
38
|
+
file = Dir['%s/*.txt' % error_folder].sort_by{ |f| File.mtime(f) }.first
|
|
39
|
+
next unless file
|
|
40
|
+
|
|
41
|
+
last_update = (Time.now - File.mtime(file)).to_i
|
|
42
|
+
|
|
43
|
+
if last_update < 60
|
|
44
|
+
print '%s sec ago - ' % last_update.to_s.blue
|
|
45
|
+
elsif last_update < 60*60
|
|
46
|
+
print '%s mins ago - ' % (last_update/60).to_i.to_s.blue
|
|
47
|
+
elsif last_update < 60*60*24
|
|
48
|
+
print '%s hours ago - ' % (last_update/(60*60)).to_i.to_s.blue
|
|
49
|
+
else
|
|
50
|
+
print '%s days ago - ' % (last_update/(60*60*24)).to_i.to_s.blue
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
puts file.split('/').last
|
|
54
|
+
|
|
55
|
+
if show
|
|
56
|
+
puts "\n" + File.read(file)
|
|
57
|
+
exit
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
first_line = File.read(file).split("\n").first
|
|
61
|
+
puts ' %s' % first_line
|
|
62
|
+
end
|
data/bin/cli/generate
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# use {{object}} and {{objects}} and {{object.classify}} as template
|
|
4
|
+
|
|
5
|
+
require 'optparse'
|
|
6
|
+
require 'colorize'
|
|
7
|
+
require 'fileutils'
|
|
8
|
+
require 'sequel'
|
|
9
|
+
require 'pp'
|
|
10
|
+
|
|
11
|
+
Sequel.extension :inflector
|
|
12
|
+
|
|
13
|
+
unless ARGV[0]
|
|
14
|
+
puts "./generate [object singular]".red
|
|
15
|
+
exit
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
template_dir = 'config/templates'
|
|
19
|
+
exit puts "Lux::Template dir #{template_dir} is not accessible" unless Dir.exists?(template_dir)
|
|
20
|
+
|
|
21
|
+
tpl_desc = {
|
|
22
|
+
p:'api',
|
|
23
|
+
m:'model',
|
|
24
|
+
a:'admin',
|
|
25
|
+
c:'cell',
|
|
26
|
+
v:'view'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@object = ARGV[0]
|
|
30
|
+
@objects = @object.pluralize
|
|
31
|
+
|
|
32
|
+
puts "Singular : #{@object.yellow}"
|
|
33
|
+
puts "Plural : #{@objects.yellow}"
|
|
34
|
+
|
|
35
|
+
def parse_vars(data)
|
|
36
|
+
object = @object
|
|
37
|
+
objects = @objects
|
|
38
|
+
klass = @object.classify
|
|
39
|
+
|
|
40
|
+
data.gsub(/\{\{([^\}]+)\}\}/) { eval $1 }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# get all files
|
|
44
|
+
templates = {}
|
|
45
|
+
for el in Dir["./#{template_dir}/*.*"].map{ |file| file.split('/').last }
|
|
46
|
+
begin
|
|
47
|
+
data = parse_vars(File.read("#{template_dir}/#{el}"))
|
|
48
|
+
rescue
|
|
49
|
+
puts '-'
|
|
50
|
+
puts "File error: #{el.red}: #{$!.message}"
|
|
51
|
+
exit
|
|
52
|
+
end
|
|
53
|
+
type = el[0,1]
|
|
54
|
+
|
|
55
|
+
path = el.split('|', 2)[1]
|
|
56
|
+
path = parse_vars(path).gsub('#','/')
|
|
57
|
+
|
|
58
|
+
templates[type] ||= []
|
|
59
|
+
templates[type].push [path, data]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# # puts "Lux::Templates : #{templates.keys.sort.map{ |el| tpl_desc[el.to_sym] ? tpl_desc[el.to_sym].sub(el, el.upcase.yellow) : el.yellow }.join(', ')}"
|
|
63
|
+
puts "Lux::Templates : #{templates.keys.map{ |el| "#{tpl_desc[el.to_sym]}(#{el.yellow})" }.join(', ')}"
|
|
64
|
+
print "Execute : "
|
|
65
|
+
|
|
66
|
+
parse_templates = STDIN.gets.chomp
|
|
67
|
+
|
|
68
|
+
for type in templates.keys
|
|
69
|
+
next unless parse_templates.index(type)
|
|
70
|
+
for el in templates[type]
|
|
71
|
+
file, data = *el
|
|
72
|
+
if File.exists?(file)
|
|
73
|
+
print 'exists'.yellow.rjust(20)
|
|
74
|
+
else
|
|
75
|
+
FileUtils.mkdir_p(file.sub(/\/[^\/]+$/,'')) rescue false
|
|
76
|
+
File.open(file, 'w') { |f| f.write(data) }
|
|
77
|
+
print 'created'.green.rjust(20)
|
|
78
|
+
end
|
|
79
|
+
puts ": #{file}"
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
data/bin/cli/get
ADDED
data/bin/cli/nginx
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
command = ARGV[0]
|
|
4
|
+
|
|
5
|
+
@local_conf = './config/nginx.conf'
|
|
6
|
+
@nginx_conf = '/etc/nginx/sites-enabled/%s.conf' % Dir.pwd.split('/').last
|
|
7
|
+
|
|
8
|
+
def build_conf
|
|
9
|
+
conf = File.read(@local_conf) rescue LuxCli.die('Local conf %s not found' % @local_conf)
|
|
10
|
+
|
|
11
|
+
LuxCli.die('$ROOT not found in config') unless conf.include?('$ROOT')
|
|
12
|
+
|
|
13
|
+
conf.gsub('$ROOT', Dir.pwd)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
case command
|
|
17
|
+
when 'show'
|
|
18
|
+
puts build_conf
|
|
19
|
+
when 'install'
|
|
20
|
+
File.write './tmp/nginx.conf', build_conf
|
|
21
|
+
puts '# run this manualy'
|
|
22
|
+
puts
|
|
23
|
+
puts 'sudo cp ./tmp/nginx.conf %s && sudo nginx -t' % @nginx_conf
|
|
24
|
+
else
|
|
25
|
+
puts ' show # show rendered config'
|
|
26
|
+
puts ' install # install config/nginx.conf to %s' % @nginx_conf
|
|
27
|
+
end
|
|
28
|
+
|
data/bin/cli/production
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
LuxCli.run "puma -p %s -e production" % @port
|
data/bin/cli/routes
ADDED
data/bin/cli/server
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
LuxCli.run "LUX_VERBOSE=true puma -p %s" % @port
|
data/bin/cli/stat
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
LuxCli.run 'goaccess -ca -f /var/log/nginx/access.log -a > public/goaccess.html'
|
data/bin/forever
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# better? -> https://github.com/bluepill-rb/bluepill
|
|
4
|
+
|
|
5
|
+
# ~/forever/forever.txt
|
|
6
|
+
# test: /Users/dux/.rvm/rubies/ruby-2.3.1/bin/ruby /Users/dux/dev/lux-fw/raumdog.com/test.rb
|
|
7
|
+
# test2: /Users/dux/.rvm/rubies/ruby-2.3.1/bin/ruby /Users/dux/dev/lux-fw/raumdog.com/test2.rb
|
|
8
|
+
|
|
9
|
+
# creates ~/forever/logs and ~/forever/pids
|
|
10
|
+
# keeps logs in size
|
|
11
|
+
|
|
12
|
+
# 1 1 * * * bash -l -c 'ruby /User/adsad/../forever'
|
|
13
|
+
|
|
14
|
+
require 'colorize'
|
|
15
|
+
require 'fileutils'
|
|
16
|
+
|
|
17
|
+
@root = File.expand_path('~/forever')
|
|
18
|
+
@max_file_size_in_mb = 1
|
|
19
|
+
|
|
20
|
+
def die(data)
|
|
21
|
+
puts data.red
|
|
22
|
+
exit
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def demonize(id, script)
|
|
26
|
+
size = @max_file_size_in_mb * 1_000_000
|
|
27
|
+
|
|
28
|
+
# rotate big files
|
|
29
|
+
for log_file in ["#{@root}/logs/#{id}.log", "#{@root}/logs/#{id}.err"]
|
|
30
|
+
if File.size?(log_file).to_i > (size * 3)
|
|
31
|
+
puts "truncate #{log_file} to #{size}".yellow
|
|
32
|
+
data = File.read(log_file)
|
|
33
|
+
data = data[data.length - size, size]
|
|
34
|
+
File.open(log_file, 'w') { |f| f.write(data) }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
pid_file = "#{@root}/pids/#{id}.pid"
|
|
39
|
+
pid = File.read(pid_file).chomp rescue nil
|
|
40
|
+
|
|
41
|
+
env_id = "FOREVER_ID=#{id}_END"
|
|
42
|
+
|
|
43
|
+
if pid && `ps aux | grep #{env_id} | grep #{pid}`.index(script)
|
|
44
|
+
puts "exists #{id.ljust(15)} pid #{pid}".green
|
|
45
|
+
else
|
|
46
|
+
print "starting #{id.ljust(15)} pid ".yellow
|
|
47
|
+
`nohup #{script} #{env_id} >> #{@root}/logs/#{id}.log 2>> #{@root}/logs/#{id}.err < /dev/null & echo $! > #{pid_file}`
|
|
48
|
+
puts File.read(pid_file)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
file = "#{@root}/forever.txt"
|
|
53
|
+
die "~/forever/forever.txt not present (#{file})" unless File.exist?(file)
|
|
54
|
+
|
|
55
|
+
FileUtils.mkdir_p "#{@root}/logs"
|
|
56
|
+
FileUtils.mkdir_p "#{@root}/pids"
|
|
57
|
+
|
|
58
|
+
apps = File.read(file).to_s.split("\n")
|
|
59
|
+
|
|
60
|
+
for line in apps
|
|
61
|
+
next if line[0,1] == '#'
|
|
62
|
+
id, script = line.split(/\s*:\s*/, 2)
|
|
63
|
+
next unless script
|
|
64
|
+
demonize id, script
|
|
65
|
+
end
|
data/bin/job_que
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
check = `ps ax | grep ruby`.split("\n").select{ |line| line.index($0) }
|
|
4
|
+
check.select! { |line| !line.index("#{Process.pid} ") }
|
|
5
|
+
|
|
6
|
+
if check.length > 0
|
|
7
|
+
puts "Lux job_que allready running"
|
|
8
|
+
puts check
|
|
9
|
+
exit
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
eval File.read './lux/loader.rb'
|
|
13
|
+
Lux.delay.run!
|
|
14
|
+
|
|
15
|
+
# require 'pathname'
|
|
16
|
+
# pid_file = Pathname.new("./tmp/job_que.pid")
|
|
17
|
+
|
|
18
|
+
# if pid_file.exist?
|
|
19
|
+
# pid = pid_file.read
|
|
20
|
+
# proc = `ps -p #{pid} -o comm=`
|
|
21
|
+
# if proc.to_s.length > 1
|
|
22
|
+
# puts "Lux job_que allready running, pid: #{pid}"
|
|
23
|
+
# system "ps ax | grep #{pid} | grep ruby"
|
|
24
|
+
# exit
|
|
25
|
+
# end
|
|
26
|
+
# end
|
|
27
|
+
|
|
28
|
+
# pid_file.write(Process.pid)
|
|
29
|
+
# Kernel.at_exit { pid_file.delete }
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# Lux.config.redis_server = Redis::Queue.new('__test', 'bp__test', :redis => Redis.new)
|
|
33
|
+
# Lux.delay.server = :memory
|
|
34
|
+
# Lux.delay.server = :redis
|
|
35
|
+
# Lux.delay.push("puts '123 abc > mem'.red")
|
|
36
|
+
# Lux.delay.push("puts '123 abc > redis'.red")
|
|
37
|
+
# Lux.delay.push(Mailer.confirm_email('rejotl@gmail.com'), :deliver)
|
|
38
|
+
# Mailer.confirm_email('rejotl@gmail.com').deliver_later
|
|
39
|
+
# Lux.delay.run!
|