xip 0.0.1 → 2.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +116 -0
  3. data/.gitignore +12 -0
  4. data/CHANGELOG.md +135 -0
  5. data/Gemfile +4 -1
  6. data/Gemfile.lock +65 -15
  7. data/LICENSE +6 -4
  8. data/README.md +51 -1
  9. data/VERSION +1 -0
  10. data/bin/xip +3 -11
  11. data/lib/xip.rb +1 -3
  12. data/lib/xip/base.rb +189 -0
  13. data/lib/xip/cli.rb +273 -0
  14. data/lib/xip/cli_base.rb +24 -0
  15. data/lib/xip/commands/command.rb +13 -0
  16. data/lib/xip/commands/console.rb +74 -0
  17. data/lib/xip/commands/server.rb +63 -0
  18. data/lib/xip/configuration.rb +56 -0
  19. data/lib/xip/controller/callbacks.rb +63 -0
  20. data/lib/xip/controller/catch_all.rb +84 -0
  21. data/lib/xip/controller/controller.rb +274 -0
  22. data/lib/xip/controller/dev_jumps.rb +40 -0
  23. data/lib/xip/controller/dynamic_delay.rb +61 -0
  24. data/lib/xip/controller/helpers.rb +128 -0
  25. data/lib/xip/controller/interrupt_detect.rb +99 -0
  26. data/lib/xip/controller/messages.rb +283 -0
  27. data/lib/xip/controller/nlp.rb +49 -0
  28. data/lib/xip/controller/replies.rb +281 -0
  29. data/lib/xip/controller/unrecognized_message.rb +61 -0
  30. data/lib/xip/core_ext.rb +5 -0
  31. data/lib/xip/core_ext/numeric.rb +10 -0
  32. data/lib/xip/core_ext/string.rb +18 -0
  33. data/lib/xip/dispatcher.rb +68 -0
  34. data/lib/xip/errors.rb +55 -0
  35. data/lib/xip/flow/base.rb +69 -0
  36. data/lib/xip/flow/specification.rb +56 -0
  37. data/lib/xip/flow/state.rb +82 -0
  38. data/lib/xip/generators/builder.rb +41 -0
  39. data/lib/xip/generators/builder/.gitignore +30 -0
  40. data/lib/xip/generators/builder/Gemfile +19 -0
  41. data/lib/xip/generators/builder/Procfile.dev +2 -0
  42. data/lib/xip/generators/builder/README.md +9 -0
  43. data/lib/xip/generators/builder/Rakefile +2 -0
  44. data/lib/xip/generators/builder/bot/controllers/bot_controller.rb +55 -0
  45. data/lib/xip/generators/builder/bot/controllers/catch_alls_controller.rb +21 -0
  46. data/lib/xip/generators/builder/bot/controllers/concerns/.keep +0 -0
  47. data/lib/xip/generators/builder/bot/controllers/goodbyes_controller.rb +9 -0
  48. data/lib/xip/generators/builder/bot/controllers/hellos_controller.rb +9 -0
  49. data/lib/xip/generators/builder/bot/controllers/interrupts_controller.rb +9 -0
  50. data/lib/xip/generators/builder/bot/controllers/unrecognized_messages_controller.rb +9 -0
  51. data/lib/xip/generators/builder/bot/helpers/bot_helper.rb +2 -0
  52. data/lib/xip/generators/builder/bot/models/bot_record.rb +3 -0
  53. data/lib/xip/generators/builder/bot/models/concerns/.keep +0 -0
  54. data/lib/xip/generators/builder/bot/replies/catch_alls/level1.yml +2 -0
  55. data/lib/xip/generators/builder/bot/replies/goodbyes/say_goodbye.yml +2 -0
  56. data/lib/xip/generators/builder/bot/replies/hellos/say_hello.yml +2 -0
  57. data/lib/xip/generators/builder/config.ru +4 -0
  58. data/lib/xip/generators/builder/config/boot.rb +6 -0
  59. data/lib/xip/generators/builder/config/database.yml +25 -0
  60. data/lib/xip/generators/builder/config/environment.rb +2 -0
  61. data/lib/xip/generators/builder/config/flow_map.rb +25 -0
  62. data/lib/xip/generators/builder/config/initializers/autoload.rb +8 -0
  63. data/lib/xip/generators/builder/config/initializers/inflections.rb +16 -0
  64. data/lib/xip/generators/builder/config/puma.rb +25 -0
  65. data/lib/xip/generators/builder/config/services.yml +35 -0
  66. data/lib/xip/generators/builder/config/sidekiq.yml +3 -0
  67. data/lib/xip/generators/builder/db/seeds.rb +7 -0
  68. data/lib/xip/generators/generate.rb +39 -0
  69. data/lib/xip/generators/generate/flow/controllers/controller.tt +7 -0
  70. data/lib/xip/generators/generate/flow/helpers/helper.tt +3 -0
  71. data/lib/xip/generators/generate/flow/replies/ask_example.tt +9 -0
  72. data/lib/xip/helpers/redis.rb +40 -0
  73. data/lib/xip/jobs.rb +9 -0
  74. data/lib/xip/lock.rb +82 -0
  75. data/lib/xip/logger.rb +9 -3
  76. data/lib/xip/migrations/configurator.rb +73 -0
  77. data/lib/xip/migrations/generators.rb +16 -0
  78. data/lib/xip/migrations/railtie_config.rb +14 -0
  79. data/lib/xip/migrations/tasks.rb +43 -0
  80. data/lib/xip/nlp/client.rb +21 -0
  81. data/lib/xip/nlp/result.rb +56 -0
  82. data/lib/xip/reloader.rb +89 -0
  83. data/lib/xip/reply.rb +36 -0
  84. data/lib/xip/scheduled_reply.rb +18 -0
  85. data/lib/xip/server.rb +63 -0
  86. data/lib/xip/service_message.rb +17 -0
  87. data/lib/xip/service_reply.rb +44 -0
  88. data/lib/xip/services/base_client.rb +24 -0
  89. data/lib/xip/services/base_message_handler.rb +27 -0
  90. data/lib/xip/services/base_reply_handler.rb +72 -0
  91. data/lib/xip/services/jobs/handle_message_job.rb +21 -0
  92. data/lib/xip/session.rb +203 -0
  93. data/lib/xip/version.rb +7 -1
  94. data/logo.svg +17 -0
  95. data/spec/configuration_spec.rb +93 -0
  96. data/spec/controller/callbacks_spec.rb +217 -0
  97. data/spec/controller/catch_all_spec.rb +154 -0
  98. data/spec/controller/controller_spec.rb +889 -0
  99. data/spec/controller/dynamic_delay_spec.rb +70 -0
  100. data/spec/controller/helpers_spec.rb +119 -0
  101. data/spec/controller/interrupt_detect_spec.rb +171 -0
  102. data/spec/controller/messages_spec.rb +744 -0
  103. data/spec/controller/nlp_spec.rb +93 -0
  104. data/spec/controller/replies_spec.rb +694 -0
  105. data/spec/controller/unrecognized_message_spec.rb +168 -0
  106. data/spec/dispatcher_spec.rb +79 -0
  107. data/spec/flow/flow_spec.rb +82 -0
  108. data/spec/flow/state_spec.rb +109 -0
  109. data/spec/helpers/redis_spec.rb +77 -0
  110. data/spec/lock_spec.rb +100 -0
  111. data/spec/nlp/client_spec.rb +23 -0
  112. data/spec/nlp/result_spec.rb +57 -0
  113. data/spec/replies/hello.yml.erb +15 -0
  114. data/spec/replies/messages/say_hola.yml+facebook.erb +6 -0
  115. data/spec/replies/messages/say_hola.yml+twilio.erb +6 -0
  116. data/spec/replies/messages/say_hola.yml.erb +6 -0
  117. data/spec/replies/messages/say_howdy_with_dynamic.yml +79 -0
  118. data/spec/replies/messages/say_msgs_without_breaks.yml +4 -0
  119. data/spec/replies/messages/say_offer.yml +6 -0
  120. data/spec/replies/messages/say_offer_with_dynamic.yml +6 -0
  121. data/spec/replies/messages/say_oi.yml.erb +15 -0
  122. data/spec/replies/messages/say_randomize_speech.yml +10 -0
  123. data/spec/replies/messages/say_randomize_text.yml +10 -0
  124. data/spec/replies/messages/say_yo.yml +6 -0
  125. data/spec/replies/messages/say_yo.yml+twitter +6 -0
  126. data/spec/replies/messages/sub1/sub2/say_nested.yml +10 -0
  127. data/spec/reply_spec.rb +61 -0
  128. data/spec/scheduled_reply_spec.rb +23 -0
  129. data/spec/service_reply_spec.rb +92 -0
  130. data/spec/session_spec.rb +366 -0
  131. data/spec/spec_helper.rb +22 -66
  132. data/spec/support/alternate_helpers/foo_helper.rb +5 -0
  133. data/spec/support/controllers/vaders_controller.rb +24 -0
  134. data/spec/support/helpers/fun/games_helper.rb +7 -0
  135. data/spec/support/helpers/fun/pdf_helper.rb +7 -0
  136. data/spec/support/helpers/standalone_helper.rb +5 -0
  137. data/spec/support/helpers_typo/users_helper.rb +2 -0
  138. data/spec/support/nlp_clients/dialogflow.rb +9 -0
  139. data/spec/support/nlp_clients/luis.rb +9 -0
  140. data/spec/support/nlp_results/luis_result.rb +163 -0
  141. data/spec/support/sample_messages.rb +66 -0
  142. data/spec/support/services.yml +31 -0
  143. data/spec/support/services_with_erb.yml +31 -0
  144. data/spec/version_spec.rb +16 -0
  145. data/xip.gemspec +25 -14
  146. metadata +320 -18
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0.beta2
data/bin/xip CHANGED
@@ -1,13 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative '../lib/xip/cli'
4
-
5
- begin
6
- cli = Xip::CLI.instance
7
- cli.parse
8
- cli.run
9
- rescue => e
10
- STDERR.puts e.message
11
- STDERR.puts e.backtrace.join("\n")
12
- exit 1
13
- end
3
+ require 'bundler'
4
+ require 'xip/cli'
5
+ Xip::Cli.start
data/lib/xip.rb CHANGED
@@ -1,3 +1 @@
1
- # frozen_string_literal: true
2
-
3
- require 'xip/version'
1
+ require 'xip/base'
@@ -0,0 +1,189 @@
1
+ # frozen_string_literal: true
2
+
3
+ # base requirements
4
+ require 'yaml'
5
+ require 'sidekiq'
6
+ require 'active_support/all'
7
+
8
+ begin
9
+ require "rails"
10
+ require "active_record"
11
+ rescue LoadError
12
+ # Don't require ActiveRecord
13
+ end
14
+
15
+ # core
16
+ require 'xip/version'
17
+ require 'xip/errors'
18
+ require 'xip/core_ext'
19
+ require 'xip/logger'
20
+ require 'xip/configuration'
21
+ require 'xip/reloader'
22
+
23
+ # helpers
24
+ require 'xip/helpers/redis'
25
+
26
+ module Xip
27
+
28
+ def self.env
29
+ @env ||= ActiveSupport::StringInquirer.new(ENV['XIP_ENV'] || 'development')
30
+ end
31
+
32
+ def self.root
33
+ @root ||= File.expand_path(Pathname.new(Dir.pwd))
34
+ end
35
+
36
+ def self.boot
37
+ load_services_config
38
+ load_environment
39
+ end
40
+
41
+ def self.config
42
+ Thread.current[:configuration] ||= load_services_config
43
+ end
44
+
45
+ def self.configuration=(config)
46
+ Thread.current[:configuration] = config
47
+ end
48
+
49
+ def self.default_autoload_paths
50
+ [
51
+ File.join(Xip.root, 'bot', 'controllers', 'concerns'),
52
+ File.join(Xip.root, 'bot', 'controllers'),
53
+ File.join(Xip.root, 'bot', 'models', 'concerns'),
54
+ File.join(Xip.root, 'bot', 'models'),
55
+ File.join(Xip.root, 'bot', 'helpers'),
56
+ File.join(Xip.root, 'config')
57
+ ]
58
+ end
59
+
60
+ def self.bot_reloader
61
+ @bot_reloader
62
+ end
63
+
64
+ def self.set_config_defaults(config)
65
+ defaults = {
66
+ dynamic_delay_muliplier: 1.0, # values > 1 increase, values < 1 decrease delay
67
+ session_ttl: 0, # 0 seconds; don't expire sessions
68
+ lock_autorelease: 30, # 30 seconds
69
+ transcript_logging: false, # show user replies in the logs
70
+ hot_reload: Xip.env.development?, # hot reload bot files on change (dev only)
71
+ eager_load: Xip.env.production?, # eager load bot files for performance (prod only)
72
+ autoload_paths: Xip.default_autoload_paths, # array of autoload paths used in eager and hot reloading
73
+ autoload_ignore_paths: [], # paths to exclude from eager and hot reloading
74
+ nlp_integration: nil, # NLP service to use, defaults to none
75
+ log_all_nlp_results: false, # log NLP service requests; useful for debugging/improving NLP models
76
+ auto_insert_delays: true # automatically insert delays/typing indicators between all replies
77
+ }
78
+ defaults.each { |option, default| config.set_default(option, default) }
79
+ end
80
+
81
+ # Loads the services.yml configuration unless one has already been loaded
82
+ def self.load_services_config(services_yaml=nil)
83
+ @semaphore ||= Mutex.new
84
+ services_yaml ||= Xip.load_services_config(
85
+ File.read(File.join(Xip.root, 'config', 'services.yml'))
86
+ )
87
+
88
+ Thread.current[:configuration] ||= begin
89
+ @semaphore.synchronize do
90
+ services_config = YAML.load(ERB.new(services_yaml).result)
91
+
92
+ unless services_config.has_key?(env)
93
+ raise Xip::Errors::ConfigurationError, "Could not find services.yml configuration for #{env} environment"
94
+ end
95
+
96
+ config = Xip::Configuration.new(services_config[env])
97
+ set_config_defaults(config)
98
+
99
+ config
100
+ end
101
+ end
102
+ end
103
+
104
+ # Same as `load_services_config` but forces the loading even if one has
105
+ # already been loaded
106
+ def self.load_services_config!(services_yaml=nil)
107
+ Thread.current[:configuration] = nil
108
+ load_services_config(services_yaml)
109
+ end
110
+
111
+ def self.load_bot!
112
+ @bot_reloader ||= begin
113
+ bot_reloader = Xip::Reloader.new
114
+ bot_reloader.load_bot!
115
+ bot_reloader
116
+ end
117
+ end
118
+
119
+ def self.load_environment
120
+ require File.join(Xip.root, 'config', 'boot')
121
+ require_directory('config/initializers')
122
+
123
+ load_bot!
124
+
125
+ Sidekiq.options[:reloader] = Xip.bot_reloader
126
+
127
+ if defined?(ActiveRecord)
128
+ if ENV['DATABASE_URL'].present?
129
+ ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
130
+ else
131
+ database_config = File.read(File.join(Xip.root, 'config', 'database.yml'))
132
+ ActiveRecord::Base.establish_connection(
133
+ YAML.load(ERB.new(database_config).result)[Xip.env]
134
+ )
135
+ end
136
+ end
137
+ end
138
+
139
+ def self.tid
140
+ Thread.current.object_id.to_s(36)
141
+ end
142
+
143
+ def self.require_directory(directory)
144
+ for_each_file_in(directory) { |file| require_relative(file) }
145
+ end
146
+
147
+ private
148
+
149
+ def self.for_each_file_in(directory, &blk)
150
+ directory = directory.to_s.gsub(%r{(\/|\\)}, File::SEPARATOR)
151
+ directory = Pathname.new(Dir.pwd).join(directory).to_s
152
+ directory = File.join(directory, '**', '*.rb') unless directory =~ /(\*\*)/
153
+
154
+ Dir.glob(directory).sort.each(&blk)
155
+ end
156
+
157
+ end
158
+
159
+ require 'xip/jobs'
160
+ require 'xip/dispatcher'
161
+ require 'xip/server'
162
+ require 'xip/reply'
163
+ require 'xip/scheduled_reply'
164
+ require 'xip/service_reply'
165
+ require 'xip/service_message'
166
+ require 'xip/session'
167
+ require 'xip/lock'
168
+ require 'xip/nlp/result'
169
+ require 'xip/nlp/client'
170
+ require 'xip/controller/callbacks'
171
+ require 'xip/controller/replies'
172
+ require 'xip/controller/messages'
173
+ require 'xip/controller/unrecognized_message'
174
+ require 'xip/controller/catch_all'
175
+ require 'xip/controller/helpers'
176
+ require 'xip/controller/dynamic_delay'
177
+ require 'xip/controller/interrupt_detect'
178
+ require 'xip/controller/dev_jumps'
179
+ require 'xip/controller/nlp'
180
+ require 'xip/controller/controller'
181
+ require 'xip/flow/base'
182
+ require 'xip/services/base_client'
183
+
184
+ if defined?(ActiveRecord)
185
+ require 'xip/migrations/configurator'
186
+ require 'xip/migrations/generators'
187
+ require 'xip/migrations/railtie_config'
188
+ require 'xip/migrations/tasks'
189
+ end
@@ -0,0 +1,273 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require 'xip/cli_base'
5
+ require 'xip/commands/console'
6
+ require 'xip/generators/builder'
7
+ require 'xip/generators/generate'
8
+
9
+ module Xip
10
+ class Cli < Thor
11
+ extend CliBase
12
+
13
+ desc 'new', 'Creates a new Xip bot'
14
+ long_desc <<-EOS
15
+ `xip new <name>` creates a new Xip both with the given name.
16
+
17
+ $ > xip new new_bot
18
+ EOS
19
+ def new(name)
20
+ Xip::Generators::Builder.start([name])
21
+ end
22
+
23
+
24
+ desc 'generate', 'Generates scaffold Xip files'
25
+ long_desc <<-EOS
26
+ `xip generate <generator> <name>` generates scaffold Xip files
27
+
28
+ $ > xip generate flow quote
29
+ EOS
30
+ def generate(generator, name)
31
+ case generator
32
+ when 'migration'
33
+ Xip::Migrations::Generator.migration(name)
34
+ when 'flow'
35
+ Xip::Generators::Generate.start([generator, name])
36
+ else
37
+ puts "Could not find generator '#{generator}'."
38
+ puts "Run `xip help generate` for more options."
39
+ end
40
+ end
41
+ map 'g' => 'generate'
42
+
43
+
44
+ desc 'version', 'Prints xip version'
45
+ long_desc <<-EOS
46
+ `xip version` prints the version of the bundled xip gem.
47
+ EOS
48
+ def version
49
+ require 'xip/version'
50
+ puts "#{ Xip::VERSION }"
51
+ end
52
+ map %w{--version -v} => :version
53
+
54
+
55
+ desc 'server', 'Starts a xip server'
56
+ long_desc <<-EOS
57
+ `xip server` starts a server for the current xip project.
58
+
59
+ $ > xip server
60
+
61
+ $ > xip server -p 4500
62
+ EOS
63
+ method_option :port, aliases: '-p', desc: 'The port to run the server on'
64
+ method_option :help, desc: 'Displays the usage message'
65
+ def server
66
+ if options[:help]
67
+ invoke :help, ['server']
68
+ else
69
+ require 'xip/commands/server'
70
+ Xip::Commands::Server.new(port: options.fetch(:port) { 5000 }).start
71
+ end
72
+ end
73
+ map 's' => 'server'
74
+
75
+
76
+ desc 'console', 'Starts a xip console'
77
+ long_desc <<-EOS
78
+ `xip console` starts the interactive xip console.
79
+
80
+ $ > xip console --engine=pry
81
+ EOS
82
+ method_option :engine, desc: "Choose a specific console engine: (#{Xip::Commands::Console::ENGINES.keys.join('/')})"
83
+ method_option :help, desc: 'Displays the usage method'
84
+ def console
85
+ if options[:help]
86
+ invoke :help, ['console']
87
+ else
88
+ Xip::Commands::Console.new(options).start
89
+ end
90
+ end
91
+ map 'c' => 'console'
92
+
93
+
94
+ desc 'setup', 'Runs setup tasks for a specified service'
95
+ long_desc <<-EOS
96
+ `xip setup <service>` runs setup tasks for the specified service.
97
+
98
+ $ > xip setup facebook
99
+ EOS
100
+ def setup(service)
101
+ Xip.load_environment
102
+ service_setup_klass = "Xip::Services::#{service.classify}::Setup".constantize
103
+ service_setup_klass.trigger
104
+ end
105
+
106
+
107
+ desc 'sessions:clear', 'Clears all sessions in development'
108
+ long_desc <<-EOS
109
+ `xip sessions:clear` clears all sessions from Redis in development.
110
+
111
+ $ > xip sessions:clear
112
+ EOS
113
+ define_method 'sessions:clear' do
114
+ Xip.load_environment
115
+ $redis.flushdb if Xip.env.development?
116
+ end
117
+
118
+
119
+ desc 'db:create', 'Creates the database from DATABASE_URL or config/database.yml for the current XIP_ENV'
120
+ long_desc <<-EOS
121
+ `xip db:create` Creates the database from DATABASE_URL or config/database.yml for the current XIP_ENV (use db:create:all to create all databases in the config). Without XIP_ENV or when XIP_ENV is development, it defaults to creating the development and test databases.
122
+
123
+ $ > xip db:create
124
+ EOS
125
+ define_method 'db:create' do
126
+ Kernel.exec('bundle exec rake db:create')
127
+ end
128
+
129
+
130
+ desc 'db:create:all', 'Creates all databases from DATABASE_URL or config/database.yml'
131
+ long_desc <<-EOS
132
+ `xip db:create:all` Creates all databases from DATABASE_URL or config/database.yml regardless of the enviornment specified in XIP_ENV
133
+
134
+ $ > xip db:create:all
135
+ EOS
136
+ define_method 'db:create:all' do
137
+ Kernel.exec('bundle exec rake db:create:all')
138
+ end
139
+
140
+
141
+ desc 'db:drop', 'Drops the database from DATABASE_URL or config/database.yml for the current XIP_ENV'
142
+ long_desc <<-EOS
143
+ `xip db:drop` Drops the database from DATABASE_URL or config/database.yml for the current XIP_ENV (use db:drop:all to drop all databases in the config). Without XIP_ENV or when XIP_ENV is development, it defaults to dropping the development and test databases.
144
+
145
+ $ > xip db:drop
146
+ EOS
147
+ define_method 'db:drop' do
148
+ Kernel.exec('bundle exec rake db:drop')
149
+ end
150
+
151
+
152
+ desc 'db:drop:all', 'Drops all databases from DATABASE_URL or config/database.yml'
153
+ long_desc <<-EOS
154
+ `xip db:drop:all` Drops all databases from DATABASE_URL or config/database.yml
155
+
156
+ $ > xip db:drop:all
157
+ EOS
158
+ define_method 'db:drop:all' do
159
+ Kernel.exec('bundle exec rake db:drop:all')
160
+ end
161
+
162
+
163
+ desc 'db:environment:set', 'Set the environment value for the database'
164
+ long_desc <<-EOS
165
+ `xip db:environment:set` Set the environment value for the database
166
+
167
+ $ > xip db:environment:set
168
+ EOS
169
+ define_method 'db:environment:set' do
170
+ Kernel.exec('bundle exec rake db:enviornment:set')
171
+ end
172
+
173
+
174
+ desc 'db:migrate', 'Migrate the database'
175
+ long_desc <<-EOS
176
+ `xip db:migrate` Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog).
177
+
178
+ $ > xip db:migrate
179
+ EOS
180
+ define_method 'db:migrate' do
181
+ Kernel.exec('bundle exec rake db:migrate')
182
+ end
183
+
184
+
185
+ desc 'db:rollback', 'Rolls the schema back to the previous version'
186
+ long_desc <<-EOS
187
+ `xip db:rollback` Rolls the schema back to the previous version (specify steps w/ STEP=n).
188
+
189
+ $ > xip db:rollback
190
+ EOS
191
+ define_method 'db:rollback' do
192
+ Kernel.exec('bundle exec rake db:rollback')
193
+ end
194
+
195
+
196
+ desc 'db:schema:load', 'Loads a schema.rb file into the database'
197
+ long_desc <<-EOS
198
+ `xip db:schema:load` Loads a schema.rb file into the database
199
+
200
+ $ > xip db:schema:load
201
+ EOS
202
+ define_method 'db:schema:load' do
203
+ Kernel.exec('bundle exec rake db:schema:load')
204
+ end
205
+
206
+
207
+ desc 'db:schema:dump', 'Creates a db/schema.rb file that is portable against any DB supported by Active Record'
208
+ long_desc <<-EOS
209
+ `xip db:schema:dump` Creates a db/schema.rb file that is portable against any DB supported by Active Record
210
+
211
+ $ > xip db:schema:dump
212
+ EOS
213
+ define_method 'db:schema:dump' do
214
+ Kernel.exec('bundle exec rake db:schema:dump')
215
+ end
216
+
217
+
218
+ desc 'db:seed', 'Seeds the database with data from db/seeds.rb'
219
+ long_desc <<-EOS
220
+ `xip db:seed` Seeds the database with data from db/seeds.rb
221
+
222
+ $ > xip db:seed
223
+ EOS
224
+ define_method 'db:seed' do
225
+ Kernel.exec('bundle exec rake db:seed')
226
+ end
227
+
228
+
229
+ desc 'db:version', 'Retrieves the current schema version number'
230
+ long_desc <<-EOS
231
+ `xip db:version` Retrieves the current schema version number
232
+
233
+ $ > xip db:version
234
+ EOS
235
+ define_method 'db:version' do
236
+ Kernel.exec('bundle exec rake db:version')
237
+ end
238
+
239
+
240
+ desc 'db:setup', 'Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)'
241
+ long_desc <<-EOS
242
+ `xip db:setup` Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)
243
+
244
+ $ > xip db:setup
245
+ EOS
246
+ define_method 'db:setup' do
247
+ Kernel.exec('bundle exec rake db:setup')
248
+ end
249
+
250
+
251
+ desc 'db:structure:dump', 'Dumps the database structure to db/structure.sql. Specify another file with SCHEMA=db/my_structure.sql'
252
+ long_desc <<-EOS
253
+ `xip db:structure:dump` Dumps the database structure to db/structure.sql. Specify another file with SCHEMA=db/my_structure.sql
254
+
255
+ $ > xip db:structure:dump
256
+ EOS
257
+ define_method 'db:structure:dump' do
258
+ Kernel.exec('bundle exec rake db:structure:dump')
259
+ end
260
+
261
+
262
+ desc 'db:structure:load', 'Recreates the databases from the structure.sql file'
263
+ long_desc <<-EOS
264
+ `xip db:structure:load` Recreates the databases from the structure.sql file
265
+
266
+ $ > xip db:structure:load
267
+ EOS
268
+ define_method 'db:structure:load' do
269
+ Kernel.exec('bundle exec rake db:structure:load')
270
+ end
271
+
272
+ end
273
+ end