whitelabel 0.2.0 → 0.4.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f61691304e1cb815aa17c09be9c73713121359c93ec986c22f6bc97748ea349b
4
+ data.tar.gz: c46cb296325e46573e52452907b5e2fde43b66602100f453bb76f5866bf93399
5
+ SHA512:
6
+ metadata.gz: 1b6b08afa04817c48be69b07ee7c6d7cdabead8b68fed3f6ec9fd18778a7ec8920104f72bf5cf0f7cc408d779bb16b9a883508a6ca906aaa1ab3ceffb116c86c
7
+ data.tar.gz: c08269c92c5273b720b00f12664a4bfa2944e017fb0a745ae555de0e7785de34bad1fb9012fe7e2908429f509ecb416c5b2444f090663e46fea1f6f03df2e92b
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.0
data/.travis.yml CHANGED
@@ -1,10 +1,4 @@
1
+ sudo: false
1
2
  script: "bundle exec rspec"
2
3
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
6
- - rbx
7
- - rbx-2.0
8
- - ree
9
- - ruby-head
10
- - jruby
4
+ - 2.3.0
data/Gemfile.lock CHANGED
@@ -1,32 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- whitelabel (0.2.0)
4
+ whitelabel (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- coderay (1.0.6)
10
- diff-lcs (1.1.3)
11
- method_source (0.7.1)
12
- pry (0.9.8.4)
13
- coderay (~> 1.0.5)
14
- method_source (~> 0.7.1)
15
- slop (>= 2.4.4, < 3)
16
- rspec (2.9.0)
17
- rspec-core (~> 2.9.0)
18
- rspec-expectations (~> 2.9.0)
19
- rspec-mocks (~> 2.9.0)
20
- rspec-core (2.9.0)
21
- rspec-expectations (2.9.1)
22
- diff-lcs (~> 1.1.3)
23
- rspec-mocks (2.9.0)
24
- slop (2.4.4)
9
+ byebug (11.1.3)
10
+ diff-lcs (1.5.0)
11
+ rake (13.0.6)
12
+ rspec (3.12.0)
13
+ rspec-core (~> 3.12.0)
14
+ rspec-expectations (~> 3.12.0)
15
+ rspec-mocks (~> 3.12.0)
16
+ rspec-core (3.12.1)
17
+ rspec-support (~> 3.12.0)
18
+ rspec-expectations (3.12.2)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.12.0)
21
+ rspec-mocks (3.12.5)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.12.0)
24
+ rspec-support (3.12.0)
25
25
 
26
26
  PLATFORMS
27
- ruby
27
+ arm64-darwin-21
28
28
 
29
29
  DEPENDENCIES
30
- pry (~> 0.9)
31
- rspec (~> 2.9)
30
+ byebug (> 11.0)
31
+ rake (> 11.3)
32
+ rspec (> 3.1)
32
33
  whitelabel!
34
+
35
+ BUNDLED WITH
36
+ 2.4.10
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/phoet/whitelabel.svg?branch=master)](https://travis-ci.org/phoet/whitelabel)
2
+
1
3
  # Whitelabel
2
4
 
3
5
  This gem helps you providing whitelabel functionality in your application.
@@ -6,15 +8,21 @@ This gem helps you providing whitelabel functionality in your application.
6
8
 
7
9
  Add this line to your application's Gemfile:
8
10
 
9
- gem 'whitelabel'
11
+ ```ruby
12
+ gem 'whitelabel'
13
+ ```
10
14
 
11
15
  And then execute:
12
16
 
13
- $ bundle
17
+ ```bash
18
+ bundle install
19
+ ```
14
20
 
15
21
  Or install it yourself as:
16
22
 
17
- $ gem install whitelabel
23
+ ```bash
24
+ gem install whitelabel
25
+ ```
18
26
 
19
27
  ## Usage
20
28
 
@@ -22,28 +30,34 @@ You can start with a pretty simple, file driven whitelabel configuration.
22
30
 
23
31
  All you need is a config file:
24
32
 
25
- # config/whitelabel.yaml
26
- ---
27
- - !ruby/struct:YourLabelClass
28
- label_id: "white"
29
- some_config: "for your application"
33
+ ```yaml
34
+ # config/whitelabel.yaml
35
+ ---
36
+ - !ruby/struct:YourLabelClass
37
+ label_id: "white"
38
+ some_config: "for your application"
39
+ ```
30
40
 
31
41
  and an initializer:
32
42
 
33
- # config/initializers/whitelabel.rb
34
- YourLabelClass = Struct.new :label_id, :some_config
35
- Whitelabel.from_file Rails.root.join("config/whitelabel.yml")
43
+ ```ruby
44
+ # config/initializers/whitelabel.rb
45
+ YourLabelClass = Struct.new :label_id, :some_config
46
+ Whitelabel.from_file Rails.root.join("config/whitelabel.yml")
47
+ ```
36
48
 
37
49
  Whitelabel works the same way I18n does, just set it up in your ApplicationController:
38
50
 
51
+ ```ruby
39
52
  # app/controllers/application_controller.rb
40
53
  before_filter :switch_label
41
54
 
42
55
  def switch_label
43
56
  unless Whitelabel.label_for(request.subdomains.first)
44
- redirect_to(labels_url(subdomain: false), alert: "Please select a Label!") and return
57
+ redirect_to(labels_url(subdomain: false), alert: "Please select a Label!")
45
58
  end
46
59
  end
60
+ ```
47
61
 
48
62
  This example uses the subdomain to determine which label should be active, but you can implement whatever you like here.
49
63
 
@@ -0,0 +1,48 @@
1
+ module Whitelabel
2
+ module Handler
3
+ attr_accessor :labels
4
+
5
+ def from_file(path)
6
+ @labels = File.open(path) { |file| YAML.unsafe_load(file) }
7
+ end
8
+
9
+ def label
10
+ Thread.current[:whitelabel]
11
+ end
12
+
13
+ def label=(label)
14
+ Thread.current[:whitelabel] = label
15
+ end
16
+
17
+ def label_for(pattern, identifier = :label_id)
18
+ self.label = find_label(pattern, identifier)
19
+ end
20
+
21
+ def find_label(pattern, identifier = :label_id)
22
+ @labels.find { |label| label.send(identifier) =~ /^#{pattern}$/ }
23
+ end
24
+
25
+ def with_label(tmp = nil)
26
+ if tmp
27
+ current_label = self.label
28
+ self.label = tmp
29
+ end
30
+ yield
31
+ ensure
32
+ self.label = current_label if current_label
33
+ end
34
+
35
+ def each_label(&block)
36
+ labels.map { |label| with_label(label, &block) }
37
+ end
38
+
39
+ def [](accessor)
40
+ raise "set a label before calling '#{accessor}'" if self.label.nil?
41
+ self.label.send :"#{accessor}"
42
+ end
43
+
44
+ def reset!
45
+ Thread.current[:whitelabel] = nil
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Whitelabel
2
- VERSION = "0.2.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/whitelabel.rb CHANGED
@@ -1,48 +1,10 @@
1
1
  require "whitelabel/version"
2
+ require "whitelabel/handler"
2
3
 
3
4
  require "yaml"
4
5
 
5
6
  module Whitelabel
6
7
  class << self
7
- attr_accessor :labels
8
-
9
- def from_file(path)
10
- @labels = File.open(path) { |file| YAML.load(file) }
11
- end
12
-
13
- def label
14
- Thread.current[:whitelabel]
15
- end
16
-
17
- def label=(label)
18
- Thread.current[:whitelabel] = label
19
- end
20
-
21
- def label_for(pattern, identifier=:label_id)
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
37
- end
38
-
39
- def [](accessor)
40
- raise "set a label before calling '#{accessor}'" if self.label.nil?
41
- self.label.send :"#{accessor}"
42
- end
43
-
44
- def reset!
45
- Thread.current[:whitelabel] = nil
46
- end
8
+ include Whitelabel::Handler
47
9
  end
48
10
  end
@@ -21,57 +21,64 @@ describe Whitelabel do
21
21
  Whitelabel.from_file(path)
22
22
  end
23
23
 
24
- it "should have two different labels" do
25
- Whitelabel.find_label('test')[:label_id].should eql('test')
26
- Whitelabel.find_label('uschi')[:label_id].should eql('uschi')
27
- Whitelabel.find_label('wrong').should be_nil
24
+ it "finds two different labels" do
25
+ expect(Whitelabel.find_label('test')[:label_id]).to eql('test')
26
+ expect(Whitelabel.find_label('uschi')[:label_id]).to eql('uschi')
27
+ expect(Whitelabel.find_label('wrong')).to be_nil
28
28
  end
29
29
 
30
- it "should work thread safe" do
30
+ it "works thread safe" do
31
31
  Whitelabel.label = :bla
32
32
  Thread.new { Whitelabel.label = nil }
33
- Whitelabel.label.should_not be_nil
33
+ expect(Whitelabel.label).to_not be_nil
34
34
  end
35
35
 
36
- it "should find a label for a pattern" do
37
- Whitelabel.label_for('uschi').should_not be_nil
38
- Whitelabel.label.name.should eql('Uschi Müller')
36
+ it "finds a label for a pattern" do
37
+ expect(Whitelabel.label_for('uschi')).to_not be_nil
38
+ expect(Whitelabel.label.name).to eql('Uschi Müller')
39
39
  end
40
40
 
41
- it "should not find a label for a missing pattern" do
42
- Whitelabel.label_for('').should be_nil
41
+ it "does not find a label for a missing pattern" do
42
+ expect(Whitelabel.label_for('')).to be_nil
43
43
  end
44
44
 
45
- it "should enable a temporary label" do
45
+ it "enables a temporary label" do
46
46
  label = Whitelabel.label_for('uschi')
47
- Whitelabel.label.should eql(label)
47
+ expect(Whitelabel.label).to eql(label)
48
48
  tmp = Whitelabel.find_label('test')
49
49
  Whitelabel.with_label(tmp) do
50
- Whitelabel.label.should eql(tmp)
50
+ expect(Whitelabel.label).to eql(tmp)
51
51
  end
52
- Whitelabel.label.should eql(label)
52
+ expect(Whitelabel.label).to eql(label)
53
53
  end
54
54
 
55
- it "should throw a meaningfull error when no label is set" do
55
+ it "throws a meaningfull error when no label is set" do
56
56
  expect { Whitelabel[:blame] }.to raise_error("set a label before calling 'blame'")
57
57
  end
58
58
 
59
+ context "each_label" do
60
+ it "iterates all labels" do
61
+ names = Whitelabel.each_label { Whitelabel[:name] }
62
+ expect(names).to eql(["bla", "Uschi Müller"])
63
+ end
64
+ end
65
+
59
66
  context "with current label" do
60
67
  before(:each) do
61
68
  Whitelabel.label = dummy
62
69
  end
63
70
 
64
71
  context "resetting" do
65
- it "should reset the current label" do
66
- Whitelabel.label.should be(dummy)
72
+ it "resets the current label" do
73
+ expect(Whitelabel.label).to be(dummy)
67
74
  Whitelabel.reset!
68
- Whitelabel.label.should be_nil
75
+ expect(Whitelabel.label).to be_nil
69
76
  end
70
77
  end
71
78
 
72
79
  context "accessing values" do
73
- it "should access a label property via []" do
74
- Whitelabel[:name].should eql('some_name')
80
+ it "accesses a label property via []" do
81
+ expect(Whitelabel[:name]).to eql('some_name')
75
82
  end
76
83
  end
77
84
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  require "whitelabel"
2
-
3
- require "pry"
2
+ require "byebug"
4
3
 
5
4
  RSpec.configure do |config|
6
- config.treat_symbols_as_metadata_keys_with_true_values = true
7
5
  config.run_all_when_everything_filtered = true
8
6
  config.filter_run :focus
9
7
  end
data/whitelabel.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  require File.expand_path('../lib/whitelabel/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Peter Schröder"]
5
+ gem.authors = ["Peter Schröder"]
6
6
  gem.email = ["phoetmail@googlemail.com"]
7
7
  gem.description = gem.summary = %q{This gem helps you providing whitelabel functionality in your application}
8
8
  gem.homepage = "https://github.com/phoet/whitelabel"
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ["lib"]
15
15
  gem.version = Whitelabel::VERSION
16
16
 
17
- gem.add_development_dependency('rspec', '~> 2.9')
18
- gem.add_development_dependency('pry', '~> 0.9')
17
+ gem.add_development_dependency('rspec', '> 3.1')
18
+ gem.add_development_dependency('byebug', '> 11.0')
19
+ gem.add_development_dependency('rake', '> 11.3')
19
20
  end
metadata CHANGED
@@ -1,48 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whitelabel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
- - Peter Schröder
9
- autorequire:
7
+ - Peter Schröder
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-23 00:00:00.000000000 Z
11
+ date: 2023-04-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - ">"
20
18
  - !ruby/object:Gem::Version
21
- version: '2.9'
19
+ version: '3.1'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - ">"
28
25
  - !ruby/object:Gem::Version
29
- version: '2.9'
26
+ version: '3.1'
30
27
  - !ruby/object:Gem::Dependency
31
- name: pry
28
+ name: byebug
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - ">"
36
32
  - !ruby/object:Gem::Version
37
- version: '0.9'
33
+ version: '11.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - ">"
44
39
  - !ruby/object:Gem::Version
45
- version: '0.9'
40
+ version: '11.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '11.3'
46
55
  description: This gem helps you providing whitelabel functionality in your application
47
56
  email:
48
57
  - phoetmail@googlemail.com
@@ -50,16 +59,17 @@ executables: []
50
59
  extensions: []
51
60
  extra_rdoc_files: []
52
61
  files:
53
- - .document
54
- - .gitignore
55
- - .rspec
56
- - .rvmrc
57
- - .travis.yml
62
+ - ".document"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".ruby-version"
66
+ - ".travis.yml"
58
67
  - Gemfile
59
68
  - Gemfile.lock
60
69
  - README.md
61
70
  - Rakefile
62
71
  - lib/whitelabel.rb
72
+ - lib/whitelabel/handler.rb
63
73
  - lib/whitelabel/version.rb
64
74
  - spec/fixtures/whitelabel.yml
65
75
  - spec/lib/whitelabel_spec.rb
@@ -67,27 +77,25 @@ files:
67
77
  - whitelabel.gemspec
68
78
  homepage: https://github.com/phoet/whitelabel
69
79
  licenses: []
70
- post_install_message:
80
+ metadata: {}
81
+ post_install_message:
71
82
  rdoc_options: []
72
83
  require_paths:
73
84
  - lib
74
85
  required_ruby_version: !ruby/object:Gem::Requirement
75
- none: false
76
86
  requirements:
77
- - - ! '>='
87
+ - - ">="
78
88
  - !ruby/object:Gem::Version
79
89
  version: '0'
80
90
  required_rubygems_version: !ruby/object:Gem::Requirement
81
- none: false
82
91
  requirements:
83
- - - ! '>='
92
+ - - ">="
84
93
  - !ruby/object:Gem::Version
85
94
  version: '0'
86
95
  requirements: []
87
- rubyforge_project:
88
- rubygems_version: 1.8.24
89
- signing_key:
90
- specification_version: 3
96
+ rubygems_version: 3.4.10
97
+ signing_key:
98
+ specification_version: 4
91
99
  summary: This gem helps you providing whitelabel functionality in your application
92
100
  test_files:
93
101
  - spec/fixtures/whitelabel.yml
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.3@whitelabel --create