Module: BangBang::ServiceConfig::ClassMethods

Includes:
EnvMethods
Defined in:
lib/bang-bang/service_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EnvMethods

#development?, #rack_env

Instance Attribute Details

#app_configObject

Returns the value of attribute app_config.



6
7
8
# File 'lib/bang-bang/service_config.rb', line 6

def app_config
  @app_config
end

#named_routesObject Also known as: uris



20
21
22
# File 'lib/bang-bang/service_config.rb', line 20

def named_routes
  @named_routes || (app_config && app_config.named_routes) || nil
end

#root_dirObject

Returns the value of attribute root_dir.



6
7
8
# File 'lib/bang-bang/service_config.rb', line 6

def root_dir
  @root_dir
end

#views_classObject



26
27
28
# File 'lib/bang-bang/service_config.rb', line 26

def views_class
  @views_class || (app_config && app_config.views_class) || nil
end

Instance Method Details

#init(params = {}) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/bang-bang/service_config.rb', line 11

def init(params={})
  self.app_config = params[:app_config]
  self.root_dir = params[:root_dir]
  self.named_routes = params[:named_routes]
  self.views_class = params[:views_class]

  plugins.init
end

#lib_dirObject



69
70
71
# File 'lib/bang-bang/service_config.rb', line 69

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

#pluginsObject



65
66
67
# File 'lib/bang-bang/service_config.rb', line 65

def plugins
  @plugins ||= ::BangBang::Plugins::Set.new(self)
end

#register_controller(controller) ⇒ Object



30
31
32
# File 'lib/bang-bang/service_config.rb', line 30

def register_controller(controller)
  controller.config = self
end

#register_service(path, &block) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/bang-bang/service_config.rb', line 34

def register_service(path, &block)
  unless service_dirs.include?(path)
    service = Service.new(self, path)
    services << service
    service.init(&block)
  end
end

#remove_generated_filesObject



92
93
94
95
96
97
# File 'lib/bang-bang/service_config.rb', line 92

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



42
43
44
45
46
# File 'lib/bang-bang/service_config.rb', line 42

def service_dirs
  services.map do |service|
    service.root_dir
  end
end

#service_subdirectory_dirs(relative_directory) ⇒ Object



85
86
87
88
89
90
# File 'lib/bang-bang/service_config.rb', line 85

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



48
49
50
# File 'lib/bang-bang/service_config.rb', line 48

def services
  @services ||= []
end

#services_by_root_dirObject



58
59
60
61
62
63
# File 'lib/bang-bang/service_config.rb', line 58

def services_by_root_dir
  services.inject({}) do |memo, service|
    memo[service.root_dir] = service
    memo
  end
end

#services_by_url_prefixObject



52
53
54
55
56
# File 'lib/bang-bang/service_config.rb', line 52

def services_by_url_prefix
  services.group_by do |service|
    service.url_prefix
  end
end

#services_dirObject



81
82
83
# File 'lib/bang-bang/service_config.rb', line 81

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

#stylesheets_dirsObject



73
74
75
# File 'lib/bang-bang/service_config.rb', line 73

def stylesheets_dirs
  service_subdirectory_dirs "app/stylesheets"
end

#vendor_dirObject



77
78
79
# File 'lib/bang-bang/service_config.rb', line 77

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