rack-dev-mark 0.6.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzFjOWI5ZjJlNDdiODE0ZWY3NDM3NzE2NjdkODk2OGI3MWNiZDBiOQ==
4
+ M2VlN2RhM2Y4NWFiNmUyM2IwMDEwY2IxOWQ1YjUxNDk0NGFlNzc2NA==
5
5
  data.tar.gz: !binary |-
6
- YmZkNjY3MjZlMmRiZTk3NTU4N2Q5YzMyYWNlNWIwM2U4ZTg1MzQ1NQ==
6
+ YjFkMTc4YzY4ZTRhMTk4MTc1MDY1MmQ4YjMyYjVlNWViY2JiMDRkMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjM4ZDUzM2Y1N2FmMDJlYjBkNzQ3MjkyY2U3NzVlZDZiOWJiZTQzOTU1ZjIy
10
- ZTgwNjgxNmVkYmU2ZTI3ZTZhMmZhY2FjYzE0ZWM1Nzc2M2NiYTlmZjUyNTI1
11
- NDE4OTVhZWQwMDdhOWY3YWJhZGQ3ODE5MmU5NzYyZDNhNGRmMTc=
9
+ YjA4ZjQ2N2Q0ZDUxNTg2MWQ4NGZjYzA4ZDM3ZTRjYmIwOWY1ODJjNmU0MjMw
10
+ MDYyZjhlYWZmZjQwOGQyYzQ0YTE1ZWYwODIzNTg2YzcxYzU5OWZjMGMwMjBl
11
+ NmI4N2I3YWExMTg3NTVhYWZkNDBhYjE0Mzk1MTczODE1YzUxNzI=
12
12
  data.tar.gz: !binary |-
13
- ZWI3Mzc0NTk3M2VlNzhjNmM1MDJjNTA5NzJhZjEzYzI2ZDBkNjYzMzkyMzI2
14
- NDg2MjlkZDNmMzY3NzYyMWM3YjEzYjcwOGRjZTZlNDEzNzU4YTk2ZmVjYzU4
15
- MjhlNTg2YTc2NGM2YzYzMTgyMjM3MDg0YjNhODNkMmM4MTgxYjA=
13
+ YzBkZTFhYWQzYmVkNjRlY2RkNzExNDNiOWQyYzk5NGYxYWVkOWJhNmQzNWJm
14
+ M2Q3NTc2Y2MyMzEwMGRkMGY1NmI0ZjUzZGNjOTFiNzRlMTdiYjIyYmFjMmM1
15
+ MmM4ZWU0ZjFkMDMxNTAxZWVkODU2ZWZhNDk3YjcyODg4MTEzNTA=
data/.travis.yml CHANGED
@@ -3,16 +3,17 @@ language: ruby
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - 2.1.0
7
- gemfile:
8
- - gemfiles/gemfile
9
- - gemfiles/rack.1.4.x.gemfile
10
- - gemfiles/rack.1.3.x.gemfile
11
- - gemfiles/rack.1.2.x.gemfile
12
- - gemfiles/rack.1.1.x.gemfile
13
- - gemfiles/rails.3.2.x.gemfile
14
- - gemfiles/rails.4.0.x.gemfile
15
- - gemfiles/rails.4.1.x.gemfile
6
+ - 2.1
7
+
8
+ env:
9
+ -
10
+ - RACK_VERSION=1.1.0
11
+ - RACK_VERSION=1.2.0
12
+ - RACK_VERSION=1.3.0
13
+ - RACK_VERSION=1.4.0
14
+ - RAILS_VERSION=3.2.0
15
+ - RAILS_VERSION=4.0.0
16
+ - RAILS_VERSION=4.1.0
16
17
 
17
18
  script: "bundle exec rake spec"
18
19
 
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem "rack", "~> #{ENV['RACK_VERSION']}" if ENV['RACK_VERSION'].to_s != ''
4
+ gem "rails", "~> #{ENV['RAILS_VERSION']}" if ENV['RAILS_VERSION'].to_s != ''
5
+
3
6
  gemspec
data/README.md CHANGED
@@ -44,7 +44,7 @@ run MyApp
44
44
  In `config/environments/development.rb`
45
45
 
46
46
  ```ruby
47
- MyApp::Application.configure do
47
+ Rails.application.configure do
48
48
  config.rack_dev_mark.enable = true
49
49
  end
50
50
  ```
@@ -83,25 +83,16 @@ module MyApp
83
83
  end
84
84
  ```
85
85
 
86
- #### Heroku
86
+ #### Rails on Heroku
87
87
 
88
- Since Heroku [uses production env for staging](https://devcenter.heroku.com/articles/multiple-environments). You can use this settings instead.
89
-
90
- ```ruby
91
- module MyApp
92
- class Application < Rails::Application
93
- Rack::DevMark.env = ENV['RACK_DEV_MARK']
94
- config.rack_dev_mark.enable = !Rails.env.production? || ENV['RACK_DEV_MARK']
95
- end
96
- end
97
- ```
98
-
99
- And set the environment variable.
88
+ Since Heroku [uses production env for staging](https://devcenter.heroku.com/articles/multiple-environments). You can't use the settings above. However, the gem provide an easier way to set it up on Heroku. Just set the environment variable on the environment in which you want to show the mark.
100
89
 
101
90
  ```bash
102
- heroku config:set RACK_DEV_MARK=staging
91
+ heroku config:set RACK_DEV_MARK_ENV=staging
103
92
  ```
104
93
 
94
+ That's it!
95
+
105
96
  ## Custom Theme
106
97
 
107
98
  Although the default themes are `title` and `github_fork_ribbon`, you can create your own themes inheriting `Rack::DevMark::Theme::Base`.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.2
data/lib/rack/dev-mark.rb CHANGED
@@ -7,28 +7,35 @@ require 'rack/dev-mark/version'
7
7
 
8
8
  module Rack
9
9
  module DevMark
10
- def self.env
11
- @env ||= ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
12
- end
10
+ class << self
11
+ def env
12
+ @env ||= rack_dev_mark_env || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
13
+ end
13
14
 
14
- def self.env=(env)
15
- @env = env
16
- end
15
+ def env=(env)
16
+ @env = env
17
+ end
17
18
 
18
- def self.revision
19
- @revision ||= (::File.open('REVISION') { |f| f.read.strip } rescue nil)
20
- end
19
+ def revision
20
+ @revision ||= (::File.open('REVISION') { |f| f.read.strip } rescue nil)
21
+ end
21
22
 
22
- def self.revision=(revision)
23
- @revision = revision
24
- end
23
+ def revision=(revision)
24
+ @revision = revision
25
+ end
25
26
 
26
- def self.timestamp
27
- @timestamp ||= (::File.open('REVISION') { |f| f.ctime } rescue nil)
28
- end
27
+ def timestamp
28
+ @timestamp ||= (::File.open('REVISION') { |f| f.mtime } rescue nil)
29
+ end
30
+
31
+ def timestamp=(timestamp)
32
+ @timestamp = timestamp.is_a?(Time) ? timestamp : Time.parse(timestamp)
33
+ end
29
34
 
30
- def self.timestamp=(timestamp)
31
- @timestamp = timestamp
35
+ def rack_dev_mark_env
36
+ s = ENV['RACK_DEV_MARK_ENV']
37
+ s.to_s == '' ? nil : s
38
+ end
32
39
  end
33
40
  end
34
41
  end
@@ -6,7 +6,7 @@ module Rack
6
6
  config.rack_dev_mark = ActiveSupport::OrderedOptions.new
7
7
 
8
8
  initializer "rack-dev-mark.configure_rails_initialization" do |app|
9
- if app.config.rack_dev_mark.enable
9
+ if app.config.rack_dev_mark.enable || Rack::DevMark.rack_dev_mark_env
10
10
  racks = [ActionDispatch::ShowExceptions, Rack::DevMark::Middleware]
11
11
  if theme = app.config.rack_dev_mark.theme || app.config.rack_dev_mark.custom_theme
12
12
  racks << theme
@@ -5,6 +5,6 @@ module Rack
5
5
  end
6
6
  end
7
7
 
8
- Dir[File.join(File.dirname(__FILE__), 'theme', '*.rb')].each do |f|
8
+ Dir[::File.join(::File.dirname(__FILE__), 'theme', '*.rb')].each do |f|
9
9
  require f
10
10
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module DevMark
3
- VERSION = '0.6.0'
3
+ VERSION = ::File.read(::File.expand_path('../../../../VERSION', __FILE__)).to_s.strip
4
4
  end
5
5
  end
@@ -7,8 +7,8 @@ Gem::Specification.new do |gem|
7
7
  gem.authors = ["Daisuke Taniwaki"]
8
8
  gem.email = ["daisuketaniwaki@gmail.com"]
9
9
  gem.homepage = "https://github.com/dtaniwaki/rack-dev-mark"
10
- gem.summary = "Differentiate development environemt from production"
11
- gem.description = "Differentiate development environemt from production"
10
+ gem.summary = "Differentiate development environment from production"
11
+ gem.description = "Differentiate development environment from production"
12
12
  gem.license = "MIT"
13
13
 
14
14
  gem.files = `git ls-files`.split("\n")
@@ -12,29 +12,38 @@ describe Rack::DevMark::Railtie do
12
12
  context "rack_dev_mark enable" do
13
13
  before do
14
14
  @app.config.rack_dev_mark.enable = true
15
- @app.initialize!
16
15
  end
17
16
  it 'inserts the middleware' do
17
+ @app.initialize!
18
18
  expect(@app.middleware.middlewares).to include(Rack::DevMark::Middleware)
19
19
  end
20
20
  end
21
21
  context "rack_dev_mark disable" do
22
22
  before do
23
23
  @app.config.rack_dev_mark.enable = false
24
- @app.initialize!
25
24
  end
26
25
  it 'does not insert the middleware' do
26
+ @app.initialize!
27
27
  expect(@app.middleware.middlewares).not_to include(Rack::DevMark::Middleware)
28
28
  end
29
+ context "with rack_dev_mark_env" do
30
+ before do
31
+ ENV['RACK_DEV_MARK_ENV'] = 'test'
32
+ end
33
+ it 'inserts the middleware' do
34
+ @app.initialize!
35
+ expect(@app.middleware.middlewares).to include(Rack::DevMark::Middleware)
36
+ end
37
+ end
29
38
  end
30
39
  context "rack_dev_mark theme" do
31
40
  let(:theme) { d = double setup: nil; allow(d).to receive(:insert_into){ |b| "#{b} dev-mark" }; d }
32
41
  before do
33
42
  @app.config.rack_dev_mark.enable = true
34
43
  @app.config.rack_dev_mark.theme = [theme]
35
- @app.initialize!
36
44
  end
37
45
  it 'inserts the middleware' do
46
+ @app.initialize!
38
47
  expect(theme).to receive(:setup)
39
48
  end
40
49
  end
@@ -43,9 +52,9 @@ describe Rack::DevMark::Railtie do
43
52
  before do
44
53
  @app.config.rack_dev_mark.enable = true
45
54
  @app.config.rack_dev_mark.custom_theme = [theme]
46
- @app.initialize!
47
55
  end
48
56
  it 'inserts the middleware' do
57
+ @app.initialize!
49
58
  expect(theme).to receive(:setup)
50
59
  end
51
60
  end
@@ -27,6 +27,12 @@ describe Rack::DevMark do
27
27
  ENV['RAILS_ENV'] = 'def'
28
28
  expect(subject.env).to eq('def')
29
29
  end
30
+ it "returns rack_dev_mark_env instead of rails_env" do
31
+ ENV['RACK_ENV'] = 'abc'
32
+ ENV['RAILS_ENV'] = 'def'
33
+ ENV['RACK_DEV_MARK_ENV'] = 'ghi'
34
+ expect(subject.env).to eq('ghi')
35
+ end
30
36
  end
31
37
  describe "::env=" do
32
38
  it "sets custom env" do
@@ -55,4 +61,43 @@ describe Rack::DevMark do
55
61
  expect(subject.revision).to eq('custom')
56
62
  end
57
63
  end
64
+ describe "::timestamp" do
65
+ let(:time) { Time.new(2000, 1, 2) }
66
+ after do
67
+ ::File.delete('REVISION') if ::File.exists?('REVISION')
68
+ subject.instance_variable_set("@timestamp", nil)
69
+ end
70
+ it "returns timestamp" do
71
+ ::FileUtils.touch 'REVISION', mtime: time
72
+ expect(subject.timestamp).to eq(time)
73
+ end
74
+ it "returns nil if REVISION does not exist" do
75
+ expect(subject.timestamp).to eq(nil)
76
+ end
77
+ end
78
+ describe "::timestamp=" do
79
+ it "sets custom timestamp by string" do
80
+ subject.timestamp = '2014/3/1'
81
+ expect(subject.timestamp).to eq(Time.new(2014, 3, 1))
82
+ end
83
+
84
+ it "sets custom timestamp by time object" do
85
+ subject.timestamp = Time.new(2014, 4, 1)
86
+ expect(subject.timestamp).to eq(Time.new(2014, 4, 1))
87
+ end
88
+ end
89
+ describe "::rack_dev_mark_env" do
90
+ it "returns nil" do
91
+ ENV['RACK_DEV_MARK_ENV'] = nil
92
+ expect(subject.rack_dev_mark_env).to eq(nil)
93
+ end
94
+ it "returns nil" do
95
+ ENV['RACK_DEV_MARK_ENV'] = ''
96
+ expect(subject.rack_dev_mark_env).to eq(nil)
97
+ end
98
+ it "returns custom value" do
99
+ ENV['RACK_DEV_MARK_ENV'] = 'abc'
100
+ expect(subject.env).to eq('abc')
101
+ end
102
+ end
58
103
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-dev-mark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daisuke Taniwaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-06 00:00:00.000000000 Z
11
+ date: 2014-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: Differentiate development environemt from production
69
+ description: Differentiate development environment from production
70
70
  email:
71
71
  - daisuketaniwaki@gmail.com
72
72
  executables: []
@@ -80,14 +80,7 @@ files:
80
80
  - README.md
81
81
  - Rakefile
82
82
  - THEME.md
83
- - gemfiles/gemfile
84
- - gemfiles/rack.1.1.x.gemfile
85
- - gemfiles/rack.1.2.x.gemfile
86
- - gemfiles/rack.1.3.x.gemfile
87
- - gemfiles/rack.1.4.x.gemfile
88
- - gemfiles/rails.3.2.x.gemfile
89
- - gemfiles/rails.4.0.x.gemfile
90
- - gemfiles/rails.4.1.x.gemfile
83
+ - VERSION
91
84
  - lib/generators/rack/dev-mark/install_generator.rb
92
85
  - lib/rack-dev-mark.rb
93
86
  - lib/rack/dev-mark.rb
@@ -145,7 +138,7 @@ rubyforge_project:
145
138
  rubygems_version: 2.2.2
146
139
  signing_key:
147
140
  specification_version: 4
148
- summary: Differentiate development environemt from production
141
+ summary: Differentiate development environment from production
149
142
  test_files:
150
143
  - spec/generators/rack/dev-mark/install_generator_spec.rb
151
144
  - spec/rack/dev-mark/middleware_spec.rb
data/gemfiles/gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec :path => '../'
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'rack', '~> 1.1.0'
4
- gemspec :path => '../'
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'rack', '~> 1.2.0'
4
- gemspec :path => '../'
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'rack', '~> 1.3.0'
4
- gemspec :path => '../'
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'rack', '~> 1.4.0'
4
- gemspec :path => '../'
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'rails', '~> 3.2'
4
- gemspec :path => '../'
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'rails', '~> 4.0'
4
- gemspec :path => '../'
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'rails', '~> 4.1'
4
- gemspec :path => '../'