forcast 0.0.110
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/.gitignore +1 -0
- data/COPYRIGHTS +11 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +166 -0
- data/PENDIENTES +39 -0
- data/README.md +35 -0
- data/Rakefile +7 -0
- data/VERSION +1 -0
- data/bin/console +14 -0
- data/bin/rake +28 -0
- data/bin/setup +8 -0
- data/forcast.gemspec +73 -0
- data/lib/forcast.rb +5 -0
- data/lib/forcast/controllers/all.rb +2 -0
- data/lib/forcast/controllers/application/all.rb +12 -0
- data/lib/forcast/controllers/application/crud.rb +91 -0
- data/lib/forcast/controllers/application/database.rb +34 -0
- data/lib/forcast/controllers/application/error.rb +18 -0
- data/lib/forcast/controllers/application/exception_handler.rb +25 -0
- data/lib/forcast/controllers/application/json.rb +83 -0
- data/lib/forcast/controllers/application/locale.rb +30 -0
- data/lib/forcast/controllers/application/log.rb +22 -0
- data/lib/forcast/controllers/application/login.rb +41 -0
- data/lib/forcast/controllers/application/meta.rb +61 -0
- data/lib/forcast/controllers/application/model.rb +17 -0
- data/lib/forcast/controllers/application/permitirtodo.rb +27 -0
- data/lib/forcast/controllers/application/utils.rb +28 -0
- data/lib/forcast/controllers/controller/all.rb +8 -0
- data/lib/forcast/controllers/controller/asociar.rb +121 -0
- data/lib/forcast/controllers/controller/busqueda.rb +151 -0
- data/lib/forcast/controllers/controller/definitor/definitor.rb +322 -0
- data/lib/forcast/controllers/controller/definitor/definitor_page.rb +40 -0
- data/lib/forcast/controllers/controller/definitor_all.rb +2 -0
- data/lib/forcast/controllers/controller/filtro.rb +48 -0
- data/lib/forcast/controllers/controller/login/controllers/base_controller.rb +135 -0
- data/lib/forcast/controllers/controller/login/controllers/login_controller.rb +38 -0
- data/lib/forcast/controllers/controller/login/login.rb +71 -0
- data/lib/forcast/controllers/controller/login_all.rb +1 -0
- data/lib/forcast/controllers/controller/paper_trail/paper_trail.rb +21 -0
- data/lib/forcast/controllers/controller/paper_trail_all.rb +1 -0
- data/lib/forcast/controllers/controller/relacion.rb +157 -0
- data/lib/forcast/controllers/controller/rule_engine/action_engine.rb +92 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/action_logs_controller.rb +12 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/actions_controller.rb +10 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/pollings_controller.rb +13 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/rule_logs_controller.rb +12 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/rules_controller.rb +19 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/webhooks_controller.rb +27 -0
- data/lib/forcast/controllers/controller/rule_engine/polling_engine.rb +76 -0
- data/lib/forcast/controllers/controller/rule_engine/rule_controller.rb +27 -0
- data/lib/forcast/controllers/controller/rule_engine/rule_engine.rb +88 -0
- data/lib/forcast/controllers/controller/rule_engine/webhook_engine.rb +38 -0
- data/lib/forcast/controllers/controller/rule_engine_all.rb +5 -0
- data/lib/forcast/jobs/all.rb +2 -0
- data/lib/forcast/jobs/jobs_assets.rb +25 -0
- data/lib/forcast/jobs/jobs_wrapper.rb +25 -0
- data/lib/forcast/jobs/rule_engine/jobs_actions.rb +73 -0
- data/lib/forcast/jobs/rule_engine/jobs_pollings.rb +77 -0
- data/lib/forcast/jobs/rule_engine/jobs_webhooks.rb +54 -0
- data/lib/forcast/migrations/0_migracion_general.rb +44 -0
- data/lib/forcast/migrations/paper_trail/versions.rb +61 -0
- data/lib/forcast/migrations/rule_engine/action_logs.rb +15 -0
- data/lib/forcast/migrations/rule_engine/actions.rb +15 -0
- data/lib/forcast/migrations/rule_engine/pollings.rb +26 -0
- data/lib/forcast/migrations/rule_engine/rule_logs.rb +22 -0
- data/lib/forcast/migrations/rule_engine/rules.rb +27 -0
- data/lib/forcast/migrations/rule_engine/webhooks.rb +25 -0
- data/lib/forcast/models/all.rb +8 -0
- data/lib/forcast/models/asociar.rb +74 -0
- data/lib/forcast/models/busqueda.rb +17 -0
- data/lib/forcast/models/login/authorization.rb +37 -0
- data/lib/forcast/models/login/json_web_token.rb +15 -0
- data/lib/forcast/models/login/login.rb +26 -0
- data/lib/forcast/models/login_all.rb +2 -0
- data/lib/forcast/models/meta.rb +19 -0
- data/lib/forcast/models/modelo.rb +125 -0
- data/lib/forcast/models/models/meta.rb +6 -0
- data/lib/forcast/models/paper_trail/paper_trail.rb +13 -0
- data/lib/forcast/models/paper_trail_all.rb +1 -0
- data/lib/forcast/models/permitirtodo.rb +57 -0
- data/lib/forcast/models/rule_engine/action_engine.rb +19 -0
- data/lib/forcast/models/rule_engine/models/action.rb +41 -0
- data/lib/forcast/models/rule_engine/models/action_log.rb +40 -0
- data/lib/forcast/models/rule_engine/models/polling.rb +43 -0
- data/lib/forcast/models/rule_engine/models/rule.rb +44 -0
- data/lib/forcast/models/rule_engine/models/rule_log.rb +39 -0
- data/lib/forcast/models/rule_engine/models/webhook.rb +43 -0
- data/lib/forcast/models/rule_engine/polling_engine.rb +113 -0
- data/lib/forcast/models/rule_engine/rule.rb +62 -0
- data/lib/forcast/models/rule_engine/rule_engine.rb +137 -0
- data/lib/forcast/models/rule_engine/rule_scope.rb +35 -0
- data/lib/forcast/models/rule_engine/webhook_engine.rb +55 -0
- data/lib/forcast/models/rule_engine_all.rb +6 -0
- data/lib/forcast/routes/concerns/asociar.rb +15 -0
- data/lib/forcast/routes/concerns/buscar.rb +6 -0
- data/lib/forcast/routes/concerns/definitor.rb +3 -0
- data/lib/forcast/routes/concerns/modelo.rb +6 -0
- data/lib/forcast/routes/database.rb +4 -0
- data/lib/forcast/routes/login.rb +4 -0
- data/lib/forcast/routes/paper_trail/paper_trail.rb +3 -0
- data/lib/forcast/routes/rule_engine/rule.rb +5 -0
- data/lib/forcast/tasks/.giosaveZr0hbs +21 -0
- data/lib/forcast/tasks/.keep +0 -0
- data/lib/forcast/tasks/all.rb +16 -0
- data/lib/forcast/tasks/diagramas.rake +32 -0
- data/lib/forcast/tasks/documentation/documentation.rb +100 -0
- data/lib/forcast/tasks/env.rake +10 -0
- data/lib/forcast/tasks/git.rake +22 -0
- data/lib/forcast/tasks/indy/indy.rb +28 -0
- data/lib/forcast/tasks/logs.rake +13 -0
- data/lib/forcast/tasks/process.rake +18 -0
- data/lib/forcast/tasks/schema.rake +17 -0
- data/lib/forcast/tasks/schema/recips/action.rb +18 -0
- data/lib/forcast/tasks/schema/recips/controller.rb +29 -0
- data/lib/forcast/tasks/schema/recips/definitor.rb +38 -0
- data/lib/forcast/tasks/schema/recips/model.rb +43 -0
- data/lib/forcast/tasks/schema/recips/project.rb +19 -0
- data/lib/forcast/tasks/schema/recips/route.rb +9 -0
- data/lib/forcast/tasks/schema/recips/tmp/controller.rb +0 -0
- data/lib/forcast/tasks/schema/recips/tmp/model.rb +0 -0
- data/lib/forcast/tasks/schema/recips/tmp/model/.keep +0 -0
- data/lib/forcast/tasks/schema/rule_engine/rule_engine.rb +98 -0
- data/lib/forcast/tasks/schema/schema.rb +346 -0
- data/lib/forcast/tasks/test.rake +129 -0
- data/lib/forcast/tasks/utils.rake +68 -0
- data/lib/forcast/tasks/yard.rake +18 -0
- data/lib/forcast/utils/all.rb +4 -0
- data/lib/forcast/utils/email.rb +49 -0
- data/lib/forcast/utils/email/forcast/utils/email/layout/default.html.erb +3 -0
- data/lib/forcast/utils/email/forcast/utils/email/layout/default.text.erb +5 -0
- data/lib/forcast/utils/firebase.rb +60 -0
- data/lib/forcast/utils/firebase_database.rb +117 -0
- data/lib/forcast/utils/measure.rb +44 -0
- data/lib/forcast/utils/qvo.rb +141 -0
- data/lib/forcast/utils/server.rb +296 -0
- data/lib/forcast/utils/telegram.rb +82 -0
- data/lib/forcast/utils/thing.rb +180 -0
- data/lib/forcast/version.rb +15 -0
- data/lib/lib/backup.rb +42 -0
- data/lib/lib/deploy.sh +40 -0
- data/lib/lib/forcast_servidor_rails.sh +11 -0
- data/lib/lib/pg_generator.sh +10 -0
- data/lib/lib/production.rb +66 -0
- data/lib/lib/production/production.rb +30 -0
- data/lib/lib/systemctl_maker.rb +88 -0
- data/lib/lib/update.rb +100 -0
- data/production.rb +31 -0
- metadata +301 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class Action::VARIABLEController < ApplicationController
|
|
2
|
+
def METODO
|
|
3
|
+
unless permitted_methods.include?(@type.to_s)
|
|
4
|
+
raise Forcast::Application::Error::General.new(t('error_type_not_allow'))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
send(@type)
|
|
8
|
+
json_response(@response, 'ok')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def example
|
|
12
|
+
@response = 'Im an example'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def permitted_methods
|
|
16
|
+
['example']
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class Api::VARIABLEController < ApplicationController
|
|
2
|
+
include Forcast::Application::Permitirtodo
|
|
3
|
+
include Forcast::Controller::Relacion
|
|
4
|
+
include Forcast::Controller::Asociar
|
|
5
|
+
include Forcast::Controller::Filtro
|
|
6
|
+
include Forcast::Controller::Busqueda
|
|
7
|
+
include Forcast::Controller::Definitor
|
|
8
|
+
# include Forcast::Controller::PaperTrail
|
|
9
|
+
# include Forcast::Controller::RuleController
|
|
10
|
+
include ProjectModule::ProjectVARIABLE
|
|
11
|
+
include DefinitorModule::DefinitorVARIABLE
|
|
12
|
+
|
|
13
|
+
# before_action :require_login!
|
|
14
|
+
# before_action :require_admin!, only: [:create, :update, :destroy]
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
# def params_permitidos_enviar
|
|
19
|
+
# []
|
|
20
|
+
# end
|
|
21
|
+
|
|
22
|
+
# def params_permitidos_update
|
|
23
|
+
# []
|
|
24
|
+
# end
|
|
25
|
+
|
|
26
|
+
# def params_permitidos_buscar
|
|
27
|
+
# []
|
|
28
|
+
# end
|
|
29
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module DefinitorModule
|
|
2
|
+
module DefinitorVARIABLE
|
|
3
|
+
def create_view_definitor
|
|
4
|
+
# {
|
|
5
|
+
# :name => :string
|
|
6
|
+
# }
|
|
7
|
+
all_definitions
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def show_view_definitor
|
|
11
|
+
# {
|
|
12
|
+
# :name => :string
|
|
13
|
+
# }
|
|
14
|
+
all_definitions
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def put_or_patch_view_definitor
|
|
18
|
+
# {
|
|
19
|
+
# :name => :string
|
|
20
|
+
# }
|
|
21
|
+
all_definitions
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def delete_view_definitor
|
|
25
|
+
# {
|
|
26
|
+
# :name => :string
|
|
27
|
+
# }
|
|
28
|
+
all_definitions
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def webhook_view_definitor
|
|
32
|
+
# {
|
|
33
|
+
# :name => :string
|
|
34
|
+
# }
|
|
35
|
+
all_definitions
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
class VARIABLE < ApplicationRecord
|
|
2
|
+
include Forcast::Model::Modelo
|
|
3
|
+
include Forcast::Model::Permitirtodo
|
|
4
|
+
include Forcast::Model::Busqueda
|
|
5
|
+
include Forcast::Model::Asociar
|
|
6
|
+
# include Forcast::Model::Login
|
|
7
|
+
# include Forcast::Model::RuleEngine
|
|
8
|
+
# include Forcast::Model::PaperTrail
|
|
9
|
+
|
|
10
|
+
def init(params)
|
|
11
|
+
# self.password=(params['password_hash'])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.parametros_necesario_create
|
|
15
|
+
[]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.parametros_a_validar_modelo_create
|
|
19
|
+
# [{:param => 'tipo_valor', :validacion => 'validaciones_tipo_valor', :error => :bad_param_not_allow_type}]
|
|
20
|
+
[]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.parametros_a_validar_modelo_update
|
|
24
|
+
# [{:param => 'tipo_valor', :validacion => 'validaciones_tipo_valor', :error => :bad_param_not_allow_type}]
|
|
25
|
+
[]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.parametros_permitido_asociar
|
|
29
|
+
[]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.parametros_a_comprobar_si_existen_create
|
|
33
|
+
[]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.parametros_a_comprobar_si_existen_update
|
|
37
|
+
[]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# def self.validaciones_tipo_valor(valor)
|
|
41
|
+
# return true unless ['string','integer','decimal'].include?(valor)
|
|
42
|
+
# end
|
|
43
|
+
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
def init_rule_engine
|
|
2
|
+
@routes = ["webhook","action","action_log","polling","rule","rule_log"]
|
|
3
|
+
cp_models_rule_engine
|
|
4
|
+
cp_controllers_rule_engine
|
|
5
|
+
cp_routes_rule_engine
|
|
6
|
+
cp_migrations_rule_engine
|
|
7
|
+
cp_jobs_rule_engine
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def cp_models_rule_engine
|
|
11
|
+
@routes.each do |route|
|
|
12
|
+
path = File.expand_path("../../../../models/rule_engine/models/#{route}.rb", __FILE__)
|
|
13
|
+
system("mkdir -p #{@root}/app/models/rule_engine")
|
|
14
|
+
system("cp #{path} #{@root}/app/models/rule_engine")
|
|
15
|
+
end
|
|
16
|
+
puts "DONE MODELS RULE ENGINE...."
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def cp_controllers_rule_engine
|
|
20
|
+
@routes.each do |route|
|
|
21
|
+
path = File.expand_path("../../../../controllers/controller/rule_engine/controllers/#{route.pluralize}_controller.rb", __FILE__)
|
|
22
|
+
system("mkdir -p #{@root}/app/controllers/api/rule_engine")
|
|
23
|
+
system("cp #{path} #{@root}/app/controllers/api/rule_engine")
|
|
24
|
+
end
|
|
25
|
+
puts "DONE CONTROLLERS RULE ENGINE...."
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def cp_routes_rule_engine
|
|
29
|
+
@routes.each do |route|
|
|
30
|
+
path = File.expand_path("../../recips/route.rb", __FILE__)
|
|
31
|
+
system("mkdir -p #{@root}/config/routes/rule_engine")
|
|
32
|
+
system("cp #{path} #{@root}/config/routes/rule_engine/#{route.pluralize}.rb")
|
|
33
|
+
end
|
|
34
|
+
write_draw_routes
|
|
35
|
+
puts "DONE ROUTES RULE ENGINE...."
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def cp_migrations_rule_engine
|
|
39
|
+
@routes.each do |route|
|
|
40
|
+
path = File.expand_path("../../../../migrations/rule_engine/#{route.pluralize}.rb", __FILE__)
|
|
41
|
+
system("mkdir -p #{@root}/db/migrate/tables/rule_engine")
|
|
42
|
+
system("cp #{path} #{@root}/db/migrate/tables/rule_engine")
|
|
43
|
+
end
|
|
44
|
+
puts "DONE MIGRATIONS RULE ENGINE...."
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def cp_jobs_rule_engine
|
|
48
|
+
routes = ["pollings","webhooks","actions"]
|
|
49
|
+
routes.each do |route|
|
|
50
|
+
path = File.expand_path("../../../../jobs/rule_engine/jobs_#{route}.rb", __FILE__)
|
|
51
|
+
system("mkdir -p #{@root}/app/jobs/concerns/rule_engine")
|
|
52
|
+
system("cp #{path} #{@root}/app/jobs/concerns/rule_engine")
|
|
53
|
+
end
|
|
54
|
+
puts "DONE JOBS RULE ENGINE...."
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def write_at(fname, at_line, sdat)
|
|
58
|
+
open(fname, 'r+') do |f|
|
|
59
|
+
while (at_line-=1) > 0 # read up to the line you want to write after
|
|
60
|
+
f.readline
|
|
61
|
+
end
|
|
62
|
+
pos = f.pos # save your position in the file
|
|
63
|
+
rest = f.read # save the rest of the file
|
|
64
|
+
f.seek pos # go back to the old position
|
|
65
|
+
f.write sdat # write new data
|
|
66
|
+
f.write rest # write rest of file
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def write_draw_routes
|
|
71
|
+
path = "#{@root}/config/routes_rule_engine.txt"
|
|
72
|
+
line = "ENGINE ROUTES SCHEMA\n"
|
|
73
|
+
line += "draw :action_logs do\n"
|
|
74
|
+
line += "end\n"
|
|
75
|
+
line += "draw :rule_logs do\n"
|
|
76
|
+
line += "end\n"
|
|
77
|
+
line += "draw :actions do\n"
|
|
78
|
+
line += " draw :action_logs do\n"
|
|
79
|
+
line += " end\n"
|
|
80
|
+
line += "end\n"
|
|
81
|
+
line += "draw :pollings do\n"
|
|
82
|
+
line += "end\n"
|
|
83
|
+
line += "draw :webhooks do\n"
|
|
84
|
+
line += "end\n"
|
|
85
|
+
line += "draw :rules do\n"
|
|
86
|
+
line += " draw :actions do\n"
|
|
87
|
+
line += " draw :action_logs do\n"
|
|
88
|
+
line += " end\n"
|
|
89
|
+
line += " end\n"
|
|
90
|
+
line += " draw :pollings do\n"
|
|
91
|
+
line += " end\n"
|
|
92
|
+
line += " draw :webhooks do\n"
|
|
93
|
+
line += " end\n"
|
|
94
|
+
line += " draw :rule_logs do\n"
|
|
95
|
+
line += " end\n"
|
|
96
|
+
line += "end\n"
|
|
97
|
+
File.write(path,line)
|
|
98
|
+
end
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
# use the regex-based implementation
|
|
2
|
+
require 'json'
|
|
3
|
+
class Pretender
|
|
4
|
+
def self.parse(filename)
|
|
5
|
+
require filename
|
|
6
|
+
ActiveRecord::Schema.schema
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
module ActiveRecord
|
|
10
|
+
class Schema
|
|
11
|
+
def create_table(table_name, options={}, &block)
|
|
12
|
+
table = Table.new(table_name)
|
|
13
|
+
yield table if block_given?
|
|
14
|
+
self.class.add_table(table.name, table.columns)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def method_missing(*args)
|
|
18
|
+
# ignore add_index, etc.
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.define(*args, &block)
|
|
22
|
+
new.instance_eval(&block)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.add_table(table_name, columns)
|
|
26
|
+
@schema ||= {}
|
|
27
|
+
@schema[table_name] = columns
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.schema
|
|
31
|
+
@schema || {}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class Table
|
|
36
|
+
attr_reader :name, :columns
|
|
37
|
+
|
|
38
|
+
def initialize(name)
|
|
39
|
+
@name = name
|
|
40
|
+
@columns = []
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def method_missing(data_type, *column_names_and_options)
|
|
44
|
+
column_names_and_options.pop if column_names_and_options.last.is_a?(Hash)
|
|
45
|
+
@columns += column_names_and_options
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def init_schema
|
|
51
|
+
path = "#{@root}/db/schema.rb"
|
|
52
|
+
object = Pretender.parse("#{path}")
|
|
53
|
+
generate_folders
|
|
54
|
+
generate_routes(object)
|
|
55
|
+
generate_controllers(object)
|
|
56
|
+
generate_actions(object)
|
|
57
|
+
generate_models(object)
|
|
58
|
+
generate_definitor(object)
|
|
59
|
+
generate_projects(object)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def generate_folders
|
|
63
|
+
system("mkdir -p #{@root}/config/routes/test")
|
|
64
|
+
system("mkdir -p #{@root}/app/models/test")
|
|
65
|
+
system("mkdir -p #{@root}/app/controllers/api/test")
|
|
66
|
+
system("mkdir -p #{@root}/app/controllers/action/test")
|
|
67
|
+
system("mkdir -p #{@root}/app/controllers/concerns/project_module/test")
|
|
68
|
+
system("mkdir -p #{@root}/app/controllers/concerns/definitor_module/test")
|
|
69
|
+
system("mkdir -p #{@root}/app/controllers/concerns/serializer_module/test")
|
|
70
|
+
puts "DONE MAKING FOLDERS...."
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def generate_routes(object)
|
|
74
|
+
routes = object.keys
|
|
75
|
+
path = File.dirname(__FILE__)+"/recips/route.rb"
|
|
76
|
+
routes.each do |route|
|
|
77
|
+
system("cp #{path} #{@root}/config/routes/test/#{route}.rb")
|
|
78
|
+
end
|
|
79
|
+
puts "DONE MAKING ROUTES...."
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def generate_controllers(object)
|
|
83
|
+
routes = object.keys
|
|
84
|
+
path = File.dirname(__FILE__)+"/recips/controller.rb"
|
|
85
|
+
tmp_path = File.dirname(__FILE__)+"/recips/tmp/controller.rb"
|
|
86
|
+
routes.each do |route|
|
|
87
|
+
text = File.read(path)
|
|
88
|
+
new_contents = text.gsub("VARIABLE", "#{route.classify.pluralize}")
|
|
89
|
+
File.open(tmp_path, "w") {|file| file.puts new_contents }
|
|
90
|
+
system("cp #{tmp_path} #{@root}/app/controllers/api/test/#{route}_controller.rb")
|
|
91
|
+
end
|
|
92
|
+
puts "DONE MAKING API CONTROLLERS...."
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def generate_actions(object)
|
|
96
|
+
routes = object.keys
|
|
97
|
+
path = File.dirname(__FILE__)+"/recips/action.rb"
|
|
98
|
+
tmp_path = File.dirname(__FILE__)+"/recips/tmp/action.rb"
|
|
99
|
+
routes.each do |route|
|
|
100
|
+
text = File.read(path)
|
|
101
|
+
new_contents = text.gsub("VARIABLE", "#{route.classify.pluralize}")
|
|
102
|
+
new_contents = new_contents.gsub("METODO", "#{route}")
|
|
103
|
+
File.open(tmp_path, "w") {|file| file.puts new_contents }
|
|
104
|
+
system("cp #{tmp_path} #{@root}/app/controllers/action/test/#{route}_controller.rb")
|
|
105
|
+
end
|
|
106
|
+
puts "DONE MAKING ACTION CONTROLLERS...."
|
|
107
|
+
routes_generate_action(routes)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def routes_generate_action(routes)
|
|
111
|
+
line = ""
|
|
112
|
+
routes.each do |route|
|
|
113
|
+
line += "post '/#{route}' => '#{route}##{route}'\n"
|
|
114
|
+
end
|
|
115
|
+
path = "#{@root}/config/routes_action_parse.txt"
|
|
116
|
+
File.write(path,line)
|
|
117
|
+
puts "DONE MAKING ACTION ROUTES...."
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def generate_definitor(object)
|
|
121
|
+
routes = object.keys
|
|
122
|
+
path = File.dirname(__FILE__)+"/recips/definitor.rb"
|
|
123
|
+
tmp_path = File.dirname(__FILE__)+"/recips/tmp/definitor.rb"
|
|
124
|
+
routes.each do |route|
|
|
125
|
+
text = File.read(path)
|
|
126
|
+
new_contents = text.gsub("VARIABLE", "#{route.classify.pluralize}")
|
|
127
|
+
File.open(tmp_path, "w") {|file| file.puts new_contents }
|
|
128
|
+
system("cp #{tmp_path} #{@root}/app/controllers/concerns/definitor_module/test/definitor_#{route}.rb")
|
|
129
|
+
end
|
|
130
|
+
puts "DONE MAKING DEFINITORS...."
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def generate_projects(object)
|
|
134
|
+
routes = object.keys
|
|
135
|
+
path = File.dirname(__FILE__)+"/recips/project.rb"
|
|
136
|
+
tmp_path = File.dirname(__FILE__)+"/recips/tmp/project.rb"
|
|
137
|
+
routes.each do |route|
|
|
138
|
+
text = File.read(path)
|
|
139
|
+
new_contents = text.gsub("VARIABLE", "#{route.classify.pluralize}")
|
|
140
|
+
File.open(tmp_path, "w") {|file| file.puts new_contents }
|
|
141
|
+
system("cp #{tmp_path} #{@root}/app/controllers/concerns/project_module/test/project_#{route}.rb")
|
|
142
|
+
end
|
|
143
|
+
puts "DONE MAKING PROJECTS...."
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def generate_models(object)
|
|
147
|
+
routes = object.keys
|
|
148
|
+
path = File.dirname(__FILE__)+"/recips/model.rb"
|
|
149
|
+
@array_has_many = []
|
|
150
|
+
routes.each do |route|
|
|
151
|
+
attributes = object[route]
|
|
152
|
+
route = route.singularize
|
|
153
|
+
tmp_path = File.dirname(__FILE__)+"/recips/tmp/model/#{route}.rb"
|
|
154
|
+
text = File.read(path)
|
|
155
|
+
new_contents = text.gsub("VARIABLE", "#{route.capitalize.classify}")
|
|
156
|
+
system("touch #{tmp_path}")
|
|
157
|
+
File.open(tmp_path, "w") {|file| file.puts new_contents }
|
|
158
|
+
size = attributes.size.to_i - 1
|
|
159
|
+
relations = size - attributes.index("updated_at").to_i
|
|
160
|
+
relations = attributes.pop(relations)
|
|
161
|
+
relations.each_with_index do |relation,index|
|
|
162
|
+
write_belongs_to(tmp_path,route,relation.to_s,index)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
write_has_many
|
|
166
|
+
cp_models(routes)
|
|
167
|
+
routes_schema_parse(object)
|
|
168
|
+
puts "DONE MAKING MODELS...."
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def write_at(fname, at_line, sdat)
|
|
172
|
+
open(fname, 'r+') do |f|
|
|
173
|
+
while (at_line-=1) > 0 # read up to the line you want to write after
|
|
174
|
+
f.readline
|
|
175
|
+
end
|
|
176
|
+
pos = f.pos # save your position in the file
|
|
177
|
+
rest = f.read # save the rest of the file
|
|
178
|
+
f.seek pos # go back to the old position
|
|
179
|
+
f.write sdat # write new data
|
|
180
|
+
f.write rest # write rest of file
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def write_belongs_to(tmp_path,origin,relation,index)
|
|
185
|
+
relation = relation.gsub("_id","").gsub("[","").gsub("]","").gsub('"',"")
|
|
186
|
+
write_at(tmp_path,index.to_i+3," belongs_to :#{relation}\n")
|
|
187
|
+
@array_has_many.push({:relation => relation, :origin => origin})
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def write_has_many
|
|
191
|
+
@array_has_many.each do |has|
|
|
192
|
+
relation = has[:relation]
|
|
193
|
+
origin = has[:origin]
|
|
194
|
+
tmp_path = File.dirname(__FILE__)+"/recips/tmp/model/#{relation}.rb"
|
|
195
|
+
write_at(tmp_path,2," has_many :#{origin}\n")
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def cp_models(files)
|
|
200
|
+
files.each do |file|
|
|
201
|
+
file = file.singularize
|
|
202
|
+
tmp_path = File.dirname(__FILE__)+"/recips/tmp/model/#{file}.rb"
|
|
203
|
+
system("cp #{tmp_path} #{@root}/app/models/test/#{file}.rb")
|
|
204
|
+
system("rm #{tmp_path}")
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def routes_schema_parse(object)
|
|
209
|
+
object = complete_object(object,@array_has_many)
|
|
210
|
+
structure = create_draw_structure(object)
|
|
211
|
+
#puts "STRUCTURED"
|
|
212
|
+
#puts structure
|
|
213
|
+
line = "GENERAL ROUTES SCHEMA\n"
|
|
214
|
+
line += draw_complex_structure(structure)
|
|
215
|
+
#puts line
|
|
216
|
+
path = "#{@root}/config/routes_schema_parse.txt"
|
|
217
|
+
File.write(path,line)
|
|
218
|
+
puts "DONE MAKING DRAW ROUTES...."
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def complete_object(object,array)
|
|
222
|
+
new_array = []
|
|
223
|
+
object.keys.each do |obj|
|
|
224
|
+
array.push({:relation => obj.singularize, :origin => ''})
|
|
225
|
+
end
|
|
226
|
+
# array.push({:relation => 'polling', :origin => 'administrador'})
|
|
227
|
+
# array.push({:relation => 'usuario', :origin => 'recinto'})
|
|
228
|
+
# array.push({:relation => 'recinto', :origin => 'casa'})
|
|
229
|
+
# array.push({:relation => 'recinto', :origin => ''})
|
|
230
|
+
array.map { |e| e[:origin] = {:relation => e[:origin], :has_many => []} }
|
|
231
|
+
keys = object.keys
|
|
232
|
+
#keys = object.keys.push('recintos')
|
|
233
|
+
keys.each do |key|
|
|
234
|
+
key = key.singularize
|
|
235
|
+
merge = array.select {|e| e[:relation] == key}
|
|
236
|
+
ar = {:relation => key, :has_many => []}
|
|
237
|
+
merge.each do |me|
|
|
238
|
+
#next if me[:origin][:relation].blank?
|
|
239
|
+
ar[:has_many].push(me[:origin])
|
|
240
|
+
end
|
|
241
|
+
new_array.push(ar)
|
|
242
|
+
end
|
|
243
|
+
#puts new_array
|
|
244
|
+
return new_array
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def create_draw_structure(array)
|
|
248
|
+
#puts "create_draw_structure"
|
|
249
|
+
array_init = array
|
|
250
|
+
new_array = array_init.each do |rel|
|
|
251
|
+
deep_draw_structure(array_init,rel)
|
|
252
|
+
end
|
|
253
|
+
return new_array
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def deep_draw_structure(array,rel)
|
|
257
|
+
return if array.empty?
|
|
258
|
+
array.each do |arr|
|
|
259
|
+
next if arr[:relation] == rel[:relation]
|
|
260
|
+
arr[:has_many].each do |e|
|
|
261
|
+
if e[:relation] == ""
|
|
262
|
+
arr[:has_many].delete(e)
|
|
263
|
+
end
|
|
264
|
+
if e[:relation] == [rel[:relation]] || e[:relation] == rel[:relation]
|
|
265
|
+
e[:has_many] = rel[:has_many]
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
array = arr[:has_many].select {|e| e[:relation] != ""}
|
|
269
|
+
deep_draw_structure(array,rel)
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def draw_method_action(action,space)
|
|
274
|
+
#puts 'draw_method_action'
|
|
275
|
+
line = space+"draw :#{action.pluralize} do\n"
|
|
276
|
+
return line
|
|
277
|
+
end
|
|
278
|
+
def draw_method_end(space)
|
|
279
|
+
line = space+"end\n"
|
|
280
|
+
return line
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
def draw_simple_structure(space = "",object)
|
|
284
|
+
line = ""
|
|
285
|
+
object.keys.each_with_index do |key|
|
|
286
|
+
line += draw_method_action(key,space)
|
|
287
|
+
space = space+" "
|
|
288
|
+
end
|
|
289
|
+
object.keys.each_with_index do |key|
|
|
290
|
+
space = space[0...-2]
|
|
291
|
+
line += draw_method_end(space)
|
|
292
|
+
end
|
|
293
|
+
return line
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def draw_complex_structure(line = "",space = "",object)
|
|
297
|
+
object.each_with_index do |key|
|
|
298
|
+
line = draw_deep_complex_structure(line,[key],space)
|
|
299
|
+
end
|
|
300
|
+
return line
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
def draw_deep_complex_structure(line,array,space_int)
|
|
304
|
+
return if array.empty?
|
|
305
|
+
#puts 'draw_deep_complex_structure'
|
|
306
|
+
array.each do |key|
|
|
307
|
+
line += draw_method_action(key[:relation],space_int)
|
|
308
|
+
space_int = space_int+" "
|
|
309
|
+
line = draw_draw_deep_complex_structure(line,key[:has_many],space_int)
|
|
310
|
+
space_end = space_int[0...-2]
|
|
311
|
+
line += draw_method_end(space_end) unless key[:has_many].empty?
|
|
312
|
+
end
|
|
313
|
+
return line
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
def draw_draw_deep_complex_structure(relation = '',line,array,space_int)
|
|
317
|
+
if array.empty?
|
|
318
|
+
space_int = space_int[0...-2]
|
|
319
|
+
line += draw_method_end(space_int)
|
|
320
|
+
return line
|
|
321
|
+
end
|
|
322
|
+
#puts 'draw_draw_deep_complex_structure'
|
|
323
|
+
array.each do |has_many|
|
|
324
|
+
line += draw_method_action(has_many[:relation],space_int)
|
|
325
|
+
space = space_int+" "
|
|
326
|
+
line = draw_draw_draw_deep_complex_structure(line,has_many[:has_many],space)
|
|
327
|
+
end
|
|
328
|
+
return line
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
def draw_draw_draw_deep_complex_structure(relation = '',line,array,space_int)
|
|
332
|
+
if array.empty?
|
|
333
|
+
space_int = space_int[0...-2]
|
|
334
|
+
line += draw_method_end(space_int)
|
|
335
|
+
return line
|
|
336
|
+
end
|
|
337
|
+
#puts 'draw_draw_draw_deep_complex_structure'
|
|
338
|
+
array.each do |has_many|
|
|
339
|
+
line += draw_method_action(has_many[:relation],space_int)
|
|
340
|
+
space = space_int+" "
|
|
341
|
+
line = draw_draw_draw_deep_complex_structure(line,has_many[:has_many],space)
|
|
342
|
+
space_end = space_int[0...-2]
|
|
343
|
+
line += draw_method_end(space_end)
|
|
344
|
+
end
|
|
345
|
+
return line
|
|
346
|
+
end
|