stealth 0.10.2 → 0.10.3

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
- SHA256:
3
- metadata.gz: 2f83e4487628f655994dec39aeb5258a3ea025d44a3cac4246f96601ab97ce47
4
- data.tar.gz: 5aacfce7dffa452760ec58a2039c02942a7505f8dcc7c86d145b9c7c14f8afbc
2
+ SHA1:
3
+ metadata.gz: 34868369470ef736c0356793ff7bcc8b9d259cad
4
+ data.tar.gz: 802522ae820d81e2232408b2b6c5eae400d67642
5
5
  SHA512:
6
- metadata.gz: 1fbffa4f483f158a5d9bb64ef7ded968467ff923ec59e7dbb330472e8d88a53a96d686af805a37c6124cf9465a7ebe74bef82d22dc65447c65c2e861d1e5e982
7
- data.tar.gz: 4addf66269c126893d698b0b42e3ff285d90619ea71b38e36ed45e2ea82641a7504a1b23dd6e948627653ce7bedbffd2a12e8c0f5ed0b08dc5299e671fc46b67
6
+ metadata.gz: d65b12faa1e3d4f7f6cad7cf36d8e6c31624c5b7229f301549f0db58fb92db438f8a8d9314f1141507acf8b1a41fdaeda036bb947b4ae623f02da3a12006f42e
7
+ data.tar.gz: 13bbf47471bf4fcdf2ae4c7c29d0393e8d8d3492ed355db6e1315004dc778ce8695a692ddef5601dfd6b51326239009896b26984e80f5947f588b830f72dc9a1
data/.circleci/config.yml CHANGED
@@ -1,20 +1,59 @@
1
- # Ruby CircleCI 2.0 configuration file
2
- #
3
- # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
- #
5
1
  version: 2
2
+
6
3
  jobs:
7
- build:
4
+ ruby_2_4:
8
5
  docker:
9
- # specify the version you desire here
10
- - image: circleci/ruby:2.4.1-node-browsers
11
- environment:
12
- STEALTH_ENV: test
6
+ - image: circleci/ruby:2.4-node-browsers
7
+ environment:
8
+ STEALTH_ENV: test
9
+
10
+ working_directory: ~/repo
11
+
12
+ steps:
13
+ - checkout
14
+
15
+ # Download and cache dependencies
16
+ - restore_cache:
17
+ keys:
18
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
19
+ # fallback to using the latest cache if no exact match is found
20
+ - v1-dependencies-
21
+
22
+ - run:
23
+ name: install dependencies
24
+ command: |
25
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
13
26
 
14
- # Specify service dependencies here if necessary
15
- # CircleCI maintains a library of pre-built images
16
- # documented at https://circleci.com/docs/2.0/circleci-images/
17
- # - image: circleci/postgres:9.4
27
+ - save_cache:
28
+ paths:
29
+ - ./vendor/bundle
30
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
31
+
32
+ # run tests!
33
+ - run:
34
+ name: run tests
35
+ command: |
36
+ mkdir /tmp/test-results
37
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
38
+
39
+ bundle exec rspec --format progress \
40
+ --format RspecJunitFormatter \
41
+ --out /tmp/test-results/rspec.xml \
42
+ --format progress \
43
+ -- \
44
+ $TEST_FILES
45
+
46
+ # collect reports
47
+ - store_test_results:
48
+ path: /tmp/test-results
49
+ - store_artifacts:
50
+ path: /tmp/test-results
51
+ destination: test-results
52
+ ruby_2_5:
53
+ docker:
54
+ - image: circleci/ruby:2.5-node-browsers
55
+ environment:
56
+ STEALTH_ENV: test
18
57
 
19
58
  working_directory: ~/repo
20
59
 
@@ -58,3 +97,10 @@ jobs:
58
97
  - store_artifacts:
59
98
  path: /tmp/test-results
60
99
  destination: test-results
100
+
101
+ workflows:
102
+ version: 2
103
+ build:
104
+ jobs:
105
+ - ruby_2_4
106
+ - ruby_2_5
data/Gemfile.lock CHANGED
@@ -2,7 +2,7 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  stealth (0.10.2)
5
- activesupport (~> 5.1)
5
+ activesupport (~> 5.2.0.rc1)
6
6
  multi_json (~> 1.12)
7
7
  puma (~> 3.10)
8
8
  sidekiq (~> 5.0)
@@ -12,7 +12,7 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activesupport (5.1.4)
15
+ activesupport (5.2.0.rc1)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (~> 0.7)
18
18
  minitest (~> 5.1)
@@ -20,14 +20,14 @@ GEM
20
20
  concurrent-ruby (1.0.5)
21
21
  connection_pool (2.2.1)
22
22
  diff-lcs (1.3)
23
- i18n (0.9.1)
23
+ i18n (0.9.3)
24
24
  concurrent-ruby (~> 1.0)
25
- minitest (5.10.3)
25
+ minitest (5.11.3)
26
26
  mock_redis (0.17.3)
27
- multi_json (1.12.2)
27
+ multi_json (1.13.1)
28
28
  mustermann (1.0.1)
29
29
  oj (3.3.6)
30
- puma (3.11.0)
30
+ puma (3.11.2)
31
31
  rack (2.0.3)
32
32
  rack-protection (2.0.0)
33
33
  rack
@@ -49,7 +49,7 @@ GEM
49
49
  rspec-support (3.6.0)
50
50
  rspec_junit_formatter (0.3.0)
51
51
  rspec-core (>= 2, < 4, != 2.12.0)
52
- sidekiq (5.0.5)
52
+ sidekiq (5.1.0)
53
53
  concurrent-ruby (~> 1.0)
54
54
  connection_pool (~> 2.2, >= 2.2.0)
55
55
  rack-protection (>= 1.5.0)
@@ -62,7 +62,7 @@ GEM
62
62
  thor (0.20.0)
63
63
  thread_safe (0.3.6)
64
64
  tilt (2.0.8)
65
- tzinfo (1.2.4)
65
+ tzinfo (1.2.5)
66
66
  thread_safe (~> 0.1)
67
67
 
68
68
  PLATFORMS
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.2
1
+ 0.10.3
data/lib/stealth/base.rb CHANGED
@@ -21,6 +21,7 @@ require 'stealth/service_message'
21
21
  require 'stealth/session'
22
22
  require 'stealth/controller/callbacks'
23
23
  require 'stealth/controller/catch_all'
24
+ require 'stealth/controller/helpers'
24
25
  require 'stealth/controller/controller'
25
26
  require 'stealth/flow/base'
26
27
  require 'stealth/services/base_client'
data/lib/stealth/cli.rb CHANGED
@@ -78,5 +78,17 @@ module Stealth
78
78
  service_setup_klass = "Stealth::Services::#{service.classify}::Setup".constantize
79
79
  service_setup_klass.trigger
80
80
  end
81
+
82
+
83
+ desc 'clear_sessions', 'Clears all sessions in development'
84
+ long_desc <<-EOS
85
+ `stealth clear_sessions` clears all sessions from Redis in development.
86
+
87
+ $ > stealth clear_sessions
88
+ EOS
89
+ def clear_sessions
90
+ Stealth.load_environment
91
+ $redis.flushdb if ENV['STEALTH_ENV'] == 'development'
92
+ end
81
93
  end
82
94
  end
@@ -6,6 +6,7 @@ module Stealth
6
6
 
7
7
  include Stealth::Controller::Callbacks
8
8
  include Stealth::Controller::CatchAll
9
+ include Stealth::Controller::Helpers
9
10
 
10
11
  attr_reader :current_message, :current_user_id, :current_flow,
11
12
  :current_service, :flow_controller, :action_name
@@ -92,6 +93,7 @@ module Stealth
92
93
  flow_controller.send(@action_name)
93
94
  run_catch_all(reason: 'Did not send replies, update session, or step') unless flow_controller.progressed?
94
95
  rescue StandardError => e
96
+ Stealth::Logger.l(topic: "catch_all", message: e.backtrace)
95
97
  run_catch_all(reason: e.message)
96
98
  end
97
99
  end
@@ -0,0 +1,126 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require "active_support/dependencies"
5
+
6
+ module Stealth
7
+ class Controller
8
+ module Helpers
9
+
10
+ extend ActiveSupport::Concern
11
+
12
+ class MissingHelperError < LoadError
13
+ def initialize(error, path)
14
+ @error = error
15
+ @path = "helpers/#{path}.rb"
16
+ set_backtrace error.backtrace
17
+
18
+ if error.path =~ /^#{path}(\.rb)?$/
19
+ super("Missing helper file helpers/%s.rb" % path)
20
+ else
21
+ raise error
22
+ end
23
+ end
24
+ end
25
+
26
+ # class << self; attr_accessor :helpers_path; end
27
+
28
+ included do
29
+ class_attribute :_helpers, default: Module.new
30
+ class_attribute :helpers_path, default: []
31
+ class_attribute :include_all_helpers, default: true
32
+ end
33
+
34
+ class_methods do
35
+ # When a class is inherited, wrap its helper module in a new module.
36
+ # This ensures that the parent class's module can be changed
37
+ # independently of the child class's.
38
+ def inherited(subclass)
39
+ helpers = _helpers
40
+ subclass._helpers = Module.new { include helpers }
41
+
42
+ if subclass.superclass == Stealth::Controller && Stealth::Controller.include_all_helpers
43
+ subclass.helper :all
44
+ else
45
+ subclass.class_eval { default_helper_module! } unless subclass.anonymous?
46
+ end
47
+
48
+ include subclass._helpers
49
+
50
+ super
51
+ end
52
+
53
+ def modules_for_helpers(args)
54
+ # Allow all helpers to be included
55
+ args += all_bot_helpers if args.delete(:all)
56
+
57
+ args.flatten.map! do |arg|
58
+ case arg
59
+ when String, Symbol
60
+ file_name = "#{arg.to_s.underscore}_helper"
61
+ begin
62
+ require_dependency(file_name)
63
+ rescue LoadError => e
64
+ raise Stealth::Controller::Helpers::MissingHelperError.new(e, file_name)
65
+ end
66
+
67
+ mod_name = file_name.camelize
68
+ begin
69
+ mod_name.constantize
70
+ rescue LoadError
71
+ raise NameError, "Couldn't find #{mod_name}, expected it to be defined in helpers/#{file_name}.rb"
72
+ end
73
+ when Module
74
+ arg
75
+ else
76
+ raise ArgumentError, "helper must be a String, Symbol, or Module"
77
+ end
78
+ end
79
+ end
80
+
81
+ def helper(*args, &block)
82
+ modules_for_helpers(args).each do |mod|
83
+ add_template_helper(mod)
84
+ end
85
+
86
+ _helpers.module_eval(&block) if block_given?
87
+ end
88
+
89
+ def default_helper_module!
90
+ module_name = name.sub(/Controller$/, "".freeze)
91
+ module_path = module_name.underscore
92
+ helper module_path
93
+ rescue LoadError => e
94
+ raise e unless e.is_missing? "helpers/#{module_path}_helper"
95
+ rescue NameError => e
96
+ raise e unless e.missing_name? "#{module_name}Helper"
97
+ end
98
+
99
+ # Returns a list of helper names in a given path.
100
+ #
101
+ # Stealth::Controller.all_helpers_from_path 'bot/helpers'
102
+ # # => ["bot", "estimates", "tickets"]
103
+ def all_helpers_from_path(path)
104
+ helpers = Array(path).flat_map do |_path|
105
+ extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/
106
+ names = Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1'.freeze) }
107
+ names.sort!
108
+ end
109
+ helpers.uniq!
110
+ helpers
111
+ end
112
+
113
+ private
114
+ def add_template_helper(mod)
115
+ _helpers.module_eval { include mod }
116
+ end
117
+
118
+ # Extract helper names from files in "bot/helpers/**/*_helper.rb"
119
+ def all_bot_helpers
120
+ all_helpers_from_path(helpers_path)
121
+ end
122
+ end
123
+
124
+ end
125
+ end
126
+ end
@@ -5,7 +5,9 @@ module Stealth
5
5
  class Logger
6
6
 
7
7
  def self.log(topic:, message:)
8
- puts "[#{topic.upcase}] #{message}"
8
+ unless ENV['STEALTH_ENV'] == 'test'
9
+ puts "[#{topic.upcase}] #{message}"
10
+ end
9
11
  end
10
12
 
11
13
  class << self
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require File.expand_path(File.join(File.dirname(__FILE__), '..', '/spec_helper'))
@@ -0,0 +1,94 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '/spec_helper'))
5
+
6
+ $:.unshift File.expand_path("../support/helpers", __dir__)
7
+
8
+ describe "Stealth::Controller helpers" do
9
+
10
+ Stealth::Controller.helpers_path = File.expand_path("../support/helpers", __dir__)
11
+
12
+ module Fun
13
+ class GamesController < Stealth::Controller
14
+ helper :all
15
+
16
+ def say_hello_world
17
+ hello_world
18
+ end
19
+ end
20
+
21
+ class PdfController < Stealth::Controller
22
+ def say_pdf_name
23
+ generate_pdf_name
24
+ end
25
+ end
26
+ end
27
+
28
+ class BaseController < Stealth::Controller
29
+
30
+ end
31
+
32
+ class AllHelpersController < Stealth::Controller
33
+ helper :all
34
+ end
35
+
36
+ class SizzleController < Stealth::Controller
37
+ helper :standalone
38
+
39
+ def say_sizzle
40
+
41
+ end
42
+ end
43
+
44
+ class HelpersTypoController < Stealth::Controller
45
+ path = File.expand_path("../support/helpers_typo", __dir__)
46
+ $:.unshift(path)
47
+ self.helpers_path = path
48
+ end
49
+
50
+ class VoodooController < Stealth::Controller
51
+ helpers_path = File.expand_path("../support/alternate_helpers", __dir__)
52
+
53
+ # Reload helpers
54
+ _helpers = Module.new
55
+ helper :all
56
+
57
+ def zoom
58
+
59
+ end
60
+ end
61
+
62
+ let(:facebook_message) { SampleMessage.new(service: 'facebook') }
63
+ let(:all_helper_methods) { [:hello_world, :baz, :generate_pdf_name] }
64
+
65
+ describe "loading" do
66
+
67
+ it "should load all helpers if none are specified by default" do
68
+ expect(BaseController._helpers.instance_methods).to match_array(all_helper_methods)
69
+ end
70
+
71
+ it "should not load helpers if none are specified by default and include_all_helpers = false" do
72
+ Stealth::Controller.include_all_helpers = false
73
+ class HelperlessController < Stealth::Controller; end
74
+ expect(HelperlessController._helpers.instance_methods).to eq []
75
+ end
76
+
77
+ it "should load all helpers if :all is used" do
78
+ expect(AllHelpersController._helpers.instance_methods).to match_array(all_helper_methods)
79
+ end
80
+
81
+ it "should allow a controller that has loaded all helpers to access a helper method" do
82
+ expect {
83
+ Fun::GamesController.new(service_message: facebook_message.message_with_text).say_hello_world
84
+ }.to_not raise_error
85
+ end
86
+
87
+ it "should allow a controller action to access a helper method" do
88
+ expect {
89
+ Fun::PdfController.new(service_message: facebook_message.message_with_text).say_pdf_name
90
+ }.to_not raise_error
91
+ end
92
+ end
93
+
94
+ end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require File.expand_path(File.join(File.dirname(__FILE__), '..', '/spec_helper'))
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
data/spec/session_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
6
  require 'rspec'
@@ -12,5 +15,5 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
15
  $redis = MockRedis.new
13
16
 
14
17
  RSpec.configure do |config|
15
-
18
+ ENV['STEALTH_ENV'] = 'test'
16
19
  end
@@ -0,0 +1,5 @@
1
+ module FooHelper
2
+ def foo
3
+
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Fun
2
+ module GamesHelper
3
+ def hello_world
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Fun
2
+ module PdfHelper
3
+ def generate_pdf_name
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module StandaloneHelper
2
+ def baz
3
+
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ module UsersHelpeR
2
+ end
@@ -1,3 +1,6 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  class SampleMessage
2
5
 
3
6
  def initialize(service:)
data/spec/version_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
data/stealth.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.add_dependency 'thor', '~> 0.20'
18
18
  s.add_dependency 'multi_json', '~> 1.12'
19
19
  s.add_dependency 'sidekiq', '~> 5.0'
20
- s.add_dependency 'activesupport', '~> 5.1'
20
+ s.add_dependency 'activesupport', '~> 5.2.0.rc1'
21
21
 
22
22
  s.add_development_dependency 'rspec', '~> 3.6'
23
23
  s.add_development_dependency 'rspec_junit_formatter', '~> 0.3'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stealth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Gomes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-10 00:00:00.000000000 Z
11
+ date: 2018-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '5.1'
89
+ version: 5.2.0.rc1
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '5.1'
96
+ version: 5.2.0.rc1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -176,6 +176,7 @@ files:
176
176
  - lib/stealth/controller/callbacks.rb
177
177
  - lib/stealth/controller/catch_all.rb
178
178
  - lib/stealth/controller/controller.rb
179
+ - lib/stealth/controller/helpers.rb
179
180
  - lib/stealth/dispatcher.rb
180
181
  - lib/stealth/errors.rb
181
182
  - lib/stealth/flow/base.rb
@@ -197,6 +198,7 @@ files:
197
198
  - lib/stealth/version.rb
198
199
  - spec/configuration_spec.rb
199
200
  - spec/controller/callbacks_spec.rb
201
+ - spec/controller/helpers_spec.rb
200
202
  - spec/controller/state_transitions_spec.rb
201
203
  - spec/flow/flow_spec.rb
202
204
  - spec/flow/state_spec.rb
@@ -204,6 +206,11 @@ files:
204
206
  - spec/service_reply_spec.rb
205
207
  - spec/session_spec.rb
206
208
  - spec/spec_helper.rb
209
+ - spec/support/alternate_helpers/foo_helper.rb
210
+ - spec/support/helpers/fun/games_helper.rb
211
+ - spec/support/helpers/fun/pdf_helper.rb
212
+ - spec/support/helpers/standalone_helper.rb
213
+ - spec/support/helpers_typo/users_helper.rb
207
214
  - spec/support/sample_messages.rb
208
215
  - spec/support/services.yml
209
216
  - spec/support/services_with_erb.yml
@@ -229,13 +236,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
236
  version: '0'
230
237
  requirements: []
231
238
  rubyforge_project:
232
- rubygems_version: 2.7.3
239
+ rubygems_version: 2.6.12
233
240
  signing_key:
234
241
  specification_version: 4
235
242
  summary: Ruby framework for conversational bots
236
243
  test_files:
237
244
  - spec/configuration_spec.rb
238
245
  - spec/controller/callbacks_spec.rb
246
+ - spec/controller/helpers_spec.rb
239
247
  - spec/controller/state_transitions_spec.rb
240
248
  - spec/flow/flow_spec.rb
241
249
  - spec/flow/state_spec.rb
@@ -243,6 +251,11 @@ test_files:
243
251
  - spec/service_reply_spec.rb
244
252
  - spec/session_spec.rb
245
253
  - spec/spec_helper.rb
254
+ - spec/support/alternate_helpers/foo_helper.rb
255
+ - spec/support/helpers/fun/games_helper.rb
256
+ - spec/support/helpers/fun/pdf_helper.rb
257
+ - spec/support/helpers/standalone_helper.rb
258
+ - spec/support/helpers_typo/users_helper.rb
246
259
  - spec/support/sample_messages.rb
247
260
  - spec/support/services.yml
248
261
  - spec/support/services_with_erb.yml