socket2me 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 807d92d069e30d179e6e36b8d6e9b9c1ec749c2b
4
- data.tar.gz: ae06a77b29065e8a749bb953f54a16aa5b440c31
3
+ metadata.gz: 6a2549d6b2f5aca33cf3810f499e6ec2e73072a0
4
+ data.tar.gz: cc57ef2e4563c038d70ae47dbc062b53a39b364d
5
5
  SHA512:
6
- metadata.gz: 8751a7bdcde5669e49b0849fbfff96e739a107b84da42bfd645daaad78b37d5727993b4dda549231a8b55d281914d387433d6516cc3cd49fc4a4ff3b4ec59547
7
- data.tar.gz: be38362051e7e6988857af1560b1b866626529dfd8dfd7c7704514c835783a2f3add8eb7c5e16475f59e0ce245b64a46c3a1d6eef0bd7e8200de3f583185841e
6
+ metadata.gz: b35633bd814e20f2a019da3a2180759aa85e4c6ffb07ac37ad8651227b7b6cb24485c76b5b296d3faea05b54ca1922880f67044ae83901e20287c4bc13386d34
7
+ data.tar.gz: efd5dccf618c0f67f27446c41fdb008193045989456ca19eb2e13fce1b6840e8c3bc4585588c1969b15661dfe11383333305c899bcb9458095fbd414cd6d995c
data/README.md CHANGED
@@ -45,16 +45,16 @@ Or install it yourself as:
45
45
 
46
46
  ## Usage
47
47
 
48
- A full rack example is in `example/dummy.ru`. That app simply creates
48
+ A full rack example is in `examples/dummy.ru`. That app simply creates
49
49
  an HTML page and provides a helper js function to display some output. The
50
50
  example then outputs the server time every second in a background thread.
51
51
 
52
- To run `example/dummy.ru`:
52
+ To run `examples/dummy.ru`:
53
53
 
54
54
  1. checkout the project: `git clone https://github.com/ddrscott/socket2me`
55
55
  2. go into the the socket2me directory: `cd socket2me`
56
56
  3. install requirements: `./bin/setup`
57
- 4. start a rack server with the example: `rackup example/dummy.ru`
57
+ 4. start a rack server with the example: `rackup examples/dummy.ru`
58
58
 
59
59
  ### Rack
60
60
  ```ruby
@@ -80,7 +80,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
80
80
 
81
81
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
82
82
 
83
- Spot check everything works by running `rackup example/dummy.ru`. The browser
83
+ Spot check everything works by running `rackup examples/dummy.ru`. The browser
84
84
  should continually append a timestamp below the header.
85
85
 
86
86
  ## Contributing
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "socket2me"
3
+ require 'bundler/setup'
4
+ require 'socket2me'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
- require "pry"
9
+ require 'pry'
10
10
  Pry.start
@@ -1,7 +1,6 @@
1
1
  require 'logger'
2
2
 
3
3
  module Socket2me
4
-
5
4
  class Configuration
6
5
  # @attr [String] ws_host for the WebSocket listener
7
6
  attr_accessor :ws_host
@@ -20,17 +19,13 @@ module Socket2me
20
19
  end
21
20
 
22
21
  # @param [Logger] logger to use
23
- def logger=(logger)
24
- @logger = logger
25
- end
22
+ attr_writer :logger
26
23
  end
27
24
 
28
25
  # @yield [Configuration]
29
26
  def self.configure(&block)
30
27
  @config ||= Configuration.new
31
- if block_given?
32
- block.call @config
33
- end
28
+ block.call @config if block_given?
34
29
  end
35
30
 
36
31
  # @return [Configuration] current configuration
@@ -3,7 +3,6 @@ require 'em-websocket'
3
3
  module Socket2me
4
4
  module Middleware
5
5
  class AddScriptTag
6
-
7
6
  def initialize(app)
8
7
  @app = app
9
8
  @ws_url = "ws://#{Socket2me.config.ws_host}:#{Socket2me.config.ws_port}"
@@ -18,12 +17,14 @@ module Socket2me
18
17
  response = @app.call(env)
19
18
  status, headers, body = *response
20
19
 
21
- return response unless headers['Content-Type'] == 'text/html'
20
+ return response unless headers['Content-Type'].include?('text/html')
22
21
 
23
22
  # replace the last body with script
24
- new_body = body.join.gsub(%r{(</body>)}i,"#{script_tag}\\1")
23
+ orig_body = body.respond_to?(:body) ? body.body : body.join
24
+
25
+ new_body = orig_body.gsub(%r{(</body>)}i, "#{script_tag}\\1")
25
26
 
26
- return status, headers, [new_body]
27
+ [status, headers, [new_body]]
27
28
  end
28
29
 
29
30
  # @return [String] the outer Javascript tag with WS client script
@@ -40,4 +41,4 @@ module Socket2me
40
41
  end
41
42
  end
42
43
  end
43
- end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Socket2me
2
- VERSION = "0.5.2"
2
+ VERSION = '0.5.3'.freeze
3
3
  end
@@ -16,8 +16,8 @@ module Socket2me
16
16
  # @return [Hash] hash of options compatible with EM::WebSocket#start
17
17
  def ws_options
18
18
  {
19
- host: Socket2me.config.ws_host,
20
- port: Socket2me.config.ws_port
19
+ host: Socket2me.config.ws_host,
20
+ port: Socket2me.config.ws_port
21
21
  }
22
22
  end
23
23
 
data/lib/socket2me.rb CHANGED
@@ -4,7 +4,6 @@ require 'socket2me/middleware/add_script_tag'
4
4
  require 'socket2me/ws_server'
5
5
 
6
6
  module Socket2me
7
-
8
7
  def self.start_ws_server
9
8
  WsServer.instance.start
10
9
  end
data/socket2me.gemspec CHANGED
@@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'socket2me/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "socket2me"
7
+ spec.name = 'socket2me'
8
8
  spec.version = Socket2me::VERSION
9
- spec.authors = ["Scott Pierce"]
10
- spec.email = ["ddrscott@gmail.com"]
9
+ spec.authors = ['Scott Pierce']
10
+ spec.email = ['ddrscott@gmail.com']
11
11
 
12
- spec.summary = %q{Execute Javascript in the browser from the server using WebSockets}
13
- spec.homepage = "https://github.com/ddrscott/socket2me"
14
- spec.license = "MIT"
12
+ spec.summary = 'Execute Javascript in the browser from the server using WebSockets'
13
+ spec.homepage = 'https://github.com/ddrscott/socket2me'
14
+ spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.require_paths = ["lib"]
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|examples)/}) }
17
+ spec.require_paths = ['lib']
18
18
 
19
19
  spec.add_dependency 'rack', '~> 1.6'
20
20
  spec.add_dependency 'em-websocket', '~> 0.5'
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.10"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec", "~> 3.4"
22
+ spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.4'
25
25
  spec.add_development_dependency 'pry'
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socket2me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Pierce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-28 00:00:00.000000000 Z
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -110,7 +110,6 @@ files:
110
110
  - Rakefile
111
111
  - bin/console
112
112
  - bin/setup
113
- - example/dummy.ru
114
113
  - lib/socket2me.rb
115
114
  - lib/socket2me/configuration.rb
116
115
  - lib/socket2me/middleware/add_script_tag.rb
data/example/dummy.ru DELETED
@@ -1,51 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
-
3
- require 'socket2me'
4
-
5
- class Stub
6
-
7
- def initialize
8
- Socket2me.configure do |config|
9
- config.ws_host = '0.0.0.0'
10
- config.ws_port = '3002'
11
- end
12
-
13
- Socket2me.start_ws_server
14
- end
15
-
16
- def call(_)
17
- [200, {'Content-Type' => 'text/html'}, [<<-HTML]]
18
- <html>
19
- <body>
20
- <h1>Stub <small>generated by #{__FILE__}</small></h1>
21
- <script>
22
- function appendP(text) {
23
- var p = document.createElement("p");
24
- p.innerHTML = text;
25
- document.body.appendChild(p);
26
- }
27
- </script>
28
- </body>
29
- </html>
30
- HTML
31
- end
32
-
33
- def start_counter
34
- Thread.abort_on_exception = true
35
- Thread.new do
36
- while true
37
- sleep 1
38
- Socket2me.exec_js("appendP('#{Time.now}')")
39
- end
40
- end
41
- end
42
- end
43
-
44
- use Socket2me::Middleware::AddScriptTag
45
-
46
- stub = Stub.new
47
- stub.start_counter
48
-
49
- run stub
50
-
51
-