Module: TrueWeb::ClassMethods

Includes:
EnvMethods
Defined in:
lib/true-web.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EnvMethods

#development?, #rack_env

Instance Attribute Details

#application_nameObject

Returns the value of attribute application_name.



21
22
23
# File 'lib/true-web.rb', line 21

def application_name
  @application_name
end

#controllerObject

Returns the value of attribute controller.



21
22
23
# File 'lib/true-web.rb', line 21

def controller
  @controller
end

#named_routesObject 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_dirObject

Returns the value of attribute root_dir.



21
22
23
# File 'lib/true-web.rb', line 21

def root_dir
  @root_dir
end

#stderr_dirObject

Returns the value of attribute stderr_dir.



21
22
23
# File 'lib/true-web.rb', line 21

def stderr_dir
  @stderr_dir
end

#stdout_dirObject

Returns the value of attribute stdout_dir.



21
22
23
# File 'lib/true-web.rb', line 21

def stdout_dir
  @stdout_dir
end

#views_classObject

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

#appObject



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_dirObject



87
88
89
# File 'lib/true-web.rb', line 87

def lib_dir
  File.join(root_dir, "lib")
end

#pluginsObject



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_filesObject



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_dirsObject



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

#servicesObject



58
59
60
# File 'lib/true-web.rb', line 58

def services
  @services ||= []
end

#services_by_root_dirObject



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_prefixObject



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_dirObject



99
100
101
# File 'lib/true-web.rb', line 99

def services_dir
  File.join(root_dir, "services")
end

#stderr_loggerObject



75
76
77
# File 'lib/true-web.rb', line 75

def stderr_logger
  @stderr_logger ||= Logger.new(stderr_dir)
end

#stdout_loggerObject



79
80
81
# File 'lib/true-web.rb', line 79

def stdout_logger
  @stdout_logger ||= Logger.new(stdout_dir)
end

#stylesheets_dirsObject



91
92
93
# File 'lib/true-web.rb', line 91

def stylesheets_dirs
  service_subdirectory_dirs "app/stylesheets"
end

#vendor_dirObject



95
96
97
# File 'lib/true-web.rb', line 95

def vendor_dir
  File.join(root_dir, "vendor")
end