charyf 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +6 -0
  3. data/Gemfile.lock +154 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +18 -0
  6. data/Rakefile +6 -0
  7. data/bin/charyf-debug +7 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/charyf.gemspec +48 -0
  11. data/exe/charyf +4 -0
  12. data/lib/charyf/deps.rb +9 -0
  13. data/lib/charyf/engine/all.rb +22 -0
  14. data/lib/charyf/engine/charyf.rb +5 -0
  15. data/lib/charyf/engine/context.rb +61 -0
  16. data/lib/charyf/engine/controller/actions.rb +29 -0
  17. data/lib/charyf/engine/controller/controller.rb +62 -0
  18. data/lib/charyf/engine/controller/conversation.rb +58 -0
  19. data/lib/charyf/engine/controller/helpers.rb +38 -0
  20. data/lib/charyf/engine/controller/renderers.rb +103 -0
  21. data/lib/charyf/engine/dispatcher/base.rb +121 -0
  22. data/lib/charyf/engine/dispatcher/default.rb +60 -0
  23. data/lib/charyf/engine/intent/intent.rb +54 -0
  24. data/lib/charyf/engine/intent/processors/dummy.rb +30 -0
  25. data/lib/charyf/engine/intent/processors/helpers.rb +32 -0
  26. data/lib/charyf/engine/intent/processors/processor.rb +56 -0
  27. data/lib/charyf/engine/interface/interface.rb +35 -0
  28. data/lib/charyf/engine/interface/program.rb +59 -0
  29. data/lib/charyf/engine/request.rb +32 -0
  30. data/lib/charyf/engine/response.rb +41 -0
  31. data/lib/charyf/engine/session/processors/default.rb +42 -0
  32. data/lib/charyf/engine/session/processors/processor.rb +39 -0
  33. data/lib/charyf/engine/session/session.rb +68 -0
  34. data/lib/charyf/engine/skill/info.rb +24 -0
  35. data/lib/charyf/engine/skill/routing.rb +57 -0
  36. data/lib/charyf/engine/skill/skill.rb +40 -0
  37. data/lib/charyf/engine.rb +3 -0
  38. data/lib/charyf/support/all.rb +4 -0
  39. data/lib/charyf/support/hash.rb +43 -0
  40. data/lib/charyf/support/object.rb +7 -0
  41. data/lib/charyf/support/string.rb +94 -0
  42. data/lib/charyf/support/string_inquirer.rb +17 -0
  43. data/lib/charyf/support.rb +1 -0
  44. data/lib/charyf/utils/all.rb +13 -0
  45. data/lib/charyf/utils/app_engine/extensions.rb +21 -0
  46. data/lib/charyf/utils/app_engine.rb +24 -0
  47. data/lib/charyf/utils/app_loader.rb +38 -0
  48. data/lib/charyf/utils/application/bootstrap.rb +176 -0
  49. data/lib/charyf/utils/application/configuration.rb +51 -0
  50. data/lib/charyf/utils/application.rb +131 -0
  51. data/lib/charyf/utils/charyf.rb +44 -0
  52. data/lib/charyf/utils/cli.rb +14 -0
  53. data/lib/charyf/utils/command/actions.rb +24 -0
  54. data/lib/charyf/utils/command/base.rb +138 -0
  55. data/lib/charyf/utils/command/behavior.rb +81 -0
  56. data/lib/charyf/utils/command/environment_argument.rb +40 -0
  57. data/lib/charyf/utils/command.rb +106 -0
  58. data/lib/charyf/utils/commands/all.rb +6 -0
  59. data/lib/charyf/utils/commands/application/application_command.rb +21 -0
  60. data/lib/charyf/utils/commands/cli/cli_command.rb +115 -0
  61. data/lib/charyf/utils/commands/console/console_command.rb +77 -0
  62. data/lib/charyf/utils/commands/destroy/destroy_command.rb +26 -0
  63. data/lib/charyf/utils/commands/generate/generate_command.rb +31 -0
  64. data/lib/charyf/utils/commands/help/USAGE +9 -0
  65. data/lib/charyf/utils/commands/help/help.rb +20 -0
  66. data/lib/charyf/utils/commands.rb +15 -0
  67. data/lib/charyf/utils/configuration.rb +36 -0
  68. data/lib/charyf/utils/error_handler.rb +26 -0
  69. data/lib/charyf/utils/extension/configurable.rb +41 -0
  70. data/lib/charyf/utils/extension/configuration.rb +63 -0
  71. data/lib/charyf/utils/extension.rb +129 -0
  72. data/lib/charyf/utils/generator/actions.rb +281 -0
  73. data/lib/charyf/utils/generator/base.rb +288 -0
  74. data/lib/charyf/utils/generators/app/USAGE +8 -0
  75. data/lib/charyf/utils/generators/app/app_generator.rb +274 -0
  76. data/lib/charyf/utils/generators/app/templates/Gemfile.erb +20 -0
  77. data/lib/charyf/utils/generators/app/templates/README.md +24 -0
  78. data/lib/charyf/utils/generators/app/templates/app/skill_controller.rb.tt +8 -0
  79. data/lib/charyf/utils/generators/app/templates/bin/charyf +5 -0
  80. data/lib/charyf/utils/generators/app/templates/config/application.rb.tt +32 -0
  81. data/lib/charyf/utils/generators/app/templates/config/boot.rb.tt +4 -0
  82. data/lib/charyf/utils/generators/app/templates/config/chapp.rb.tt +5 -0
  83. data/lib/charyf/utils/generators/app/templates/config/environments/development.rb.tt +2 -0
  84. data/lib/charyf/utils/generators/app/templates/config/environments/production.rb.tt +2 -0
  85. data/lib/charyf/utils/generators/app/templates/config/environments/test.rb.tt +2 -0
  86. data/lib/charyf/utils/generators/app/templates/config/load.rb.tt +17 -0
  87. data/lib/charyf/utils/generators/app/templates/gitignore +18 -0
  88. data/lib/charyf/utils/generators/app_base.rb +277 -0
  89. data/lib/charyf/utils/generators/defaults.rb +75 -0
  90. data/lib/charyf/utils/generators/intents/intents_generator.rb +41 -0
  91. data/lib/charyf/utils/generators/named_base.rb +73 -0
  92. data/lib/charyf/utils/generators/skill/skill_generator.rb +47 -0
  93. data/lib/charyf/utils/generators/skill/templates/controllers/skill_controller.rb.tt +10 -0
  94. data/lib/charyf/utils/generators/skill/templates/module.rb.tt +6 -0
  95. data/lib/charyf/utils/generators/skill/templates/skill.rb.tt +3 -0
  96. data/lib/charyf/utils/generators.rb +187 -0
  97. data/lib/charyf/utils/initializable.rb +95 -0
  98. data/lib/charyf/utils/logger.rb +26 -0
  99. data/lib/charyf/utils/machine.rb +129 -0
  100. data/lib/charyf/utils/parser/en_parser.rb +97 -0
  101. data/lib/charyf/utils/parser/parser.rb +37 -0
  102. data/lib/charyf/utils/ruby_version_check.rb +15 -0
  103. data/lib/charyf/utils/storage/provider.rb +44 -0
  104. data/lib/charyf/utils/strategy.rb +44 -0
  105. data/lib/charyf/utils/utils.rb +64 -0
  106. data/lib/charyf/utils.rb +2 -0
  107. data/lib/charyf/version.rb +19 -0
  108. data/lib/charyf.rb +18 -0
  109. data/lib/locale/en.yml +206 -0
  110. data/todo.md +3 -0
  111. metadata +272 -0
@@ -0,0 +1,274 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../app_base'
4
+ require_relative '../../../support'
5
+
6
+ module Charyf
7
+ module Generators
8
+ # The application builder allows you to override elements of the application
9
+ # generator without being forced to reverse the operations of the default
10
+ # generator.
11
+ #
12
+ # This allows you to override entire operations, like the creation of the
13
+ # Gemfile, README, or JavaScript files, without needing to know exactly
14
+ # what those operations do so you can create another template action.
15
+ #
16
+ # class CustomAppBuilder < Charyf::Generators::AppBuilder
17
+ # def test
18
+ # @generator.gem "rspec", group: [:development, :test]
19
+ # run "bundle install"
20
+ # generate "rspec:install"
21
+ # end
22
+ # end
23
+ class AppBuilder
24
+ # def rakefile
25
+ # template "Rakefile"
26
+ # end
27
+ #
28
+ def readme
29
+ copy_file 'README.md', 'README.md'
30
+ end
31
+
32
+ def gemfile
33
+ template 'Gemfile.erb', 'Gemfile'
34
+ end
35
+
36
+ def update_gemfile
37
+
38
+ gemfile_entries.each do |entry|
39
+ options = entry.options.dup
40
+ options[:comment] = entry.comment if entry.comment && !entry.comment.empty?
41
+
42
+ versions = entry.version ? entry.version.split(", ") : nil
43
+
44
+ args = [entry.name, versions, options].flatten.compact
45
+
46
+ @generator.gem *args
47
+ end
48
+
49
+ end
50
+
51
+ def gitignore
52
+ template 'gitignore', '.gitignore'
53
+ end
54
+
55
+ def version_control
56
+ if !options[:skip_git] && !options[:pretend]
57
+ run "git init", capture: options[:quiet]
58
+ end
59
+ end
60
+
61
+ def app
62
+ directory "app"
63
+
64
+ empty_directory_with_keep_file "app/skills"
65
+ end
66
+
67
+ def bin
68
+ directory "bin" do |content|
69
+ "#{shebang}\n" + content
70
+ end
71
+
72
+ chmod "bin", 0755 & ~File.umask, verbose: false
73
+ end
74
+
75
+ def config
76
+ empty_directory "config"
77
+
78
+ inside "config" do
79
+ template "application.rb"
80
+ template "boot.rb"
81
+ template "chapp.rb"
82
+ template "load.rb"
83
+
84
+ directory "environments"
85
+ empty_directory_with_keep_file "initializers"
86
+ end
87
+ end
88
+
89
+ def lib
90
+ empty_directory "lib"
91
+ end
92
+
93
+ def log
94
+ empty_directory_with_keep_file "log"
95
+ end
96
+
97
+ def tmp
98
+ empty_directory_with_keep_file "tmp"
99
+ end
100
+ end
101
+
102
+ CHARYF_DEV_PATH = File.expand_path('../../../../..', __dir__)
103
+ RESERVED_NAMES = %w[application skill plugin runner test generator install new]
104
+
105
+ class AppGenerator < AppBase # :nodoc:
106
+ # WEBPACKS = %w( react vue angular elm )
107
+
108
+ add_shared_options_for 'application'
109
+
110
+ desc_file File.expand_path('USAGE', __dir__)
111
+
112
+ class_option :version, type: :boolean, aliases: "-v", group: :charyf,
113
+ desc: "Show Charyf version number and quit"
114
+
115
+ class_option :skip_bundle, type: :boolean, aliases: "-B", default: false,
116
+ desc: "Don't run bundle install"
117
+
118
+ def initialize(*args)
119
+ super
120
+ if options[:lib]
121
+ self.options = options.merge(skip_git: true).freeze
122
+ end
123
+
124
+ end
125
+ #
126
+ public_task :set_default_accessors!
127
+ public_task :create_root
128
+ #
129
+ def create_root_files
130
+ build(:readme)
131
+ build(:gitignore) unless options[:skip_git]
132
+ build(:version_control)
133
+
134
+
135
+ unless options[:skip_gemfile]
136
+ if options[:lib]
137
+
138
+ begin
139
+ # Temporary change root
140
+ self.destination_root = File.expand_path('..', destination_root)
141
+ if File.exist?(File.join(destination_root, 'Gemfile'))
142
+ build(:update_gemfile)
143
+ else
144
+ build(:gemfile)
145
+ end
146
+ ensure
147
+ self.destination_root = File.expand_path('charyf', destination_root)
148
+ end
149
+
150
+ else
151
+ build(:gemfile)
152
+ end
153
+ end
154
+ end
155
+
156
+ def create_app_files
157
+ build(:app)
158
+ end
159
+
160
+ def create_bin_files
161
+ build(:bin)
162
+ end
163
+
164
+ def create_config_files
165
+ build(:config)
166
+ end
167
+
168
+ def create_lib_files
169
+ build(:lib)
170
+ end
171
+
172
+ def create_log_files
173
+ build(:log)
174
+ end
175
+
176
+ def create_tmp_files
177
+ build(:tmp)
178
+ end
179
+
180
+ public_task :run_bundle
181
+
182
+ def run_after_bundle_callbacks
183
+ @after_bundle_callbacks.each(&:call)
184
+ end
185
+
186
+ def self.banner
187
+ "charyf new #{arguments.map(&:usage).join(' ')} [options] \n"
188
+ end
189
+
190
+ private
191
+
192
+ def app_name
193
+ @app_name ||= (defined_app_const_base? ? defined_app_name : File.basename(destination_root)).tr('\\', "").tr(". ", "_")
194
+ end
195
+
196
+ def defined_app_name
197
+ defined_app_const_base.underscore
198
+ end
199
+
200
+ def defined_app_const_base
201
+ Charyf.respond_to?(:application) && defined?(Charyf::Application) &&
202
+ Charyf.application.is_a?(Charyf::Application) && Charyf.application.class.name.sub(/::Application$/, "")
203
+ end
204
+ #
205
+ alias :defined_app_const_base? :defined_app_const_base
206
+
207
+ def app_const_base
208
+ @app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, "_").squeeze("_").camelize
209
+ end
210
+ alias :camelized :app_const_base
211
+
212
+ def app_const
213
+ @app_const ||= "#{app_const_base}::Application"
214
+ end
215
+
216
+ def valid_const?
217
+ if app_const =~ /^\d/
218
+ raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers."
219
+ elsif RESERVED_NAMES.include?(app_name)
220
+ raise Error, "Invalid application name #{app_name}. Please give a " \
221
+ "name which does not match one of the reserved charyf " \
222
+ "words: #{RESERVED_NAMES.join(", ")}"
223
+ elsif Object.const_defined?(app_const_base)
224
+ raise Error, "Invalid application name #{app_name}, constant #{app_const_base} is already in use. Please choose another application name."
225
+ end
226
+ end
227
+
228
+ def get_builder_class
229
+ defined?(::AppBuilder) ? ::AppBuilder : Charyf::Generators::AppBuilder
230
+ end
231
+ end
232
+
233
+ # This class handles preparation of the arguments before the AppGenerator is
234
+ # called.
235
+ #
236
+ # This class should be called before the AppGenerator is required and started
237
+ # since it configures and mutates ARGV correctly.
238
+ class ARGVScrubber # :nodoc:
239
+
240
+ VERSION_ARGS = %w(--version -v)
241
+
242
+ def initialize(argv = ARGV)
243
+ @argv = argv
244
+ end
245
+
246
+ #
247
+ def prepare!
248
+ handle_version_request!(@argv.first)
249
+ handle_invalid_command!(@argv.first, @argv) do
250
+ return @argv.drop(1)
251
+ end
252
+ end
253
+
254
+ private
255
+
256
+ def handle_version_request!(argument)
257
+ if VERSION_ARGS.include?(argument)
258
+ require_relative '../../../version'
259
+ puts "Charyf #{Charyf.version}"
260
+ exit(0)
261
+ end
262
+ end
263
+
264
+ def handle_invalid_command!(argument, argv)
265
+ if argument == 'new'
266
+ yield
267
+ else
268
+ ['--help'] + argv.drop(1)
269
+ end
270
+ end
271
+
272
+ end
273
+ end
274
+ end
@@ -0,0 +1,20 @@
1
+ source 'https://rubygems.org'
2
+
3
+ <% gemfile_entries.each do |gem| -%>
4
+ <% if gem.comment -%>
5
+ # <%= gem.comment %>
6
+ <% end -%>
7
+ <%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<%= %(, '#{gem.version}') if gem.version -%>
8
+ <% if gem.options.any? -%>
9
+ , <%= gem.options.map { |k,v|
10
+ "#{k}: #{v.inspect}" }.join(', ') -%>
11
+ <% end -%>
12
+
13
+
14
+ <% end %>
15
+ group :development, :test do
16
+ gem 'pry'
17
+ <% if RUBY_ENGINE == 'ruby' -%>
18
+ gem 'pry-byebug'
19
+ <% end -%>
20
+ end
@@ -0,0 +1,24 @@
1
+ # README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
@@ -0,0 +1,8 @@
1
+ class SkillController < Charyf::Controller::Base
2
+
3
+ def unknown
4
+ logger.warn("Unknown response for request: #{request.inspect}")
5
+ reply(text: "I am sorry, I can't help you with that.")
6
+ end
7
+
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ APP_PATH = File.expand_path('../config/application', __dir__)
4
+ require_relative '../config/boot'
5
+ require 'charyf/utils/commands'
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+ # Charyf does not use Bundler.require in order to reduce boot time
3
+ # Each gem should be loaded individually using 'require'
4
+ # To load gem only in specific environment, add the require statement
5
+ # to the correct file in the environments folder
6
+ require 'charyf'
7
+ require_relative 'load'
8
+
9
+ module <%= app_const_base %>
10
+ class Application < Charyf::Application
11
+
12
+ # I18n
13
+ config.i18n.available_locales = [:en]
14
+
15
+ config.i18n.default_locale = :en
16
+
17
+ # Processor
18
+ config.enabled_intent_processors = <%= intents_details.keys -%>
19
+
20
+ # Storage
21
+ config.storage_provider = :<%= options[:storage_provider] -%>
22
+
23
+ # Dispatcher
24
+ # No other supported dispatchers now
25
+ # config.dispatcher = :default
26
+
27
+ # Session
28
+ # Sessions are currently unsupported
29
+ # config.dispatcher = :default
30
+
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ # Set up gems listed in the Gemfile
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../<%= "../" if lib? -%>Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the Charyf application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Charyf application.
5
+ Charyf.application.initialize!
@@ -0,0 +1,2 @@
1
+ Charyf.application.configure do
2
+ end
@@ -0,0 +1,2 @@
1
+ Charyf.application.configure do
2
+ end
@@ -0,0 +1,2 @@
1
+ Charyf.application.configure do
2
+ end
@@ -0,0 +1,17 @@
1
+ # As we don't support the idea of auto require at boot,
2
+ # we provide you a way to require everything you need in front.
3
+ #
4
+ # We suggest to require everything only when needed
5
+ #
6
+ # Here you can list requires to all libraries that need to be present at boot time
7
+ # Typically all charyf components like intent processors and memory providers
8
+
9
+ # Require storage provider
10
+ require '<%= storage_details[:require] -%>'
11
+
12
+
13
+ # Require intent processors
14
+ <% intents_details.values.each do |details| -%>
15
+ require '<%= details[:require] -%>'
16
+ <% end -%>
17
+
@@ -0,0 +1,18 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore all logfiles and tempfiles.
11
+ /log/*
12
+ /tmp/*
13
+ <% if keeps? -%>
14
+ !/log/.keep
15
+ !/tmp/.keep
16
+ <% end -%>
17
+
18
+ .byebug_history