Class: Stratagem::ModelBuilder
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#parsed_controllers ⇒ Object
readonly
Returns the value of attribute parsed_controllers.
-
#parsed_models ⇒ Object
readonly
Returns the value of attribute parsed_models.
Instance Method Summary collapse
-
#initialize ⇒ ModelBuilder
constructor
A new instance of ModelBuilder.
- #load_files(base_dir, path = [], file_list = []) ⇒ Object
- #load_models ⇒ Object
- #load_plugins ⇒ Object
- #load_public ⇒ Object
- #load_routes ⇒ Object
- #load_template_paths ⇒ Object
- #log(msg) ⇒ Object
- #print_errors ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ ModelBuilder
Returns a new instance of ModelBuilder.
5 6 7 |
# File 'lib/stratagem/model_builder.rb', line 5 def initialize @model = Stratagem::Model::Application.instance end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/stratagem/model_builder.rb', line 3 def model @model end |
#parsed_controllers ⇒ Object (readonly)
Returns the value of attribute parsed_controllers.
3 4 5 |
# File 'lib/stratagem/model_builder.rb', line 3 def parsed_controllers @parsed_controllers end |
#parsed_models ⇒ Object (readonly)
Returns the value of attribute parsed_models.
3 4 5 |
# File 'lib/stratagem/model_builder.rb', line 3 def parsed_models @parsed_models end |
Instance Method Details
#load_files(base_dir, path = [], file_list = []) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/stratagem/model_builder.rb', line 117 def load_files(base_dir,path=[],file_list=[]) dir = File.join(base_dir, *path) files = Dir.new(dir).entries files.each do |file| next if file =~ /^\./ if (File.directory?(File.join(dir, file))) load_files(base_dir, path + [file], file_list) else file_path = File.join(path, file) file_list << file_path end end file_list end |
#load_models ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/stratagem/model_builder.rb', line 46 def load_models() @model.models.clear # load files into classes log "loading models" root = File.join(RAILS_ROOT, 'app','models') load_files(File.join(root)).map {|model| models = Stratagem::Model::Component::Model.load_all(File.join(root, model)) models.each do |c| log "\t#{c.klass.name} loaded from #{model}" end @model.models << models } log "" end |
#load_plugins ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/stratagem/model_builder.rb', line 35 def load_plugins() @model.plugins.clear if (Stratagem.rails_3?) @model.plugins << Rails.application.railties.plugins else loader = Rails::Plugin::Loader.new(Rails::Initializer.new(Rails::Configuration.new)) loader.load_plugins @model.plugins << loader.initializer.loaded_plugins end end |
#load_public ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/stratagem/model_builder.rb', line 62 def load_public @model.static_files.clear log "loading static files" Dir[File.join(RAILS_ROOT, 'public', '**', '*.html')].each {|static| static.gsub!(RAILS_ROOT, '').gsub!(/^\/public\//, '') @model.static_files << Stratagem::Model::Component::StaticFile.new(static) log "\t#{static}" } log "" end |
#load_routes ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/stratagem/model_builder.rb', line 86 def load_routes @model.routes.clear @model.controllers.clear log 'loading routes' root = File.join(RAILS_ROOT, 'app','controllers') ActionController::Routing::Routes.routes.each {|route| route_container = Stratagem::Model::Component::Route.new(route) @model.routes << route_container p route.requirements begin puts "loading controller - #{route_container.controller_name}" controller_class = route_container.controller_name.constantize filename = File.join(root, "#{route_container.controller_path}_controller.rb") if (File.exists?(filename)) parse_tree = RedParse.new(File.read(filename)).parse else parse_tree = nil end controller_container = Stratagem::Model::Component::Controller.new(filename, parse_tree, controller_class) configure_route(route_container, controller_container) @model.controllers << controller_container rescue log "\tinvalid route #{route.to_s} - #{$!.message}" @model.routes.invalid << Stratagem::Model::Component::Route.new(route) end } log "" end |
#load_template_paths ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/stratagem/model_builder.rb', line 74 def load_template_paths @model.views.clear log "loading templates" root = File.join(RAILS_ROOT, 'app','views') load_files(root).map {|template| @model.views << Stratagem::Model::Component::View.new(template) log "\t#{template}" } log "" end |
#log(msg) ⇒ Object
21 22 23 |
# File 'lib/stratagem/model_builder.rb', line 21 def log(msg) Stratagem.logger.debug msg end |
#print_errors ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/stratagem/model_builder.rb', line 25 def print_errors @model.routes.invalid.each {|route| puts "route: #{route.route.to_s} is invalid" } @model.controllers.missing.each {|controller, routes| puts "controller: #{controller}, with #{routes.size} routes is missing" } end |
#run ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/stratagem/model_builder.rb', line 9 def run load_plugins load_public load_template_paths load_routes load_models print_errors @model end |