loadable_component 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,6 +47,8 @@ class SlowLoadableComponent < LoadableComponent
47
47
  return self
48
48
  end
49
49
 
50
+ load
51
+
50
52
  end_time = Time.now + @timeout
51
53
  until Time.now >= end_time
52
54
  return self if loaded?
@@ -1,3 +1,3 @@
1
1
  class LoadableComponent
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -6,16 +6,15 @@ describe SlowLoadableComponent do
6
6
  SlowlyDetonatingComponent.new.get.should be_instance_of(SlowlyDetonatingComponent)
7
7
  end
8
8
 
9
- it "calls the load method if the component is not already loaded" do
10
- number_of_times_through_loop = 1
11
- component = SlowLoading.new(number_of_times_through_loop).get
9
+ it "calls #load if the component is not already loaded" do
10
+ component = SlowLoading.new.get
12
11
  component.should be_instance_of(SlowLoading)
13
12
 
14
- component.loop_count.should == number_of_times_through_loop
13
+ component.load_called.should be_true
15
14
  end
16
15
 
17
16
  it "calls the load method once if the component takes a long time to load" do
18
- OnlyOneLoad.new(5).get
17
+ OnlyOneLoad.new.get
19
18
  end
20
19
 
21
20
  it "should throw an error if calling load does not cause the component to load before timeout" do
data/spec/spec_helper.rb CHANGED
@@ -55,40 +55,31 @@ class SlowlyDetonatingComponent < SlowLoadableComponent
55
55
  end
56
56
 
57
57
  class SlowLoading < SlowLoadableComponent
58
- attr_reader :loop_count
58
+ attr_reader :load_called
59
59
 
60
- def initialize(count)
61
- @count = count
62
- @loop_count = 0
60
+ def initialize
61
+ @load_called = false
63
62
 
64
63
  super(1)
65
64
  end
66
65
 
67
66
  def load
68
- # does nothing
67
+ @load_called = true
69
68
  end
70
69
 
71
70
  def loaded?
72
- if @loop_count > @count
73
- false
74
- else
75
- @loop_count += 1
76
- end
71
+ @load_called
77
72
  end
78
73
  end
79
74
 
80
75
  class OnlyOneLoad < SlowLoading
81
- def initialize(count)
82
- super(count)
83
- @load_called = false
84
- end
85
76
 
86
77
  def load
87
78
  if @load_called
88
79
  raise "load already called"
89
80
  end
90
81
 
91
- @load_called = true
82
+ super
92
83
  end
93
84
  end
94
85
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loadable_component
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jari Bakken