blue_print 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +1 -1
- data/Rakefile +1 -5
- data/benchmark/pure.rb +39 -29
- data/benchmark/with_blue_print.rb +6 -29
- data/benchmark/with_extend.rb +6 -25
- data/lib/blue_print.rb +5 -3
- data/lib/blue_print/helper.rb +6 -2
- data/lib/blue_print/integration/action_controller.rb +4 -0
- data/lib/blue_print/version.rb +1 -1
- data/lib/generators/rails/blue_print_generator.rb +1 -1
- data/lib/generators/rspec/blue_print_generator.rb +1 -1
- data/spec/lib/blue_print/helper_spec.rb +33 -0
- data/spec/lib/generators/rails/blue_print_generator_spec.rb +3 -3
- data/spec/lib/generators/rspec/blue_print_generator_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36c078c9540643a1c92333bb69e1cff272152531
|
4
|
+
data.tar.gz: 333c4e5f2f455a7d9a40cc798f057a99533ddd5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d242609ed3a93872634e7fdd7955837972c96e7b3b4a0fde2e43c69583c81687e173b6a800dcc45da7c00211fdaf1aa3617e6874efb8bb755a175cfb37ecd6cf
|
7
|
+
data.tar.gz: 569938c8a3701fb2b0f0464e761fc24de4624d79df01b9bfec3a169cd3e251c196e96855bee4dac38800ef8e3b92a65462d8d975784e48e80679769bc4b5ad13
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -13,11 +13,7 @@ task :benchmark do
|
|
13
13
|
},
|
14
14
|
benchmark_iteration: BENCHMARK_ITERATION,
|
15
15
|
method_call_iteration: NUM_ITERATION,
|
16
|
-
benchmarks:
|
17
|
-
pure: PURE_RESULT,
|
18
|
-
blue_print: BLUE_PRINT_RESULT,
|
19
|
-
extend: EXTEND_RESULT
|
20
|
-
}
|
16
|
+
benchmarks: SCORES
|
21
17
|
}
|
22
18
|
|
23
19
|
result[:benchmarks].each_pair do |label, scores|
|
data/benchmark/pure.rb
CHANGED
@@ -5,6 +5,37 @@ require 'benchmark'
|
|
5
5
|
LABEL_WIDTH = 10
|
6
6
|
BENCHMARK_ITERATION = 100
|
7
7
|
NUM_ITERATION = 100000
|
8
|
+
SCORES = Hash.new { |h, k| h[k] = [] }
|
9
|
+
|
10
|
+
def benchmark(label, before_active, active, before_deactive, deactive)
|
11
|
+
progress = ProgressBar.create(
|
12
|
+
title: label.to_s.ljust(LABEL_WIDTH),
|
13
|
+
total: BENCHMARK_ITERATION
|
14
|
+
)
|
15
|
+
GC.start
|
16
|
+
BENCHMARK_ITERATION.times do |n|
|
17
|
+
n += 1
|
18
|
+
|
19
|
+
SCORES[label].push(
|
20
|
+
Benchmark.measure("#{n}#{n.ordinal}") do
|
21
|
+
before_active && before_active.call
|
22
|
+
|
23
|
+
NUM_ITERATION.times do
|
24
|
+
active.call
|
25
|
+
end
|
26
|
+
|
27
|
+
before_deactive && before_deactive.call
|
28
|
+
|
29
|
+
NUM_ITERATION.times do
|
30
|
+
deactive.call
|
31
|
+
end
|
32
|
+
end
|
33
|
+
)
|
34
|
+
|
35
|
+
progress.increment
|
36
|
+
end
|
37
|
+
progress.finish
|
38
|
+
end
|
8
39
|
|
9
40
|
class Model
|
10
41
|
def self.active?
|
@@ -36,33 +67,12 @@ end
|
|
36
67
|
|
37
68
|
model = Model.new
|
38
69
|
|
39
|
-
|
40
|
-
progress = ProgressBar.create(
|
41
|
-
title: model.name.to_s.ljust(LABEL_WIDTH),
|
42
|
-
total: BENCHMARK_ITERATION
|
43
|
-
)
|
44
|
-
GC.start
|
45
|
-
BENCHMARK_ITERATION.times do |n|
|
46
|
-
n += 1
|
70
|
+
DEFAULT_CALL = -> { Model.new.name; NoEffect.new.name }
|
47
71
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
Model.deactivate!
|
58
|
-
|
59
|
-
NUM_ITERATION.times do
|
60
|
-
Model.new.name
|
61
|
-
NoEffect.new.name
|
62
|
-
end
|
63
|
-
end
|
64
|
-
)
|
65
|
-
|
66
|
-
progress.increment
|
67
|
-
end
|
68
|
-
progress.finish
|
72
|
+
benchmark(
|
73
|
+
:pure,
|
74
|
+
-> { Model.activate! },
|
75
|
+
DEFAULT_CALL,
|
76
|
+
-> { Model.deactivate! },
|
77
|
+
DEFAULT_CALL
|
78
|
+
)
|
@@ -25,33 +25,10 @@ end
|
|
25
25
|
|
26
26
|
model = Model.new
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
benchmark(
|
29
|
+
:blue_print,
|
30
|
+
-> { BenchmarkContext.activate! },
|
31
|
+
DEFAULT_CALL,
|
32
|
+
-> { BenchmarkContext.deactivate! },
|
33
|
+
DEFAULT_CALL
|
32
34
|
)
|
33
|
-
GC.start
|
34
|
-
BENCHMARK_ITERATION.times do |n|
|
35
|
-
n += 1
|
36
|
-
|
37
|
-
BLUE_PRINT_RESULT.push(
|
38
|
-
Benchmark.measure("#{n}#{n.ordinal}") do
|
39
|
-
BenchmarkContext.activate!
|
40
|
-
|
41
|
-
NUM_ITERATION.times do
|
42
|
-
Model.new.name
|
43
|
-
NoEffect.new.name
|
44
|
-
end
|
45
|
-
|
46
|
-
BenchmarkContext.deactivate!
|
47
|
-
|
48
|
-
NUM_ITERATION.times do
|
49
|
-
Model.new.name
|
50
|
-
NoEffect.new.name
|
51
|
-
end
|
52
|
-
end
|
53
|
-
)
|
54
|
-
|
55
|
-
progress.increment
|
56
|
-
end
|
57
|
-
progress.finish
|
data/benchmark/with_extend.rb
CHANGED
@@ -14,29 +14,10 @@ end
|
|
14
14
|
|
15
15
|
model = Model.new.extend(ExtendedUser)
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
benchmark(
|
18
|
+
:extended,
|
19
|
+
nil,
|
20
|
+
-> { Model.new.extend(ExtendedUser).name; NoEffect.new.name },
|
21
|
+
nil,
|
22
|
+
DEFAULT_CALL,
|
21
23
|
)
|
22
|
-
GC.start
|
23
|
-
BENCHMARK_ITERATION.times do |n|
|
24
|
-
n += 1
|
25
|
-
|
26
|
-
EXTEND_RESULT.push(
|
27
|
-
Benchmark.measure("#{n}#{n.ordinal}") do
|
28
|
-
NUM_ITERATION.times do
|
29
|
-
Model.new.extend(ExtendedUser).name
|
30
|
-
NoEffect.new.name
|
31
|
-
end
|
32
|
-
|
33
|
-
NUM_ITERATION.times do
|
34
|
-
Model.new.name
|
35
|
-
NoEffect.new.name
|
36
|
-
end
|
37
|
-
end
|
38
|
-
)
|
39
|
-
|
40
|
-
progress.increment
|
41
|
-
end
|
42
|
-
progress.finish
|
data/lib/blue_print.rb
CHANGED
@@ -8,15 +8,17 @@ require 'blue_print/integration'
|
|
8
8
|
require 'blue_print/railtie' if defined?(Rails)
|
9
9
|
|
10
10
|
module BluePrint
|
11
|
+
ENV_KEY = :blue_print
|
12
|
+
|
11
13
|
def self.env
|
12
|
-
Thread.current[
|
14
|
+
Thread.current[ENV_KEY] ||= Thread.parents[ENV_KEY]
|
13
15
|
end
|
14
16
|
|
15
17
|
def self.env=(env)
|
16
|
-
Thread.current[
|
18
|
+
Thread.current[ENV_KEY] = env
|
17
19
|
end
|
18
20
|
|
19
21
|
def self.clear!
|
20
|
-
Thread.current[
|
22
|
+
Thread.current[ENV_KEY] = nil
|
21
23
|
end
|
22
24
|
end
|
data/lib/blue_print/helper.rb
CHANGED
@@ -5,9 +5,13 @@ module BluePrint::Helper
|
|
5
5
|
context = BluePrint::Context.resolve(name_or_context)
|
6
6
|
|
7
7
|
if context.active?
|
8
|
-
yield
|
8
|
+
block_given? && yield(BluePrint.env)
|
9
9
|
else
|
10
|
-
fallback.respond_to?(:call) && fallback.call
|
10
|
+
fallback.respond_to?(:call) && fallback.call(BluePrint.env)
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
def without_context_of(name_or_context, fallback = nil, &block)
|
15
|
+
within_context_of(name_or_context, block, &fallback)
|
16
|
+
end
|
13
17
|
end
|
data/lib/blue_print/version.rb
CHANGED
@@ -20,7 +20,7 @@ module Rails
|
|
20
20
|
def create_behavior_files
|
21
21
|
each_with_role do |role|
|
22
22
|
template 'role.rb', File.join(
|
23
|
-
'app/blue_prints', class_path, "#{file_name}_context", "#{role.
|
23
|
+
'app/blue_prints', class_path, "#{file_name}_context", "#{role.underscore}.rb"
|
24
24
|
)
|
25
25
|
end
|
26
26
|
end
|
@@ -13,7 +13,7 @@ module Rspec
|
|
13
13
|
def create_behavior_files
|
14
14
|
each_with_role do |role|
|
15
15
|
template 'role_spec.rb', File.join(
|
16
|
-
'spec/blue_prints', class_path, "#{file_name}_context", "#{role.
|
16
|
+
'spec/blue_prints', class_path, "#{file_name}_context", "#{role.underscore}_spec.rb"
|
17
17
|
)
|
18
18
|
end
|
19
19
|
end
|
@@ -35,4 +35,37 @@ describe BluePrint::Helper do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
describe '#without_context_of' do
|
40
|
+
context 'with deactive context' do
|
41
|
+
let(:context) { double(active?: false) }
|
42
|
+
|
43
|
+
it 'runs block' do
|
44
|
+
helper.should_receive(:message).once
|
45
|
+
helper.without_context_of(context) do |env|
|
46
|
+
expect(env).to eq(BluePrint.env)
|
47
|
+
helper.message
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with active context' do
|
53
|
+
let(:context) { double(active?: true) }
|
54
|
+
|
55
|
+
it 'not runs block' do
|
56
|
+
helper.should_not_receive(:message)
|
57
|
+
helper.without_context_of(context) do
|
58
|
+
helper.message
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'runs fallback' do
|
63
|
+
helper.should_receive(:fallback)
|
64
|
+
helper.should_not_receive(:message)
|
65
|
+
helper.without_context_of(context, proc { helper.fallback }) do
|
66
|
+
helper.message
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
38
71
|
end
|
@@ -56,13 +56,13 @@ describe Rails::Generators::BluePrintGenerator do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
context 'with Staff user:staff:customer' do
|
59
|
-
let(:arguments) { %w(Staff user:staff:
|
59
|
+
let(:arguments) { %w(Staff user:staff:customer_user) }
|
60
60
|
|
61
61
|
specify 'be generated' do
|
62
62
|
expect(destination_root).to(have_structure do
|
63
63
|
directory 'app/blue_prints' do
|
64
64
|
file 'staff_context.rb' do
|
65
|
-
contains 'cast ::User, as: [Staff,
|
65
|
+
contains 'cast ::User, as: [Staff, CustomerUser]'
|
66
66
|
end
|
67
67
|
|
68
68
|
directory 'staff_context' do
|
@@ -70,7 +70,7 @@ describe Rails::Generators::BluePrintGenerator do
|
|
70
70
|
contains 'StaffContext::Staff'
|
71
71
|
end
|
72
72
|
|
73
|
-
file '
|
73
|
+
file 'customer_user.rb' do
|
74
74
|
contains 'StaffContext::Customer'
|
75
75
|
end
|
76
76
|
end
|
@@ -28,7 +28,7 @@ describe Rspec::BluePrintGenerator do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'with Staff user:staff:customer' do
|
31
|
-
let(:arguments) { %w(Staff user:staff:
|
31
|
+
let(:arguments) { %w(Staff user:staff:customer_user) }
|
32
32
|
|
33
33
|
specify 'be generated' do
|
34
34
|
expect(destination_root).to(have_structure do
|
@@ -37,8 +37,8 @@ describe Rspec::BluePrintGenerator do
|
|
37
37
|
contains 'StaffContext::Staff'
|
38
38
|
end
|
39
39
|
|
40
|
-
file '
|
41
|
-
contains 'StaffContext::
|
40
|
+
file 'customer_user_spec.rb' do
|
41
|
+
contains 'StaffContext::CustomerUser'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blue_print
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Kusano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|