ember_cli_deploy_redis 0.1.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 (80) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +2 -0
  3. data/.jrubyrc +1 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +5 -0
  6. data/README.md +69 -15
  7. data/ember_cli_deploy_redis.gemspec +28 -25
  8. data/lib/ember_cli_deploy_redis.rb +8 -2
  9. data/lib/ember_cli_deploy_redis/application.rb +12 -1
  10. data/lib/ember_cli_deploy_redis/configuration.rb +31 -3
  11. data/lib/ember_cli_deploy_redis/errors.rb +1 -1
  12. data/lib/ember_cli_deploy_redis/revision.rb +17 -9
  13. data/lib/ember_cli_deploy_redis/revision_list.rb +12 -6
  14. data/lib/ember_cli_deploy_redis/version.rb +1 -1
  15. data/lib/ember_cli_deploy_redis/web.rb +59 -0
  16. data/lib/ember_cli_deploy_redis/web_helpers.rb +162 -0
  17. data/spec/lib/ember_cli_deploy_redis/application_spec.rb +12 -2
  18. data/spec/lib/ember_cli_deploy_redis/revision_list_spec.rb +34 -3
  19. data/spec/lib/ember_cli_deploy_redis/revision_spec.rb +29 -12
  20. data/spec/lib/ember_cli_deploy_redis/web_helpers_spec.rb +69 -0
  21. data/spec/lib/ember_cli_deploy_redis/web_spec.rb +164 -0
  22. data/spec/lib/ember_cli_deploy_redis_spec.rb +21 -8
  23. data/spec/spec_helper.rb +15 -5
  24. data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
  25. data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
  26. data/web/assets/javascripts/application.js +67 -0
  27. data/web/assets/javascripts/locales/README.md +27 -0
  28. data/web/assets/javascripts/locales/jquery.timeago.ar.js +96 -0
  29. data/web/assets/javascripts/locales/jquery.timeago.bg.js +18 -0
  30. data/web/assets/javascripts/locales/jquery.timeago.bs.js +49 -0
  31. data/web/assets/javascripts/locales/jquery.timeago.ca.js +18 -0
  32. data/web/assets/javascripts/locales/jquery.timeago.cs.js +18 -0
  33. data/web/assets/javascripts/locales/jquery.timeago.cy.js +20 -0
  34. data/web/assets/javascripts/locales/jquery.timeago.da.js +18 -0
  35. data/web/assets/javascripts/locales/jquery.timeago.de.js +18 -0
  36. data/web/assets/javascripts/locales/jquery.timeago.el.js +18 -0
  37. data/web/assets/javascripts/locales/jquery.timeago.en-short.js +20 -0
  38. data/web/assets/javascripts/locales/jquery.timeago.en.js +20 -0
  39. data/web/assets/javascripts/locales/jquery.timeago.es.js +18 -0
  40. data/web/assets/javascripts/locales/jquery.timeago.et.js +18 -0
  41. data/web/assets/javascripts/locales/jquery.timeago.fa.js +22 -0
  42. data/web/assets/javascripts/locales/jquery.timeago.fi.js +28 -0
  43. data/web/assets/javascripts/locales/jquery.timeago.fr-short.js +16 -0
  44. data/web/assets/javascripts/locales/jquery.timeago.fr.js +17 -0
  45. data/web/assets/javascripts/locales/jquery.timeago.he.js +18 -0
  46. data/web/assets/javascripts/locales/jquery.timeago.hr.js +49 -0
  47. data/web/assets/javascripts/locales/jquery.timeago.hu.js +18 -0
  48. data/web/assets/javascripts/locales/jquery.timeago.hy.js +18 -0
  49. data/web/assets/javascripts/locales/jquery.timeago.id.js +18 -0
  50. data/web/assets/javascripts/locales/jquery.timeago.it.js +16 -0
  51. data/web/assets/javascripts/locales/jquery.timeago.ja.js +19 -0
  52. data/web/assets/javascripts/locales/jquery.timeago.ko.js +17 -0
  53. data/web/assets/javascripts/locales/jquery.timeago.lt.js +20 -0
  54. data/web/assets/javascripts/locales/jquery.timeago.mk.js +20 -0
  55. data/web/assets/javascripts/locales/jquery.timeago.nl.js +20 -0
  56. data/web/assets/javascripts/locales/jquery.timeago.no.js +18 -0
  57. data/web/assets/javascripts/locales/jquery.timeago.pl.js +31 -0
  58. data/web/assets/javascripts/locales/jquery.timeago.pt-br.js +16 -0
  59. data/web/assets/javascripts/locales/jquery.timeago.pt.js +16 -0
  60. data/web/assets/javascripts/locales/jquery.timeago.ro.js +18 -0
  61. data/web/assets/javascripts/locales/jquery.timeago.rs.js +49 -0
  62. data/web/assets/javascripts/locales/jquery.timeago.ru.js +34 -0
  63. data/web/assets/javascripts/locales/jquery.timeago.sk.js +18 -0
  64. data/web/assets/javascripts/locales/jquery.timeago.sl.js +44 -0
  65. data/web/assets/javascripts/locales/jquery.timeago.sv.js +18 -0
  66. data/web/assets/javascripts/locales/jquery.timeago.th.js +20 -0
  67. data/web/assets/javascripts/locales/jquery.timeago.tr.js +16 -0
  68. data/web/assets/javascripts/locales/jquery.timeago.uk.js +34 -0
  69. data/web/assets/javascripts/locales/jquery.timeago.uz.js +19 -0
  70. data/web/assets/javascripts/locales/jquery.timeago.zh-cn.js +20 -0
  71. data/web/assets/javascripts/locales/jquery.timeago.zh-tw.js +20 -0
  72. data/web/assets/stylesheets/application.css +580 -0
  73. data/web/assets/stylesheets/bootstrap.css +9 -0
  74. data/web/locales/en.yml +13 -0
  75. data/web/views/_footer.erb +14 -0
  76. data/web/views/application.erb +38 -0
  77. data/web/views/dashboard.erb +26 -0
  78. data/web/views/layout.erb +26 -0
  79. metadata +89 -42
  80. data/Gemfile.lock +0 -121
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjVlZTM5MTYwODRlNjVhN2VkYzA1NjcwNDY1MmViMTQxNGNiM2JlNA==
4
+ MTBjNmE1MTRkMTg2NDY5ZGFjNzY3YTliZjQ4NGUxOTM1MWMxMTZiMg==
5
5
  data.tar.gz: !binary |-
6
- NjUyMGE1MGZhNmU3YjM4NGUwZmYzYjNhMDIyNGJkYWIxZDNmNzI5Zg==
6
+ YTgwYjZmYTdmZGUwYjQwMjUzMWI5N2I3ZDBmZTFjMjUwMDBhNjhhNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzMyNDFmMzFjOTU3NWEwZTQxYTljNWNmMmI2NTI0N2IwYWQwODk0ZDc2ZTE1
10
- YmRmNTQ3N2I3ZGE5NzdiNzMzNzFkMTQzZWY4OTE4ZWQ4MTg3ZmY4NTM5OGZh
11
- YTQxY2U2MTRmZDJjNDI3YjM0MmY1YjUzNzhjN2U2N2Y1YTMwZDM=
9
+ MTQ5YmM1MDljMWMxMWYxMzk1M2JlZmVhOTExYTlmMDY5MDg3ZTc1ODBkYWVl
10
+ NDEwOWVhNmNkMGJlM2VhZDZkM2E3OGYxOTA0ZDM1MTY0YjQ2OTY3ZDQ3M2Fj
11
+ YjgxZTY0NTYyODUwNDQ4OGUxZGU0NmVkNTE5NTcxYWIwMmJmODU=
12
12
  data.tar.gz: !binary |-
13
- YTcxZjkwMDczMTY1ZThhMDc3NWI3NGM0OTJmYTg0NDc1MGQwOTEyNzJmYmJh
14
- Mjk3YTUwNWJhMDhlMzg0MmM4MDgyZmE5NTViNGI1YTc4ZmE3Mjg2NmYxMTg4
15
- NmY0MWVjZjJhZTMxOTk5NDU2NDk3Mjc0NzcxNmY4YTk0ODY0M2U=
13
+ Y2M3OTEyMmMwMDJkMDk3ZjNhZmY4ZmY0OTQwODQ2NWM4OTFjZTQ2NDE2MTZj
14
+ OWMzNmQyYzdhZmNhNTEzYjhmZGU4NDZmNmEwZWE1MGNlNDM2Y2ViZGFmMjI1
15
+ NDY4YzY5NTYyMGM3OGZiMjAwMmExNWJjOGE4ZGU5YWJkN2NiM2E=
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ coverage
2
+ Gemfile.lock
data/.jrubyrc ADDED
@@ -0,0 +1 @@
1
+ compat.version=2.0
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format documentation
data/.travis.yml CHANGED
@@ -5,6 +5,11 @@ rvm:
5
5
  - 2.0.0
6
6
  - 2.1.6
7
7
  - 2.2.3
8
+ - jruby-1.7.22
9
+ - jruby-9.0.1.0
10
+ - jruby-head
11
+ env:
12
+ - JRUBY_OPTS="-Xcli.debug=true --debug"
8
13
  script: bundle exec rspec
9
14
  deploy:
10
15
  provider: rubygems
data/README.md CHANGED
@@ -4,56 +4,110 @@
4
4
 
5
5
  # ember_cli_deploy_redis
6
6
 
7
- Ruby interaction with [ember-cli-deploy-redis][2] to support [ember-cli][1] project deployments.
7
+ Ruby interaction with [the Ahalogy fork of ember-cli-deploy-redis][2] to support [ember-cli][1] project deployments.
8
8
 
9
9
  [ember-cli-deploy-redis][2] stores deployment information including
10
- the index page contents in Redis, and this gem allows access to it so that it can be served.
10
+ the index page contents in Redis.
11
+ This gem allows access to that content so that it can be served.
11
12
 
12
13
  ## Installing
13
14
 
14
15
  ```ruby
15
- gem install ember_cli_deploy_redis
16
+ gem install ember_cli_deploy_redis
16
17
  ```
17
18
 
18
19
  Or if you are using bundler add to your Gemfile:
19
20
 
20
21
  ```ruby
21
- gem ember_cli_deploy_redis, '~> 0.0.1'
22
+ gem ember_cli_deploy_redis, '~> 0.0.1'
22
23
  ```
23
24
 
24
25
  ## Usage
25
26
 
26
- The following errors may be raised by the methods mentioned below:
27
-
28
- * `EmberCliDeployRedis::NoDeployments`
29
- * `EmberCliDeployRedis::FileMissingFromDeployment`
30
-
31
27
  ### Configuration
32
28
 
33
29
  ```ruby
34
30
  EmberCliDeployRedis.configure do |config|
35
- config.app_name = "ember_cli_project_name"
31
+ config.default_app_name = "ember_cli_project_name"
36
32
  # Optional:
37
33
  config.keyspace = "optional_redis_keyspace"
38
34
  end
39
35
  ```
40
36
 
41
- ### Getting deployed revisions
37
+ ### Getting all deployed revisions for the default app
38
+
39
+ ```ruby
40
+ EmberCliDeployRedis.revisions
41
+ ```
42
+
43
+ This will raise an `EmberCliDeployRedis::ConfigurationError` if `default_app_name` was not configured.
44
+
45
+ ### Getting the currently-active revision for the default app
46
+
47
+ ```ruby
48
+ EmberCliDeployRedis.active_revision
49
+ ```
50
+
51
+ This will raise an `EmberCliDeployRedis::ConfigurationError` if `default_app_name` was not configured.
52
+
53
+ ### Get a specific app
42
54
 
43
55
  ```ruby
44
- EmberCliDeployRedis.revisions
56
+ EmberCliDeployRedis::Application.new('app_name')
45
57
  ```
46
58
 
47
- ### Getting the latest deployed revision
59
+ ### Get specific revision from an app
48
60
 
49
61
  ```ruby
50
- EmberCliDeployRedis.latest_revision
62
+ application.revision_by_name('revision_identifier')
51
63
  ```
52
64
 
53
65
  ### Getting the contents of a deployed file
54
66
 
55
67
  ```ruby
56
- EmberCliDeployRedis.latest_revision.contents_of('index.html')
68
+ EmberCliDeployRedis.active_revision.contents_of('index.html')
69
+ ```
70
+
71
+ This will raise an `EmberCliDeployRedis::FileMissingFromDeployment` if the file is not present in Redis.
72
+
73
+ ## Web UI
74
+
75
+ Borrowed from the awesome [Sidekiq Web UI](https://github.com/mperham/sidekiq/wiki/Monitoring).
76
+
77
+ Add sinatra to your Gemfile:
78
+
79
+ ```ruby
80
+ # if you require 'sinatra' you get the DSL extended to Object
81
+ gem 'sinatra', :require => nil
82
+ ```
83
+
84
+ Add the following to your config/routes.rb:
85
+
86
+ ```ruby
87
+ require 'ember_cli_deploy_redis/web'
88
+ mount EmberCliDeployRedis::Web => '/sidekiq'
89
+ ```
90
+
91
+ This interface allows the display of the currently-active revision and the most recent revisions.
92
+
93
+ It also includes "test" link for each non-active revision.
94
+ This is done using a query parameter, the name of which is set in the `revision_specifier_query_param` configuration variable.
95
+
96
+ ### Configuration
97
+
98
+ ```ruby
99
+ EmberCliDeployRedis.configure do |config|
100
+ # By default, the default_app_name is used. Otherwise, you can specify multiple app names:
101
+ config.web_application_names = %w(application1 application2)
102
+
103
+ # To enable "test" links for revisions:
104
+ config.revision_specifier_query_param = "_ember_app"
105
+
106
+ # To perform an action when a revision is made active:
107
+ config.on_revision_activated do |new_revision|
108
+ # Slack webhook here!
109
+ end
110
+ end
57
111
  ```
58
112
 
59
113
  ## To Do
@@ -2,32 +2,35 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
  require "ember_cli_deploy_redis/version"
4
4
 
5
- Gem::Specification.new do |s|
6
- s.name = "ember_cli_deploy_redis"
7
- s.version = EmberCliDeployRedis::VERSION
8
- s.authors = ["Ahalogy"]
9
- s.email = ["robin@robindaugherty.net"]
10
- s.homepage = ""
11
- s.summary = "Ruby interaction with ember-cli-deploy-redis"
12
- s.description = <<-MD
13
- Supports ember-cli project deployments
14
- made using ember-cli-deploy-redis, which stores deployment information including
15
- the index page contents in Redis.
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ember_cli_deploy_redis"
7
+ spec.version = EmberCliDeployRedis::VERSION
8
+ spec.licenses = ["MIT"]
9
+ spec.authors = ["Ahalogy", "Robin Daugherty"]
10
+ spec.email = ["robin@robindaugherty.net"]
11
+ spec.homepage = "https://github.com/Ahalogy/ember_cli_deploy_redis_ruby"
12
+ spec.summary = "Serves up ember-cli content deployed with our fork of ember-cli-deploy-redis"
13
+ spec.description = <<-MD
14
+ Handles the serving of page contents of deployed ember-cli projects deployed using our fork of
15
+ (ember-cli-deploy-redis)[https://github.com/Ahalogy/ember-cli-deploy-redis],
16
+ which stores deployment information including the index page contents in Redis.
16
17
  MD
18
+ spec.requirements << 'An Ember-ClI project'
19
+ spec.requirements << '(ember-cli-deploy)[https://github.com/ember-cli/ember-cli-deploy], 0.4.x'
20
+ spec.requirements << '(ember-cli-deploy-redis)[https://github.com/Ahalogy/ember-cli-deploy-redis]'
21
+ spec.requirements << 'A Ruby (Rails/Sinatra/etc) app to serve up the Ember-CLI project and provide it an API.'
17
22
 
18
- s.files = `git ls-files`.split("\n")
19
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
- s.require_paths = ["lib"]
23
+ spec.files = `git ls-files`.split("\n")
24
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ spec.require_paths = ["lib"]
26
+ spec.required_ruby_version = '~> 2.0'
22
27
 
23
- s.add_dependency "redis"
24
- s.add_development_dependency "fakeredis"
25
- s.add_development_dependency "shoulda-matchers"
26
- s.add_development_dependency "dotenv"
27
- s.add_development_dependency "rspec"
28
- s.add_development_dependency "pry"
29
- s.add_development_dependency 'pry-byebug'
30
- s.add_development_dependency 'pry-doc'
31
- s.add_development_dependency 'pry-rescue'
32
- s.add_development_dependency 'pry-stack_explorer'
28
+ spec.add_runtime_dependency "redis"
29
+ spec.add_development_dependency "fakeredis"
30
+ spec.add_development_dependency "shoulda-matchers"
31
+ spec.add_development_dependency "dotenv"
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_development_dependency 'sinatra', '~> 1.4', '>= 1.4.6'
34
+ spec.add_development_dependency 'rack-test'
35
+ spec.add_development_dependency 'rspec-html-matchers'
33
36
  end
@@ -18,7 +18,7 @@ module EmberCliDeployRedis
18
18
 
19
19
  def default_app
20
20
  unless configuration.default_app_name
21
- fail 'No default_app_name has been configured for the ember-cli project.'
21
+ fail EmberCliDeployRedis::ConfigurationError, 'No default_app_name has been configured.'
22
22
  end
23
23
  @default_app ||= EmberCliDeployRedis::Application.new(configuration.default_app_name)
24
24
  end
@@ -27,8 +27,14 @@ module EmberCliDeployRedis
27
27
  default_app.revisions
28
28
  end
29
29
 
30
+ # @deprecated use {#active_revision} instead
30
31
  def latest_revision
31
- default_app.latest_revision
32
+ warn "[DEPRECATION] `latest_revision` is deprecated, use `active_revision` instead"
33
+ active_revision
34
+ end
35
+
36
+ def active_revision
37
+ default_app.active_revision
32
38
  end
33
39
  end
34
40
  end
@@ -11,8 +11,19 @@ module EmberCliDeployRedis
11
11
  EmberCliDeployRedis::RevisionList.from_redis(self)
12
12
  end
13
13
 
14
+ # @deprecated use {#active_revision} instead
14
15
  def latest_revision
15
- EmberCliDeployRedis::Revision.latest_from_redis(self)
16
+ warn "[DEPRECATION] `latest_revision` is deprecated, use `active_revision` instead"
17
+ active_revision
18
+ end
19
+
20
+ def active_revision
21
+ EmberCliDeployRedis::Revision.active_from_redis(self)
22
+ end
23
+
24
+ # Returns the Revision specified by name, or nil if nothing matched.
25
+ def revision_by_name(revision_name)
26
+ revisions.find { |r| r.name == revision_name }
16
27
  end
17
28
 
18
29
  private
@@ -1,15 +1,43 @@
1
1
  module EmberCliDeployRedis
2
2
  class Configuration
3
- attr_accessor :redis, :keyspace
4
- attr_reader :default_app_name
3
+ attr_accessor :redis
5
4
 
6
5
  def keyspace
7
6
  @keyspace ||= 'ember-cli-deploy'
8
7
  end
9
8
 
9
+ attr_writer :keyspace
10
+
11
+ attr_reader :default_app_name
12
+
10
13
  def default_app_name=(name)
14
+ fail ArgumentError, "default_app_name has already been set" if @default_app_name
11
15
  @default_app_name = name
12
- @default_app = nil
16
+ end
17
+
18
+ # Array of names of Ember applications that will be supported.
19
+ def web_application_names
20
+ @web_application_names ||= [default_app_name]
21
+ end
22
+
23
+ def web_application_names=(names)
24
+ fail ArgumentError, "names must be an array" unless names.respond_to? :each
25
+ @web_application_names = names
26
+ end
27
+
28
+ attr_reader :revision_specifier_query_param
29
+ def revision_specifier_query_param=(param_name)
30
+ @revision_specifier_query_param = param_name
31
+ end
32
+
33
+ def on_revision_activated(&block)
34
+ @on_revision_activated_block = block
35
+ end
36
+
37
+ attr_reader :on_revision_activated_block
38
+
39
+ def revision_has_been_activated(revision)
40
+ @on_activate_revision_block.call(revision) if @on_activate_revision_block
13
41
  end
14
42
 
15
43
  def redis_key_for_revision_list(application)
@@ -1,4 +1,4 @@
1
1
  module EmberCliDeployRedis
2
- class NoDeployments < ::StandardError; end
2
+ class ConfigurationError < ::StandardError; end
3
3
  class FileMissingFromDeployment < ::StandardError; end
4
4
  end
@@ -5,8 +5,9 @@ module EmberCliDeployRedis
5
5
  attr_reader :application
6
6
  attr_reader :name
7
7
 
8
- def self.latest_from_redis(application)
9
- new application, latest_revision_from_redis(application)
8
+ def self.active_from_redis(application)
9
+ revision_name = active_revision_from_redis(application)
10
+ new application, revision_name if revision_name
10
11
  end
11
12
 
12
13
  def initialize(application, name)
@@ -18,20 +19,27 @@ module EmberCliDeployRedis
18
19
  contents_of_file_from_redis(filename)
19
20
  end
20
21
 
22
+ def active?
23
+ self == application.active_revision
24
+ end
25
+
26
+ def ==(other)
27
+ other.name == name
28
+ end
29
+
30
+ def activate!
31
+ key = EmberCliDeployRedis.configuration.redis_key_for_revision_list(application)
32
+ EmberCliDeployRedis.configuration.redis.lpush(key, name)
33
+ end
34
+
21
35
  private
22
36
 
23
37
  attr_writer :application
24
38
  attr_writer :name
25
39
 
26
- def self.latest_revision_from_redis(application)
40
+ def self.active_revision_from_redis(application)
27
41
  key = EmberCliDeployRedis.configuration.redis_key_for_revision_list(application)
28
42
  names = EmberCliDeployRedis.configuration.redis.lrange(key, 0, 0)
29
- unless names.size > 0
30
- fail(
31
- EmberCliDeployRedis::NoDeployments,
32
- "No revisions have been deployed to Redis",
33
- )
34
- end
35
43
  names.first
36
44
  end
37
45
 
@@ -1,15 +1,12 @@
1
- require 'forwardable'
1
+ require 'delegate'
2
2
 
3
3
  module EmberCliDeployRedis
4
4
  # Holds a list of deployed application revisions that may be used.
5
- class RevisionList
6
- extend Forwardable
7
-
5
+ # Delegates to the array of revisions, so standard {Array} methods can be called.
6
+ class RevisionList < SimpleDelegator
8
7
  attr_reader :application
9
8
  attr_reader :revisions
10
9
 
11
- def_delegators :revisions, :[], :first, :last
12
-
13
10
  def self.from_redis(application)
14
11
  new application, list_from_redis(application).map { |r| Revision.new(application, r) }
15
12
  end
@@ -17,6 +14,15 @@ module EmberCliDeployRedis
17
14
  def initialize(application, revisions)
18
15
  self.application = application
19
16
  self.revisions = revisions
17
+ super(revisions)
18
+ end
19
+
20
+ def method_missing(method, *args, &block)
21
+ if revisions.respond_to? method
22
+ revisions.send(method, *args, &block)
23
+ else
24
+ super
25
+ end
20
26
  end
21
27
 
22
28
  private
@@ -1,3 +1,3 @@
1
1
  module EmberCliDeployRedis
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,59 @@
1
+ require 'erb'
2
+ require 'yaml'
3
+ require 'sinatra/base'
4
+
5
+ require 'ember_cli_deploy_redis'
6
+ require 'ember_cli_deploy_redis/web_helpers'
7
+
8
+ module EmberCliDeployRedis
9
+ class Web < Sinatra::Base
10
+ enable :sessions
11
+ use Rack::Protection, :use => :authenticity_token unless ENV['RACK_ENV'] == 'test'
12
+
13
+ set :root, File.expand_path(File.dirname(__FILE__) + "/../../web")
14
+ set :public_folder, proc { "#{root}/assets" }
15
+ set :views, proc { "#{root}/views" }
16
+ set :locales, ["#{root}/locales"]
17
+
18
+ helpers WebHelpers
19
+
20
+ get '/' do
21
+ @applications = EmberCliDeployRedis.configuration.web_application_names.map { |name|
22
+ Application.new(name)
23
+ }
24
+ erb :dashboard
25
+ end
26
+
27
+ get "/applications/:app_name" do
28
+ halt 404 unless params[:app_name]
29
+ @application = Application.new(params[:app_name])
30
+ @revisions = @application.revisions
31
+ erb :application
32
+ end
33
+
34
+ post "/applications/:app_name/activate/:revision_name" do
35
+ halt 404 unless params[:app_name]
36
+ halt 404 unless params[:revision_name]
37
+ application = Application.new(params[:app_name])
38
+ revision = application.revision_by_name(params[:revision_name])
39
+ if EmberCliDeployRedis.configuration.on_revision_activated_block
40
+ EmberCliDeployRedis.configuration.on_revision_activated_block.call(revision)
41
+ end
42
+ revision.activate!
43
+ redirect_with_query("#{root_path}applications/#{application.name}")
44
+ end
45
+ end
46
+ end
47
+
48
+ if defined?(::ActionDispatch::Request::Session) &&
49
+ !::ActionDispatch::Request::Session.respond_to?(:each)
50
+ # mperham/sidekiq#2460
51
+ # Rack apps can't reuse the Rails session store without
52
+ # this monkeypatch
53
+ class ActionDispatch::Request::Session
54
+ def each(&block)
55
+ hash = self.to_hash
56
+ hash.each(&block)
57
+ end
58
+ end
59
+ end