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.
21 22 23 |
# File 'lib/true-web.rb', line 21 def application_name @application_name end |
#controller ⇒ Object
Returns the value of attribute controller.
21 22 23 |
# File 'lib/true-web.rb', line 21 def controller @controller end |
#named_routes ⇒ Object Also known as: uris
Returns the value of attribute named_routes.
21 22 23 |
# File 'lib/true-web.rb', line 21 def named_routes @named_routes end |
#root_dir ⇒ Object
Returns the value of attribute root_dir.
21 22 23 |
# File 'lib/true-web.rb', line 21 def root_dir @root_dir end |
#stderr_dir ⇒ Object
Returns the value of attribute stderr_dir.
21 22 23 |
# File 'lib/true-web.rb', line 21 def stderr_dir @stderr_dir end |
#stdout_dir ⇒ Object
Returns the value of attribute stdout_dir.
21 22 23 |
# File 'lib/true-web.rb', line 21 def stdout_dir @stdout_dir end |
#views_class ⇒ Object
Returns the value of attribute views_class.
21 22 23 |
# File 'lib/true-web.rb', line 21 def views_class @views_class end |
Instance Method Details
#app ⇒ Object
38 39 40 41 42 |
# File 'lib/true-web.rb', line 38 def app @app ||= Rack::Builder.new do run controller end.to_app end |
#init(params = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/true-web.rb', line 27 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
87 88 89 |
# File 'lib/true-web.rb', line 87 def lib_dir File.join(root_dir, "lib") end |
#plugins ⇒ Object
83 84 85 |
# File 'lib/true-web.rb', line 83 def plugins @plugins ||= ::TrueWeb::Plugins::Set.new(self) end |
#register_service(path, &block) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/true-web.rb', line 44 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
118 119 120 121 122 123 |
# File 'lib/true-web.rb', line 118 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
52 53 54 55 56 |
# File 'lib/true-web.rb', line 52 def service_dirs services.map do |service| service.root_dir end end |
#service_subdirectory_dirs(relative_directory) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/true-web.rb', line 103 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
58 59 60 |
# File 'lib/true-web.rb', line 58 def services @services ||= [] end |
#services_by_root_dir ⇒ Object
68 69 70 71 72 73 |
# File 'lib/true-web.rb', line 68 def services_by_root_dir services.inject({}) do |memo, service| memo[service.root_dir] = service memo end end |
#services_by_url_prefix ⇒ Object
62 63 64 65 66 |
# File 'lib/true-web.rb', line 62 def services_by_url_prefix services.group_by do |service| service.url_prefix end end |
#services_dir ⇒ Object
99 100 101 |
# File 'lib/true-web.rb', line 99 def services_dir File.join(root_dir, "services") end |
#stderr_logger ⇒ Object
75 76 77 |
# File 'lib/true-web.rb', line 75 def stderr_logger @stderr_logger ||= Logger.new(stderr_dir) end |
#stdout_logger ⇒ Object
79 80 81 |
# File 'lib/true-web.rb', line 79 def stdout_logger @stdout_logger ||= Logger.new(stdout_dir) end |
#stylesheets_dirs ⇒ Object
91 92 93 |
# File 'lib/true-web.rb', line 91 def stylesheets_dirs service_subdirectory_dirs "app/stylesheets" end |
#vendor_dir ⇒ Object
95 96 97 |
# File 'lib/true-web.rb', line 95 def vendor_dir File.join(root_dir, "vendor") end |