bang-bang 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/lib/bang-bang.rb +3 -104
- data/lib/bang-bang/app_config.rb +36 -0
- data/lib/bang-bang/concern.rb +69 -0
- data/lib/bang-bang/service.rb +9 -5
- data/lib/bang-bang/service_config.rb +100 -0
- data/lib/bang-bang/version.rb +1 -1
- data/spec/bang-bang/controller_spec.rb +5 -1
- data/spec/bang-bang/service_spec.rb +3 -3
- data/spec/bang-bang/views_spec.rb +1 -1
- data/spec/fixture-app/app.rb +2 -1
- data/spec/fixture-app/services/authentication/app/controllers/authentication.rb +1 -1
- data/spec/fixture-app/services/authentication/init.rb +1 -0
- data/spec/fixture-app/services/authentication/lib/authentication.rb +22 -0
- metadata +6 -2
data/Gemfile.lock
CHANGED
data/lib/bang-bang.rb
CHANGED
@@ -13,112 +13,11 @@ require "#{dir}/bang-bang/version"
|
|
13
13
|
require "#{dir}/bang-bang/env_methods"
|
14
14
|
|
15
15
|
module BangBang
|
16
|
-
def self.included(mod)
|
17
|
-
mod.extend(ClassMethods)
|
18
|
-
end
|
19
|
-
|
20
|
-
module ClassMethods
|
21
|
-
attr_accessor :application_name, :named_routes, :stderr_dir, :stdout_dir, :root_dir, :views_class
|
22
|
-
alias_method :uris, :named_routes
|
23
|
-
|
24
|
-
include ::BangBang::EnvMethods
|
25
|
-
|
26
|
-
def init(params={})
|
27
|
-
self.application_name = params[:application_name] || raise(ArgumentError, "You must provide an :application_name param")
|
28
|
-
self.root_dir = params[:root_dir] || raise(ArgumentError, "You must provide a :root_dir param")
|
29
|
-
self.named_routes = params[:named_routes] || raise(ArgumentError, "You must provide a :named_routes param")
|
30
|
-
self.views_class = params[:views_class] || raise(ArgumentError, "You must provide a :views_class param")
|
31
|
-
|
32
|
-
plugins.init
|
33
|
-
end
|
34
|
-
|
35
|
-
def register_controller(controller)
|
36
|
-
controller.config = self
|
37
|
-
end
|
38
|
-
|
39
|
-
def register_service(path, &block)
|
40
|
-
unless service_dirs.include?(path)
|
41
|
-
service = Service.new(path)
|
42
|
-
services << service
|
43
|
-
service.init(&block)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def service_dirs
|
48
|
-
services.map do |service|
|
49
|
-
service.root_dir
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def services
|
54
|
-
@services ||= []
|
55
|
-
end
|
56
|
-
|
57
|
-
def services_by_url_prefix
|
58
|
-
services.group_by do |service|
|
59
|
-
service.url_prefix
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def services_by_root_dir
|
64
|
-
services.inject({}) do |memo, service|
|
65
|
-
memo[service.root_dir] = service
|
66
|
-
memo
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def stderr_logger
|
71
|
-
@stderr_logger ||= Logger.new(stderr_dir)
|
72
|
-
end
|
73
|
-
|
74
|
-
def stdout_logger
|
75
|
-
@stdout_logger ||= Logger.new(stdout_dir)
|
76
|
-
end
|
77
|
-
|
78
|
-
def plugins
|
79
|
-
@plugins ||= ::BangBang::Plugins::Set.new(self)
|
80
|
-
end
|
81
|
-
|
82
|
-
def lib_dir
|
83
|
-
File.join(root_dir, "lib")
|
84
|
-
end
|
85
|
-
|
86
|
-
def stylesheets_dirs
|
87
|
-
service_subdirectory_dirs "app/stylesheets"
|
88
|
-
end
|
89
|
-
|
90
|
-
def vendor_dir
|
91
|
-
File.join(root_dir, "vendor")
|
92
|
-
end
|
93
|
-
|
94
|
-
def services_dir
|
95
|
-
File.join(root_dir, "services")
|
96
|
-
end
|
97
|
-
|
98
|
-
def service_subdirectory_dirs(relative_directory)
|
99
|
-
service_dirs.flatten.map do |service_path|
|
100
|
-
full_path = File.join(service_path, relative_directory)
|
101
|
-
full_path if File.directory?(full_path)
|
102
|
-
end.compact
|
103
|
-
end
|
104
|
-
|
105
|
-
def stderr_dir
|
106
|
-
"#{root_dir}/log/#{application_name}.#{rack_env}.stderr.log"
|
107
|
-
end
|
108
|
-
|
109
|
-
def stdout_dir
|
110
|
-
"#{root_dir}/log/#{application_name}.#{rack_env}.stdout.log"
|
111
|
-
end
|
112
|
-
|
113
|
-
def remove_generated_files
|
114
|
-
Dir["#{root_dir}/**/public/**/*.generated"].each do |generated_path|
|
115
|
-
FileUtils.rm_f(File.join(File.dirname(generated_path), File.basename(generated_path, ".generated")))
|
116
|
-
FileUtils.rm_f(generated_path)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
16
|
end
|
121
17
|
|
18
|
+
require "#{dir}/bang-bang/concern"
|
19
|
+
require "#{dir}/bang-bang/service_config"
|
20
|
+
require "#{dir}/bang-bang/app_config"
|
122
21
|
require "#{dir}/bang-bang/controller"
|
123
22
|
require "#{dir}/bang-bang/service"
|
124
23
|
require "#{dir}/bang-bang/views"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module BangBang
|
2
|
+
module AppConfig
|
3
|
+
extend BangBang::Concern
|
4
|
+
|
5
|
+
include ServiceConfig
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
attr_accessor :application_name, :stderr_dir, :stdout_dir
|
9
|
+
|
10
|
+
def init(params={})
|
11
|
+
params[:root_dir] || raise(ArgumentError, "You must provide a :root_dir param")
|
12
|
+
params[:named_routes] || raise(ArgumentError, "You must provide a :named_routes param")
|
13
|
+
params[:views_class] || raise(ArgumentError, "You must provide a :views_class param")
|
14
|
+
self.application_name = params[:application_name] || raise(ArgumentError, "You must provide an :application_name param")
|
15
|
+
params[:app_config] = self
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def stderr_logger
|
20
|
+
@stderr_logger ||= Logger.new(stderr_dir)
|
21
|
+
end
|
22
|
+
|
23
|
+
def stdout_logger
|
24
|
+
@stdout_logger ||= Logger.new(stdout_dir)
|
25
|
+
end
|
26
|
+
|
27
|
+
def stderr_dir
|
28
|
+
"#{root_dir}/log/#{application_name}.#{rack_env}.stderr.log"
|
29
|
+
end
|
30
|
+
|
31
|
+
def stdout_dir
|
32
|
+
"#{root_dir}/log/#{application_name}.#{rack_env}.stdout.log"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module BangBang
|
2
|
+
begin
|
3
|
+
require "active_support/concern"
|
4
|
+
Concern = ActiveSupport::Concern
|
5
|
+
rescue LoadError
|
6
|
+
# A typical module looks like this
|
7
|
+
#
|
8
|
+
# module M
|
9
|
+
# def self.included(base)
|
10
|
+
# base.send(:extend, ClassMethods)
|
11
|
+
# base.send(:include, InstanceMethods)
|
12
|
+
# scope :foo, :conditions => { :created_at => nil }
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# module ClassMethods
|
16
|
+
# def cm; puts 'I am a class method'; end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# module InstanceMethods
|
20
|
+
# def im; puts 'I am an instance method'; end
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# By using <tt>ActiveSupport::Concern</tt> the above module could instead be written as:
|
25
|
+
#
|
26
|
+
# module M
|
27
|
+
# extend ActiveSupport::Concern
|
28
|
+
#
|
29
|
+
# included do
|
30
|
+
# scope :foo, :conditions => { :created_at => nil }
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# module ClassMethods
|
34
|
+
# def cm; puts 'I am a class method'; end
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# module InstanceMethods
|
38
|
+
# def im; puts 'I am an instance method'; end
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
module Concern
|
42
|
+
def self.extended(base)
|
43
|
+
base.instance_variable_set("@_dependencies", [])
|
44
|
+
end
|
45
|
+
|
46
|
+
def append_features(base)
|
47
|
+
if base.instance_variable_defined?("@_dependencies")
|
48
|
+
base.instance_variable_get("@_dependencies") << self
|
49
|
+
return false
|
50
|
+
else
|
51
|
+
return false if base < self
|
52
|
+
@_dependencies.each { |dep| base.send(:include, dep) }
|
53
|
+
super
|
54
|
+
base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
|
55
|
+
base.send :include, const_get("InstanceMethods") if const_defined?("InstanceMethods")
|
56
|
+
base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def included(base = nil, &block)
|
61
|
+
if base.nil?
|
62
|
+
@_included_block = block
|
63
|
+
else
|
64
|
+
super
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/bang-bang/service.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
module BangBang
|
2
2
|
class Service
|
3
|
-
attr_reader :root_dir
|
3
|
+
attr_reader :app_config, :root_dir
|
4
4
|
attr_accessor :url_prefix
|
5
5
|
|
6
|
-
def initialize(dir)
|
6
|
+
def initialize(app_config, dir)
|
7
|
+
@app_config = app_config
|
7
8
|
@root_dir = dir
|
8
9
|
end
|
9
10
|
|
10
11
|
def init
|
11
|
-
init_controllers
|
12
|
-
autoload_models
|
13
12
|
append_load_paths
|
14
13
|
eval_init_rb
|
14
|
+
init_controllers
|
15
|
+
autoload_models
|
15
16
|
yield(self) if block_given?
|
16
17
|
self
|
17
18
|
end
|
18
19
|
|
19
20
|
def append_load_paths
|
20
|
-
lib_dir = File.join(root_dir, "lib")
|
21
21
|
$LOAD_PATH << lib_dir if File.directory?(lib_dir)
|
22
22
|
end
|
23
23
|
|
@@ -146,6 +146,10 @@ module BangBang
|
|
146
146
|
end
|
147
147
|
|
148
148
|
protected
|
149
|
+
def lib_dir
|
150
|
+
File.join(root_dir, "lib")
|
151
|
+
end
|
152
|
+
|
149
153
|
def asset_url(file, url_path, cache_buster)
|
150
154
|
if cache_buster
|
151
155
|
"#{url_path}?_cb=#{File.mtime(file).to_i}"
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module BangBang
|
2
|
+
module ServiceConfig
|
3
|
+
extend Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
attr_accessor :app_config, :root_dir
|
7
|
+
attr_writer :named_routes, :views_class
|
8
|
+
|
9
|
+
include ::BangBang::EnvMethods
|
10
|
+
|
11
|
+
def init(params={})
|
12
|
+
self.app_config = params[:app_config]
|
13
|
+
self.root_dir = params[:root_dir]
|
14
|
+
self.named_routes = params[:named_routes]
|
15
|
+
self.views_class = params[:views_class]
|
16
|
+
|
17
|
+
plugins.init
|
18
|
+
end
|
19
|
+
|
20
|
+
def named_routes
|
21
|
+
@named_routes || (app_config && app_config.named_routes) || nil
|
22
|
+
end
|
23
|
+
alias_method :uris, :named_routes
|
24
|
+
alias_method :uris=, :named_routes=
|
25
|
+
|
26
|
+
def views_class
|
27
|
+
@views_class || (app_config && app_config.views_class) || nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def register_controller(controller)
|
31
|
+
controller.config = self
|
32
|
+
end
|
33
|
+
|
34
|
+
def register_service(path, &block)
|
35
|
+
unless service_dirs.include?(path)
|
36
|
+
service = Service.new(self, path)
|
37
|
+
services << service
|
38
|
+
service.init(&block)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def service_dirs
|
43
|
+
services.map do |service|
|
44
|
+
service.root_dir
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def services
|
49
|
+
@services ||= []
|
50
|
+
end
|
51
|
+
|
52
|
+
def services_by_url_prefix
|
53
|
+
services.group_by do |service|
|
54
|
+
service.url_prefix
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def services_by_root_dir
|
59
|
+
services.inject({}) do |memo, service|
|
60
|
+
memo[service.root_dir] = service
|
61
|
+
memo
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def plugins
|
66
|
+
@plugins ||= ::BangBang::Plugins::Set.new(self)
|
67
|
+
end
|
68
|
+
|
69
|
+
def lib_dir
|
70
|
+
File.join(root_dir, "lib")
|
71
|
+
end
|
72
|
+
|
73
|
+
def stylesheets_dirs
|
74
|
+
service_subdirectory_dirs "app/stylesheets"
|
75
|
+
end
|
76
|
+
|
77
|
+
def vendor_dir
|
78
|
+
File.join(root_dir, "vendor")
|
79
|
+
end
|
80
|
+
|
81
|
+
def services_dir
|
82
|
+
File.join(root_dir, "services")
|
83
|
+
end
|
84
|
+
|
85
|
+
def service_subdirectory_dirs(relative_directory)
|
86
|
+
service_dirs.flatten.map do |service_path|
|
87
|
+
full_path = File.join(service_path, relative_directory)
|
88
|
+
full_path if File.directory?(full_path)
|
89
|
+
end.compact
|
90
|
+
end
|
91
|
+
|
92
|
+
def remove_generated_files
|
93
|
+
Dir["#{root_dir}/**/public/**/*.generated"].each do |generated_path|
|
94
|
+
FileUtils.rm_f(File.join(File.dirname(generated_path), File.basename(generated_path, ".generated")))
|
95
|
+
FileUtils.rm_f(generated_path)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/bang-bang/version.rb
CHANGED
@@ -3,9 +3,13 @@ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
|
3
3
|
module BangBang
|
4
4
|
describe Controller do
|
5
5
|
describe "GET /authentication/error-page" do
|
6
|
+
def uris
|
7
|
+
@uris ||= Authentication::Routes.instance
|
8
|
+
end
|
9
|
+
|
6
10
|
context "when there is not a rack.logger" do
|
7
11
|
it "responds with a 500" do
|
8
|
-
any_instance_of(
|
12
|
+
any_instance_of(Authentication::Controller) do |controller|
|
9
13
|
stub.proxy(controller).env do |env|
|
10
14
|
env.delete("rack.logger")
|
11
15
|
env
|
@@ -6,7 +6,7 @@ module BangBang
|
|
6
6
|
context "when the service has a file matching the given url" do
|
7
7
|
it "returns the file path of the static file base on the Service's prefix + file path" do
|
8
8
|
authentication_path = "#{FixtureApp.root_dir}/services/authentication"
|
9
|
-
service = Service.new(authentication_path).init
|
9
|
+
service = Service.new(Object.new, authentication_path).init
|
10
10
|
service.url_prefix.should == "/authentication"
|
11
11
|
service.get_static_file_path("/authentication/javascripts/foo.js").should ==
|
12
12
|
File.join(authentication_path, "/public/javascripts/foo.js")
|
@@ -16,7 +16,7 @@ module BangBang
|
|
16
16
|
context "when the service does not have a file matching the given url" do
|
17
17
|
it "returns nil" do
|
18
18
|
authentication_path = "#{FixtureApp.root_dir}/services/authentication"
|
19
|
-
service = Service.new(authentication_path).init
|
19
|
+
service = Service.new(Object.new, authentication_path).init
|
20
20
|
service.get_static_file_path("i-dont-exist").should be_nil
|
21
21
|
end
|
22
22
|
end
|
@@ -25,7 +25,7 @@ module BangBang
|
|
25
25
|
describe "#templates_hash" do
|
26
26
|
it "returns a hash of all of the template files" do
|
27
27
|
authentication_path = "#{FixtureApp.root_dir}/services/authentication"
|
28
|
-
service = Service.new(authentication_path).init
|
28
|
+
service = Service.new(Object.new, authentication_path).init
|
29
29
|
|
30
30
|
hash = service.templates_hash
|
31
31
|
hash["/authentication/index.html.ms"].should == File.read(File.join(service.templates_dir, "index.html.ms"))
|
@@ -14,7 +14,7 @@ module BangBang
|
|
14
14
|
context "when the presenter file exists" do
|
15
15
|
it "evals the presenter file (which is responsible for adding the method)" do
|
16
16
|
authentication_path = "#{FixtureApp.root_dir}/services/authentication"
|
17
|
-
service = Service.new(authentication_path).init
|
17
|
+
service = Service.new(Object.new, authentication_path).init
|
18
18
|
app_instance = Object.new
|
19
19
|
stub(app_instance).services {[service]}
|
20
20
|
stub(app_instance).config {FixtureApp}
|
data/spec/fixture-app/app.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Authentication
|
2
|
+
include BangBang::ServiceConfig
|
3
|
+
|
4
|
+
class Controller < ::BangBang::Controller
|
5
|
+
set :dump_errors, false
|
6
|
+
end
|
7
|
+
register_controller Controller
|
8
|
+
|
9
|
+
class Views < ::BangBang::Views
|
10
|
+
end
|
11
|
+
|
12
|
+
class Routes < NamedRoutes::Routes
|
13
|
+
end
|
14
|
+
|
15
|
+
init(
|
16
|
+
:views => Views,
|
17
|
+
:routes => Routes,
|
18
|
+
:root_dir => File.expand_path("#{File.dirname(__FILE__)}/.."),
|
19
|
+
:named_routes => Routes,
|
20
|
+
:views_class => Views
|
21
|
+
)
|
22
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bang-bang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brian Takita
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-24 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -174,11 +174,14 @@ files:
|
|
174
174
|
- Rakefile
|
175
175
|
- bang-bang.gemspec
|
176
176
|
- lib/bang-bang.rb
|
177
|
+
- lib/bang-bang/app_config.rb
|
178
|
+
- lib/bang-bang/concern.rb
|
177
179
|
- lib/bang-bang/controller.rb
|
178
180
|
- lib/bang-bang/env_methods.rb
|
179
181
|
- lib/bang-bang/plugins.rb
|
180
182
|
- lib/bang-bang/plugins/directory_first_sort.rb
|
181
183
|
- lib/bang-bang/service.rb
|
184
|
+
- lib/bang-bang/service_config.rb
|
182
185
|
- lib/bang-bang/version.rb
|
183
186
|
- lib/bang-bang/views.rb
|
184
187
|
- spec/bang-bang/controller_spec.rb
|
@@ -189,6 +192,7 @@ files:
|
|
189
192
|
- spec/fixture-app/services/authentication/app/presenters/index.html.ms.rb
|
190
193
|
- spec/fixture-app/services/authentication/app/templates/index.html.ms
|
191
194
|
- spec/fixture-app/services/authentication/init.rb
|
195
|
+
- spec/fixture-app/services/authentication/lib/authentication.rb
|
192
196
|
- spec/fixture-app/services/authentication/public/javascripts/foo.js
|
193
197
|
- spec/spec_helper.rb
|
194
198
|
- spec/spec_helpers/example_group.rb
|