exvo_helpers 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,15 +7,25 @@ Ruby gem providing helper methods for various Exvo apps/services. It takes into
7
7
  Results are from the 'development' Rails environment:
8
8
 
9
9
  ```ruby
10
- Exvo::Helpers.cdn_host => 'www.exvo.local'
11
- Exvo::Helpers.cfs_host => 'cfs.exvo.local'
12
- Exvo::Helpers.desktop_host => 'www.exvo.local'
13
- Exvo::Helpers.themes_host => 'themes.exvo.local'
10
+ Exvo::Helpers.cdn_host => 'www.exvo.local'
11
+ Exvo::Helpers.cfs_host => 'cfs.exvo.local'
12
+ Exvo::Helpers.desktop_host => 'www.exvo.local'
13
+ Exvo::Helpers.themes_host => 'themes.exvo.local'
14
+ Exvo::Helpers.blog_host => 'blog.exvo.local'
15
+ Exvo::Helpers.contacts_host => 'contacts.exvo.local'
16
+ Exvo::Helpers.inbox_host => 'inbox.exvo.local'
17
+ Exvo::Helpers.music_host => 'music.exvo.local'
18
+ Exvo::Helpers.pics_host => 'pics.exvo.local'
14
19
 
15
20
  Exvo::Helpers.cdn_uri => 'http://www.exvo.local'
16
21
  Exvo::Helpers.cfs_uri => 'http://cfs.exvo.local'
17
22
  Exvo::Helpers.desktop_uri => 'http://www.exvo.local'
18
23
  Exvo::Helpers.themes_uri => 'http://themes.exvo.local'
24
+ Exvo::Helpers.blog_uri => 'http://blog.exvo.local'
25
+ Exvo::Helpers.contacts_uri => 'http://contacts.exvo.local'
26
+ Exvo::Helpers.inbox_uri => 'http://inbox.exvo.local'
27
+ Exvo::Helpers.music_uri => 'http://music.exvo.local'
28
+ Exvo::Helpers.pics_uri => 'http://pics.exvo.local'
19
29
  ```
20
30
 
21
31
  For consistency, there are also read-only `auth_host/auth_uri` methods, that just pass execution to the [exvo-auth](https://github.com/Exvo/Auth) gem (so it's required that exvo-auth gem is available when using them):
@@ -31,19 +41,29 @@ Exvo::Helpers.auth_uri => 'http://exvo.auth.local'
31
41
  There are two ways to do it. One is by the means of ENV variables (preferred one):
32
42
 
33
43
  ```ruby
34
- ENV['CDN_HOST'] = 'test.cdn.exvo.com'
35
- ENV['CFS_HOST'] = 'test.cfs.exvo.com'
36
- ENV['DESKTOP_HOST'] = 'test.exvo.com'
37
- ENV['THEMES_HOST'] = 'test.themes.exvo.com'
44
+ ENV['CDN_HOST'] = 'test.cdn.exvo.com'
45
+ ENV['CFS_HOST'] = 'test.cfs.exvo.com'
46
+ ENV['DESKTOP_HOST'] = 'test.exvo.com'
47
+ ENV['THEMES_HOST'] = 'test.themes.exvo.com'
48
+ ENV['BLOG_HOST'] = 'test.blog.exvo.local'
49
+ ENV['CONTACTS_HOST'] = 'test.contacts.exvo.local'
50
+ ENV['INBOX_HOST'] = 'test.inbox.exvo.local'
51
+ ENV['MUSIC_HOST'] = 'test.music.exvo.local'
52
+ ENV['PICS_HOST'] = 'test.pics.exvo.local'
38
53
  ```
39
54
 
40
55
  The other one is to set it in the application's config file:
41
56
 
42
57
  ```ruby
43
- Exvo::Helpers.cdn_host = 'test.cfs.exvo.com'
44
- Exvo::Helpers.cfs_host = 'test.cfs.exvo.com'
45
- Exvo::Helpers.desktop_host = 'test.exvo.com'
46
- Exvo::Helpers.themes_host = 'test.themes.exvo.com'
58
+ Exvo::Helpers.cdn_host = 'test.cfs.exvo.com'
59
+ Exvo::Helpers.cfs_host = 'test.cfs.exvo.com'
60
+ Exvo::Helpers.desktop_host = 'test.exvo.com'
61
+ Exvo::Helpers.themes_host = 'test.themes.exvo.com'
62
+ Exvo::Helpers.blog_host = 'test.blog.exvo.local'
63
+ Exvo::Helpers.contacts_host = 'test.contacts.exvo.local'
64
+ Exvo::Helpers.inbox_host = 'test.inbox.exvo.local'
65
+ Exvo::Helpers.music_host = 'test.music.exvo.local'
66
+ Exvo::Helpers.pics_host = 'test.pics.exvo.local'
47
67
  ```
48
68
 
49
69
 
@@ -2,63 +2,40 @@ module Exvo
2
2
 
3
3
  module Helpers
4
4
 
5
- # CDN BUNDLES
5
+ # Dynamically define class methods
6
+ class << self
7
+
8
+ %w(cdn cfs desktop themes blog contacts inbox music pics).each do |service|
9
+
10
+ # def self.cdn_uri
11
+ # "http://#{cdn_host}"
12
+ # end
13
+ define_method "#{service}_uri" do
14
+ "http://#{ send("#{service}_host") }"
15
+ end
16
+
17
+ # def self.cdn_host
18
+ # @@cdn_host ||= ENV['CDN_HOST'] || default_opts[env.to_sym][:cdn_host]
19
+ # end
20
+ define_method "#{service}_host" do
21
+ # poor man's metaprogramming memoization - if it's defined (and not nil!) return it; if not, set it
22
+ if class_variable_defined?("@@#{service}_host") and class_variable_get("@@#{service}_host")
23
+ class_variable_get("@@#{service}_host")
24
+ else
25
+ host = ENV["#{service.upcase}_HOST"] || default_opts[env.to_sym]["#{service}_host".to_sym]
26
+ class_variable_set("@@#{service}_host", host)
27
+ end
28
+ end
29
+
30
+ # def self.cdn_host=(host)
31
+ # @@cdn_host = host
32
+ # end
33
+ define_method "#{service}_host=" do |host|
34
+ class_variable_set("@@#{service}_host", host)
35
+ end
6
36
 
7
- def self.cdn_uri
8
- "http://#{cdn_host}"
9
- end
10
-
11
- def self.cdn_host
12
- @@cdn_host ||= ENV['CDN_HOST'] || default_opts[env.to_sym][:cdn_host]
13
- end
14
-
15
- def self.cdn_host=(host)
16
- @@cdn_host = host
17
- end
18
-
19
-
20
- # CFS
21
-
22
- def self.cfs_uri
23
- "http://#{cfs_host}"
24
- end
25
-
26
- def self.cfs_host
27
- @@cfs_host ||= ENV['CFS_HOST'] || default_opts[env.to_sym][:cfs_host]
28
- end
29
-
30
- def self.cfs_host=(host)
31
- @@cfs_host = host
32
- end
33
-
34
-
35
- # DESKTOP
36
-
37
- def self.desktop_uri
38
- "http://#{desktop_host}"
39
- end
40
-
41
- def self.desktop_host
42
- @@desktop_host ||= ENV['DESKTOP_HOST'] || default_opts[env.to_sym][:desktop_host]
43
- end
44
-
45
- def self.desktop_host=(host)
46
- @@desktop_host = host
47
- end
48
-
49
-
50
- # THEMES
51
-
52
- def self.themes_uri
53
- "http://#{themes_host}"
54
- end
55
-
56
- def self.themes_host
57
- @@themes_host ||= ENV['THEMES_HOST'] || default_opts[env.to_sym][:themes_host]
58
- end
37
+ end
59
38
 
60
- def self.themes_host=(host)
61
- @@themes_host = host
62
39
  end
63
40
 
64
41
 
@@ -103,25 +80,45 @@ module Exvo
103
80
  :cdn_host => 'cdn.exvo.com',
104
81
  :cfs_host => 'cfs.exvo.com',
105
82
  :desktop_host => 'www.exvo.com',
106
- :themes_host => 'themes.exvo.com'
83
+ :themes_host => 'themes.exvo.com',
84
+ :blog_host => 'blog.exvo.com',
85
+ :contacts_host => 'contacts.exvo.com',
86
+ :inbox_host => 'inbox.exvo.com',
87
+ :music_host => 'music.exvo.com',
88
+ :pics_host => 'pics.exvo.com'
107
89
  },
108
90
  :staging => {
109
91
  :cdn_host => 'staging.cdn.exvo.com',
110
92
  :cfs_host => 'staging.cfs.exvo.com',
111
93
  :desktop_host => 'www.exvo.co',
112
- :themes_host => 'staging.themes.exvo.com'
94
+ :themes_host => 'staging.themes.exvo.com',
95
+ :blog_host => 'staging.blog.exvo.com',
96
+ :contacts_host => 'exvo-contacts-staging.heroku.com',
97
+ :inbox_host => 'exvo-inbox-staging.heroku.com',
98
+ :music_host => 'exvo-music-staging.heroku.com',
99
+ :pics_host => 'exvo-pictures-staging.heroku.com'
113
100
  },
114
101
  :development => {
115
102
  :cdn_host => 'www.exvo.local',
116
103
  :cfs_host => 'cfs.exvo.local',
117
104
  :desktop_host => 'www.exvo.local',
118
- :themes_host => 'themes.exvo.local'
105
+ :themes_host => 'themes.exvo.local',
106
+ :blog_host => 'blog.exvo.local',
107
+ :contacts_host => 'contacts.exvo.local',
108
+ :inbox_host => 'inbox.exvo.local',
109
+ :music_host => 'music.exvo.local',
110
+ :pics_host => 'pics.exvo.local'
119
111
  },
120
112
  :test => {
121
113
  :cdn_host => 'www.exvo.local',
122
114
  :cfs_host => 'cfs.exvo.local',
123
115
  :desktop_host => 'www.exvo.local',
124
- :themes_host => 'themes.exvo.local'
116
+ :themes_host => 'themes.exvo.local',
117
+ :blog_host => 'blog.exvo.local',
118
+ :contacts_host => 'contacts.exvo.local',
119
+ :inbox_host => 'inbox.exvo.local',
120
+ :music_host => 'music.exvo.local',
121
+ :pics_host => 'pics.exvo.local'
125
122
  }
126
123
  }
127
124
  end
@@ -1,3 +1,3 @@
1
1
  module ExvoHelpers
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -16,6 +16,22 @@ describe Exvo::Helpers do
16
16
  end
17
17
  end
18
18
 
19
+ describe "uri methods in production environment" do
20
+ before do
21
+ Exvo::Helpers.stub(:env).and_return('production')
22
+ end
23
+
24
+ specify { Exvo::Helpers.cdn_uri.should match('cdn.exvo.com') }
25
+ specify { Exvo::Helpers.cfs_uri.should match('cfs.exvo.com') }
26
+ specify { Exvo::Helpers.desktop_uri.should match('www.exvo.com') }
27
+ specify { Exvo::Helpers.themes_uri.should match('themes.exvo.com') }
28
+ specify { Exvo::Helpers.blog_uri.should match('blog.exvo.com') }
29
+ specify { Exvo::Helpers.contacts_uri.should match('contacts.exvo.com') }
30
+ specify { Exvo::Helpers.inbox_uri.should match('inbox.exvo.com') }
31
+ specify { Exvo::Helpers.music_uri.should match('music.exvo.com') }
32
+ specify { Exvo::Helpers.pics_uri.should match('pics.exvo.com') }
33
+ end
34
+
19
35
  describe "host methods in production environment" do
20
36
  before do
21
37
  Exvo::Helpers.stub(:env).and_return('production')
@@ -25,51 +41,37 @@ describe Exvo::Helpers do
25
41
  specify { Exvo::Helpers.cfs_host.should eql('cfs.exvo.com') }
26
42
  specify { Exvo::Helpers.desktop_host.should eql('www.exvo.com') }
27
43
  specify { Exvo::Helpers.themes_host.should eql('themes.exvo.com') }
44
+ specify { Exvo::Helpers.blog_host.should eql('blog.exvo.com') }
45
+ specify { Exvo::Helpers.contacts_host.should eql('contacts.exvo.com') }
46
+ specify { Exvo::Helpers.inbox_host.should eql('inbox.exvo.com') }
47
+ specify { Exvo::Helpers.music_host.should eql('music.exvo.com') }
48
+ specify { Exvo::Helpers.pics_host.should eql('pics.exvo.com') }
28
49
  end
29
50
 
30
51
  describe "ENV setting overrides the defaults" do
52
+ # as all methods are defined the same using metaprogramming, only testing for 1 is enough
31
53
  let(:cdn_host) { "test.cdn.exvo.com" }
32
- let(:cfs_host) { "test.cfs.exvo.com" }
33
- let(:desktop_host) { "test.exvo.com" }
34
- let(:themes_host) { "test.themes.exvo.com" }
35
54
 
36
55
  before do
37
56
  # clear any previous memoization
38
57
  Exvo::Helpers.cdn_host = nil
39
- Exvo::Helpers.cfs_host = nil
40
- Exvo::Helpers.desktop_host = nil
41
- Exvo::Helpers.themes_host = nil
42
58
 
43
59
  # set ENV
44
60
  ENV["CDN_HOST"] = cdn_host
45
- ENV["CFS_HOST"] = cfs_host
46
- ENV["DESKTOP_HOST"] = desktop_host
47
- ENV["THEMES_HOST"] = themes_host
48
61
  end
49
62
 
50
63
  specify { Exvo::Helpers.cdn_host.should eql(cdn_host) }
51
- specify { Exvo::Helpers.cfs_host.should eql(cfs_host) }
52
- specify { Exvo::Helpers.desktop_host.should eql(desktop_host) }
53
- specify { Exvo::Helpers.themes_host.should eql(themes_host) }
54
64
  end
55
65
 
56
66
  describe "setting host directly overrides the defaults" do
67
+ # as all methods are defined the same using metaprogramming, only testing for 1 is enough
57
68
  let(:cdn_host) { "new.cdn.exvo.com" }
58
- let(:cfs_host) { "new.cfs.exvo.com" }
59
- let(:desktop_host) { "new.exvo.com" }
60
- let(:themes_host) { "new.themes.exvo.com" }
61
69
 
62
70
  before do
63
71
  Exvo::Helpers.cdn_host = cdn_host
64
- Exvo::Helpers.cfs_host = cfs_host
65
- Exvo::Helpers.desktop_host = desktop_host
66
- Exvo::Helpers.themes_host = themes_host
67
72
  end
68
73
 
69
74
  specify { Exvo::Helpers.cdn_host.should eql(cdn_host) }
70
- specify { Exvo::Helpers.cfs_host.should eql(cfs_host) }
71
- specify { Exvo::Helpers.desktop_host.should eql(desktop_host) }
72
- specify { Exvo::Helpers.themes_host.should eql(themes_host) }
73
75
  end
74
76
 
75
77
  describe "auth_host/auth_uri methods which pass to the ExvoAuth gem" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exvo_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-18 00:00:00.000000000Z
12
+ date: 2011-11-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &78439060 !ruby/object:Gem::Requirement
16
+ requirement: &85101570 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *78439060
24
+ version_requirements: *85101570
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &78438710 !ruby/object:Gem::Requirement
27
+ requirement: &85101310 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.7'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *78438710
35
+ version_requirements: *85101310
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: guard
38
- requirement: &78438360 !ruby/object:Gem::Requirement
38
+ requirement: &85101070 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.8.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *78438360
46
+ version_requirements: *85101070
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-rspec
49
- requirement: &78438020 !ruby/object:Gem::Requirement
49
+ requirement: &85100830 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.4.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *78438020
57
+ version_requirements: *85100830
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rb-fsevent
60
- requirement: &78437820 !ruby/object:Gem::Requirement
60
+ requirement: &85100640 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *78437820
68
+ version_requirements: *85100640
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rb-inotify
71
- requirement: &78437580 !ruby/object:Gem::Requirement
71
+ requirement: &85100410 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *78437580
79
+ version_requirements: *85100410
80
80
  description: Ruby gem providing helper *_uri/*_host methods for Exvo services/apps
81
81
  like DESKTOP/CFS/AUTH/THEMES.
82
82
  email: