plek 0.5.0 → 1.0.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.
Files changed (3) hide show
  1. data/lib/plek.rb +16 -53
  2. data/lib/plek/version.rb +1 -1
  3. metadata +4 -4
@@ -2,61 +2,28 @@ require 'builder'
2
2
  require 'plek/version'
3
3
 
4
4
  class Plek
5
+ class NoConfigurationError < StandardError; end
5
6
  DEFAULT_PATTERN = "pattern".freeze
7
+ HTTP_DOMAINS = ['dev.gov.uk']
6
8
 
7
- SERVICES = {
8
- "production.www" => "www.gov.uk",
9
- "production.assets" => "static.production.alphagov.co.uk",
10
- "production.cdn" => "d17tffe05zdvwj.cloudfront.net",
11
- "production.publication-preview" => "private-frontend.production.alphagov.co.uk",
12
- "production.#{DEFAULT_PATTERN}" => "%s.production.alphagov.co.uk",
9
+ attr_accessor :parent_domain
13
10
 
14
- "preview.www" => "www.preview.alphagov.co.uk",
15
- "preview.assets" => "static.preview.alphagov.co.uk",
16
- "preview.cdn" => "djb1962t8apu5.cloudfront.net",
17
- "preview.publication-preview" => "private-frontend.preview.alphagov.co.uk",
18
- "preview.#{DEFAULT_PATTERN}" => "%s.preview.alphagov.co.uk",
19
-
20
- "staging.frontend" => "demo.alphagov.co.uk",
21
- "staging.publisher" => "guides.staging.alphagov.co.uk",
22
- "staging.assets" => "static.staging.alphagov.co.uk",
23
- "staging.publication-preview" => "private-frontend.staging.alphagov.co.uk",
24
- "staging.#{DEFAULT_PATTERN}" => "%s.staging.alphagov.co.uk",
25
-
26
- "development.assets" => "static.dev.gov.uk",
27
- "development.cdn" => "static.dev.gov.uk",
28
- "development.publication-preview"=> "www.dev.gov.uk",
29
- "development.#{DEFAULT_PATTERN}" => "%s.dev.gov.uk",
30
-
31
- "test.publication-preview" => "www.test.gov.uk",
32
- "test.cdn" => "static.test.gov.uk",
33
- "test.#{DEFAULT_PATTERN}" => "%s.test.gov.uk",
34
- }.freeze
35
-
36
- attr_accessor :environment
37
- private :environment=
38
-
39
- def initialize(environment)
40
- self.environment = environment
11
+ def initialize(domain_to_use = nil)
12
+ self.parent_domain = domain_to_use || ENV['GOVUK_APP_DOMAIN'] || raise(NoConfigurationError, 'Expected GOVUK_APP_DOMAIN to be set. Perhaps you should run your task through govuk_setenv <appname>?')
41
13
  end
42
14
 
43
15
  # Find the URI for a service/application.
44
16
  def find(service)
45
- name = name_for service
46
- host = SERVICES[service_key_for(name)]
47
- host ||= SERVICES["#{environment}.#{DEFAULT_PATTERN}"].to_s % name
17
+ name = name_for(service)
18
+ host = "#{name}.#{parent_domain}"
48
19
 
49
- if environment == 'preview' || environment == 'production'
50
- "https://#{host}"
51
- else
20
+ if HTTP_DOMAINS.include?(parent_domain)
52
21
  "http://#{host}"
22
+ else
23
+ "https://#{host}"
53
24
  end
54
25
  end
55
26
 
56
- def service_key_for(name)
57
- "#{environment}.#{name}"
58
- end
59
-
60
27
  def name_for(service)
61
28
  name = service.to_s.dup
62
29
  name.downcase!
@@ -65,15 +32,11 @@ class Plek
65
32
  name
66
33
  end
67
34
 
68
- def self.current_env
69
- if (ENV['RAILS_ENV'] || ENV['RACK_ENV']) == 'test'
70
- 'test'
71
- else
72
- ENV['FACTER_govuk_platform'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
73
- end
74
- end
75
-
76
- def self.current
77
- Plek.new(current_env)
35
+ class << self
36
+ # This alias allows calls to be made in the old style:
37
+ # Plek.current.find('foo')
38
+ # as well as the new style:
39
+ # Plek.new.find('foo')
40
+ alias_method :current, :new
78
41
  end
79
42
  end
@@ -1,3 +1,3 @@
1
1
  class Plek
2
- VERSION = '0.5.0'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: plek
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Craig R Webster
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-09-20 00:00:00 Z
13
+ date: 2012-12-04 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: builder
@@ -71,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- hash: -3610201643130859393
74
+ hash: -4590434743325616263
75
75
  segments:
76
76
  - 0
77
77
  version: "0"
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- hash: -3610201643130859393
83
+ hash: -4590434743325616263
84
84
  segments:
85
85
  - 0
86
86
  version: "0"