Module: TrueWeb::ClassMethods
- Includes:
- EnvMethods
- Defined in:
- lib/true-web.rb
Instance Attribute Summary collapse
-
#application_name ⇒ Object
Returns the value of attribute application_name.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#named_routes ⇒ Object
(also: #uris)
Returns the value of attribute named_routes.
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
-
#stderr_dir ⇒ Object
Returns the value of attribute stderr_dir.
-
#stdout_dir ⇒ Object
Returns the value of attribute stdout_dir.
-
#views_class ⇒ Object
Returns the value of attribute views_class.
Instance Method Summary collapse
- #app ⇒ Object
- #init(params = {}) ⇒ Object
- #lib_dir ⇒ Object
- #plugins ⇒ Object
- #register_service(path, &block) ⇒ Object
- #remove_generated_files ⇒ Object
- #service_dirs ⇒ Object
- #service_subdirectory_dirs(relative_directory) ⇒ Object
- #services ⇒ Object
- #services_by_root_dir ⇒ Object
- #services_by_url_prefix ⇒ Object
- #services_dir ⇒ Object
- #stderr_logger ⇒ Object
- #stdout_logger ⇒ Object
- #stylesheets_dirs ⇒ Object
- #vendor_dir ⇒ Object
Methods included from EnvMethods
Instance Attribute Details
#application_name ⇒ Object
Returns the value of attribute application_name.
22 23 24 |
# File 'lib/true-web.rb', line 22 def application_name @application_name end |
#controller ⇒ Object
Returns the value of attribute controller.
22 23 24 |
# File 'lib/true-web.rb', line 22 def controller @controller end |
#named_routes ⇒ Object Also known as: uris
Returns the value of attribute named_routes.
22 23 24 |
# File 'lib/true-web.rb', line 22 def named_routes @named_routes end |
#root_dir ⇒ Object
Returns the value of attribute root_dir.
22 23 24 |
# File 'lib/true-web.rb', line 22 def root_dir @root_dir end |
#stderr_dir ⇒ Object
Returns the value of attribute stderr_dir.
22 23 24 |
# File 'lib/true-web.rb', line 22 def stderr_dir @stderr_dir end |
#stdout_dir ⇒ Object
Returns the value of attribute stdout_dir.
22 23 24 |
# File 'lib/true-web.rb', line 22 def stdout_dir @stdout_dir end |
#views_class ⇒ Object
Returns the value of attribute views_class.
22 23 24 |
# File 'lib/true-web.rb', line 22 def views_class @views_class end |
Instance Method Details
#app ⇒ Object
39 40 41 42 43 |
# File 'lib/true-web.rb', line 39 def app @app ||= Rack::Builder.new do run controller end.to_app end |
#init(params = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/true-web.rb', line 28 def init(params={}) self.controller = params[:controller] || raise(ArgumentError, "You must provide an :controller param") self.application_name = params[:application_name] || raise(ArgumentError, "You must provide an :application_name param") self.root_dir = params[:root_dir] || raise(ArgumentError, "You must provide a :root_dir param") self.named_routes = params[:named_routes] || raise(ArgumentError, "You must provide a :named_routes param") self.views_class = params[:views_class] || raise(ArgumentError, "You must provide a :views_class param") self.controller.config = self plugins.init end |
#lib_dir ⇒ Object
88 89 90 |
# File 'lib/true-web.rb', line 88 def lib_dir File.join(root_dir, "lib") end |
#plugins ⇒ Object
84 85 86 |
# File 'lib/true-web.rb', line 84 def plugins @plugins ||= ::TrueWeb::Plugins::Set.new(self) end |
#register_service(path, &block) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/true-web.rb', line 45 def register_service(path, &block) unless service_dirs.include?(path) service = Service.new(path) services << service service.init(&block) end end |
#remove_generated_files ⇒ Object
119 120 121 122 123 124 |
# File 'lib/true-web.rb', line 119 def remove_generated_files Dir["#{root_dir}/**/public/**/*.generated"].each do |generated_path| FileUtils.rm_f(File.join(File.dirname(generated_path), File.basename(generated_path, ".generated"))) FileUtils.rm_f(generated_path) end end |
#service_dirs ⇒ Object
53 54 55 56 57 |
# File 'lib/true-web.rb', line 53 def service_dirs services.map do |service| service.root_dir end end |
#service_subdirectory_dirs(relative_directory) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/true-web.rb', line 104 def service_subdirectory_dirs(relative_directory) service_dirs.flatten.map do |service_path| full_path = File.join(service_path, relative_directory) full_path if File.directory?(full_path) end.compact end |
#services ⇒ Object
59 60 61 |
# File 'lib/true-web.rb', line 59 def services @services ||= [] end |
#services_by_root_dir ⇒ Object
69 70 71 72 73 74 |
# File 'lib/true-web.rb', line 69 def services_by_root_dir services.inject({}) do |memo, service| memo[service.root_dir] = service memo end end |
#services_by_url_prefix ⇒ Object
63 64 65 66 67 |
# File 'lib/true-web.rb', line 63 def services_by_url_prefix services.group_by do |service| service.url_prefix end end |
#services_dir ⇒ Object
100 101 102 |
# File 'lib/true-web.rb', line 100 def services_dir File.join(root_dir, "services") end |
#stderr_logger ⇒ Object
76 77 78 |
# File 'lib/true-web.rb', line 76 def stderr_logger @stderr_logger ||= Logger.new(stderr_dir) end |
#stdout_logger ⇒ Object
80 81 82 |
# File 'lib/true-web.rb', line 80 def stdout_logger @stdout_logger ||= Logger.new(stdout_dir) end |
#stylesheets_dirs ⇒ Object
92 93 94 |
# File 'lib/true-web.rb', line 92 def stylesheets_dirs service_subdirectory_dirs "app/stylesheets" end |
#vendor_dir ⇒ Object
96 97 98 |
# File 'lib/true-web.rb', line 96 def vendor_dir File.join(root_dir, "vendor") end |