whitelabel 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ *.gem
@@ -19,7 +19,21 @@ module Whitelabel
19
19
  end
20
20
 
21
21
  def label_for(pattern, identifier=:label_id)
22
- self.label = @labels.find { |label| label.send(identifier) =~ /^#{pattern}$/ }
22
+ self.label = find_label(pattern, identifier)
23
+ end
24
+
25
+ def find_label(pattern, identifier=:label_id)
26
+ @labels.find { |label| label.send(identifier) =~ /^#{pattern}$/ }
27
+ end
28
+
29
+ def with_label(tmp=nil)
30
+ if tmp
31
+ current_label = self.label
32
+ self.label = tmp
33
+ end
34
+ yield
35
+ ensure
36
+ self.label = current_label if current_label
23
37
  end
24
38
 
25
39
  def [](accessor)
@@ -1,3 +1,3 @@
1
1
  module Whitelabel
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -19,6 +19,12 @@ describe Whitelabel do
19
19
  Whitelabel.from_file(path)
20
20
  end
21
21
 
22
+ it "should have two different labels" do
23
+ Whitelabel.find_label('test')[:label_id].should eql('test')
24
+ Whitelabel.find_label('uschi')[:label_id].should eql('uschi')
25
+ Whitelabel.find_label('wrong').should be_nil
26
+ end
27
+
22
28
  it "should work thread safe" do
23
29
  Whitelabel.label = :bla
24
30
  Thread.new { Whitelabel.label = nil }
@@ -34,6 +40,16 @@ describe Whitelabel do
34
40
  Whitelabel.label_for('').should be_nil
35
41
  end
36
42
 
43
+ it "should enable a temporary label" do
44
+ label = Whitelabel.label_for('uschi')
45
+ Whitelabel.label.should eql(label)
46
+ tmp = Whitelabel.find_label('test')
47
+ Whitelabel.with_label(tmp) do
48
+ Whitelabel.label.should eql(tmp)
49
+ end
50
+ Whitelabel.label.should eql(label)
51
+ end
52
+
37
53
  context "with current label" do
38
54
  before(:each) do
39
55
  Whitelabel.label = Dummy.new('some_id', 'some_name')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whitelabel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70301997873560 !ruby/object:Gem::Requirement
16
+ requirement: &70180733442420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.9'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70301997873560
24
+ version_requirements: *70180733442420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: pry
27
- requirement: &70301997873060 !ruby/object:Gem::Requirement
27
+ requirement: &70180733441920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0.9'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70301997873060
35
+ version_requirements: *70180733441920
36
36
  description: This gem helps you providing whitelabel functionality in your application
37
37
  email:
38
38
  - phoetmail@googlemail.com
@@ -41,6 +41,7 @@ extensions: []
41
41
  extra_rdoc_files: []
42
42
  files:
43
43
  - .document
44
+ - .gitignore
44
45
  - .rspec
45
46
  - .rvmrc
46
47
  - .travis.yml