blue_print 1.3.0 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 206433cbd4ea20e4889db2b3925b82d6f133bd21
4
- data.tar.gz: 37a77da96f4fd80e0646e084cc640c93530dbd60
3
+ metadata.gz: 36c078c9540643a1c92333bb69e1cff272152531
4
+ data.tar.gz: 333c4e5f2f455a7d9a40cc798f057a99533ddd5d
5
5
  SHA512:
6
- metadata.gz: 2a94144f0ef54288803e77e932a9dc42e4bbcf621af214a4cb3a7d52c8108119758efe47107603d656a56e3d8ce65d6977ec4e5273b1ffa86e9d420859aacc89
7
- data.tar.gz: 4aa19df93eb03d52a7ad5f17a214310339ac9f74fa0da8d65e30a2fe4bb9fce1e2857285fb37468b8dda7bc84576800c232a367ffa8ee87be2aefcf9d87d3dec
6
+ metadata.gz: d242609ed3a93872634e7fdd7955837972c96e7b3b4a0fde2e43c69583c81687e173b6a800dcc45da7c00211fdaf1aa3617e6874efb8bb755a175cfb37ecd6cf
7
+ data.tar.gz: 569938c8a3701fb2b0f0464e761fc24de4624d79df01b9bfec3a169cd3e251c196e96855bee4dac38800ef8e3b92a65462d8d975784e48e80679769bc4b5ad13
@@ -15,6 +15,9 @@ matrix:
15
15
  allow_failures:
16
16
  - rvm: ruby-head
17
17
  - gemfile: gemfiles/rails-head.gemfile
18
+ branches:
19
+ except:
20
+ - /^v([0-9]+\.){2}[0-9]+/
18
21
  script: bundle exec rspec
19
22
  notifications:
20
23
  slack:
data/README.md CHANGED
@@ -21,7 +21,7 @@ The behavior switching framework. inspired by [DCI](http://en.wikipedia.org/wiki
21
21
  Add this line to your application's Gemfile:
22
22
 
23
23
  ```ruby
24
- gem 'blue_print', '~> 1.2.0'
24
+ gem 'blue_print', '~> 1.3.0'
25
25
  ```
26
26
 
27
27
  ## Usage
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|
@@ -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
- PURE_RESULT = []
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
- PURE_RESULT.push(
49
- Benchmark.measure("#{n}#{n.ordinal}") do
50
- Model.activate!
51
-
52
- NUM_ITERATION.times do
53
- Model.new.name
54
- NoEffect.new.name
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
- BLUE_PRINT_RESULT = []
29
- progress = ProgressBar.create(
30
- title: model.name.to_s.ljust(LABEL_WIDTH),
31
- total: BENCHMARK_ITERATION
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
@@ -14,29 +14,10 @@ end
14
14
 
15
15
  model = Model.new.extend(ExtendedUser)
16
16
 
17
- EXTEND_RESULT = []
18
- progress = ProgressBar.create(
19
- title: model.name.to_s.ljust(LABEL_WIDTH),
20
- total: BENCHMARK_ITERATION
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
@@ -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[:blue_print] ||= Thread.parents[:blue_print]
14
+ Thread.current[ENV_KEY] ||= Thread.parents[ENV_KEY]
13
15
  end
14
16
 
15
17
  def self.env=(env)
16
- Thread.current[:blue_print] = env
18
+ Thread.current[ENV_KEY] = env
17
19
  end
18
20
 
19
21
  def self.clear!
20
- Thread.current[:blue_print] = nil
22
+ Thread.current[ENV_KEY] = nil
21
23
  end
22
24
  end
@@ -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 BluePrint.env
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
@@ -25,6 +25,10 @@ module BluePrint::Integration::ActionController
25
25
  end
26
26
  end
27
27
 
28
+ ::ActionController::Base::MODULES.push(
29
+ BluePrint::Integration::ActionController
30
+ )
31
+
28
32
  ::ActionController::Base.send(
29
33
  :include,
30
34
  BluePrint::Integration::ActionController
@@ -1,3 +1,3 @@
1
1
  module BluePrint
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
@@ -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.downcase}.rb"
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.downcase}_spec.rb"
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:customer) }
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, Customer]'
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 'customer.rb' do
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:customer) }
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 'customer_spec.rb' do
41
- contains 'StaffContext::Customer'
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.0
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-16 00:00:00.000000000 Z
11
+ date: 2014-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler