kibana-sinatra 3.1.0.1 → 3.1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1e05bf726539ac6f753a4f87fcfac3437365c8c
4
- data.tar.gz: b13d42d8c9a2bc96f3724b6146ec8aa446d96684
3
+ metadata.gz: 7d6fb0ca5b9deb5f4ac4021e85db5ed2bc2f8cc1
4
+ data.tar.gz: 7fcc55bafac7329a79b8e8e56dc5991fe2eb4b2a
5
5
  SHA512:
6
- metadata.gz: 2b6cb7c1cc7db01d55c8b7b3c84a73d699c3ca9726ed42532fd5c8be566fd486536623b2dde6295ef9a7efffeda664972363b02a4fccdad741a447a4fb28b6f1
7
- data.tar.gz: 0d74a6de030ef1386d4e9d3622a08aa4ff00f0acb94632a2bc17f8b752570e646bd58da842cddb562382ed3766148dc77c2127cfb9b0d602132c267295dbe462
6
+ metadata.gz: 2054e744ba55b7f4299c1b88ff5780e67f58a6358d4473142e0e9ed7e4f28c4cb6d509f9111cd55f1e0264684b6b4c9c162a8a739e6886a56c9bd9b6ef21bbb8
7
+ data.tar.gz: 3f9f274511bfaf9edd1382b175e37d98a0dd24f7bd51e60086b71c41b1c18fa6707794e9b40172b24eabda4aff17a76cf444356fd2b89219f6aa086a2319120b
data/README.md CHANGED
@@ -75,6 +75,24 @@ At last, you need to just run rackup.
75
75
  rackup
76
76
  ```
77
77
 
78
+ ### Custom dashboards
79
+
80
+ If you would like to include custom dashboard JSON files you can do so by overriding the `render_dashboard(name)` method. This method requires a single parameter `name` that will contain the filename requested. For example, if the browser requests `/app/dashboards/test.json`, then `test.json` will be assigned to the `name` parameter.
81
+
82
+ This method should return the JSON as a string.
83
+
84
+ You could then make that JSON file the default by overriding `default_route` like this:
85
+
86
+ ```ruby
87
+ module Kibana::Sinatra
88
+ class Web
89
+ def default_route
90
+ "/dashboard/file/test.json"
91
+ end
92
+ end
93
+ end
94
+ ```
95
+
78
96
  ## Versions
79
97
 
80
98
  Kibana-sinatra's version number will match the upstream Kibana version number, plus an additional build number. For example:
@@ -1,5 +1,5 @@
1
1
  module Kibana
2
2
  module Sinatra
3
- VERSION = "3.1.0.1"
3
+ VERSION = "3.1.0.2"
4
4
  end
5
5
  end
@@ -15,6 +15,10 @@ module Kibana
15
15
  erb :config
16
16
  end
17
17
 
18
+ get '/app/dashboards/:name' do
19
+ render_dashboard params[:name]
20
+ end
21
+
18
22
  def elasticsearch_url
19
23
  "http://\"+window.location.hostname+\":9200"
20
24
  end
@@ -26,6 +30,10 @@ module Kibana
26
30
  def default_route
27
31
  "/dashboard/file/default.json"
28
32
  end
33
+
34
+ def render_dashboard(name)
35
+ status 404
36
+ end
29
37
  end
30
38
 
31
39
  end
@@ -65,17 +65,49 @@ class SinatraTest < Minitest::Unit::TestCase
65
65
  end
66
66
  end
67
67
 
68
+ def test_it_renders_kibana_builtin_dashboard
69
+ get '/app/dashboards/default.json'
70
+ assert last_response.ok?
71
+ assert_equal 4140, last_response.body.length
72
+ end
73
+
74
+ def test_it_renders_kibana_builtin_dashboard_when_custom_present
75
+ render_dashboard = Proc.new {|name| "asdf" }
76
+
77
+ monkey_patch "render_dashboard", render_dashboard do
78
+ get '/app/dashboards/default.json'
79
+ assert last_response.ok?
80
+ assert_equal 4140, last_response.body.length
81
+ end
82
+ end
83
+
84
+ def test_it_renders_default_dashboard
85
+ get '/app/dashboards/asdf.json'
86
+ assert last_response.not_found?
87
+ assert_equal 0, last_response.body.length
88
+ end
89
+
90
+ def test_it_renders_custom_dashboard
91
+ render_dashboard = Proc.new {|name| "asdf" }
92
+
93
+ monkey_patch "render_dashboard", render_dashboard do
94
+ get '/app/dashboards/testing.json'
95
+ assert last_response.ok?
96
+ assert_equal "asdf", last_response.body
97
+ end
98
+ end
99
+
68
100
  def monkey_patch(method_name, method_replacement)
69
101
  Kibana::Sinatra::Web.class_eval do
70
- alias_method "old_#{method_name}", method_name
102
+ alias_method "original_#{method_name}", method_name
71
103
  define_method method_name, method_replacement
72
104
  end
73
105
 
74
106
  yield
75
-
107
+ ensure
76
108
  Kibana::Sinatra::Web.class_eval do
77
- alias_method method_name, "old_#{method_name}"
78
- remove_method "old_#{method_name}"
109
+ alias_method method_name, "original_#{method_name}"
110
+ remove_method "original_#{method_name}"
79
111
  end
80
112
  end
81
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kibana-sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.1
4
+ version: 3.1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Neubert