Module: Reup::Helpers
- Defined in:
- lib/reup/helpers.rb
Constant Summary collapse
- ENV_FILE =
File. "../env.yaml", __FILE__
Instance Method Summary collapse
- #cocaine_run(command, quiet:) ⇒ Object
- #detect_change_to(files, &block) ⇒ Object
- #env ⇒ Object
- #env_file ⇒ Object
-
#install(args = {}) ⇒ Object
API methods.
- #install_command ⇒ Object
- #kernel_run(command) ⇒ Object
-
#last_modified(file) ⇒ Object
Environment helpers.
- #reset_db(args = {}) ⇒ Object
- #reset_db_command ⇒ Object
-
#run(command, quiet: false, print_command: true, replace_process: false) ⇒ Object
Executable helpers.
- #serve ⇒ Object
- #serve_command ⇒ Object
- #watch_files ⇒ Object
Instance Method Details
#cocaine_run(command, quiet:) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/reup/helpers.rb', line 24 def cocaine_run(command, quiet:) cmd = Cocaine::CommandLine.new(command) result = cmd.run puts result unless quiet result end |
#detect_change_to(files, &block) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/reup/helpers.rb', line 35 def detect_change_to(files, &block) before = files.map { |f| last_modified(f) } yield after = files.map { |f| last_modified(f) } before != after # Not equal means there was a change end |
#env ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/reup/helpers.rb', line 77 def env @env ||= ( possible_envs = env_file.keys env = nil possible_envs.each do |possible| indicator_files = Array(env_file[possible]["indicator_files"]) if indicator_files.any? { |f| File.exist? f } env = possible break end end raise "You don't appear to be in a supported environment" unless env env ) end |
#env_file ⇒ Object
50 51 52 |
# File 'lib/reup/helpers.rb', line 50 def env_file @env_file ||= YAML.load_file ENV_FILE end |
#install(args = {}) ⇒ Object
API methods
97 98 99 |
# File 'lib/reup/helpers.rb', line 97 def install(args = {}) run install_command, args end |
#install_command ⇒ Object
58 59 60 |
# File 'lib/reup/helpers.rb', line 58 def install_command @install_command ||= env_file[env]["install"]["command"] end |
#kernel_run(command) ⇒ Object
31 32 33 |
# File 'lib/reup/helpers.rb', line 31 def kernel_run(command) Kernel.exec command end |
#last_modified(file) ⇒ Object
Environment helpers
46 47 48 |
# File 'lib/reup/helpers.rb', line 46 def last_modified(file) File.mtime file end |
#reset_db(args = {}) ⇒ Object
101 102 103 |
# File 'lib/reup/helpers.rb', line 101 def reset_db(args = {}) run reset_db_command, args end |
#reset_db_command ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/reup/helpers.rb', line 66 def reset_db_command @reset_db_command ||= ( db_section = env_file[env]["db"] if db_section db_section["reset_command"] else nil end ) end |
#run(command, quiet: false, print_command: true, replace_process: false) ⇒ Object
Executable helpers
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/reup/helpers.rb', line 12 def run(command, quiet: false, print_command: true, replace_process: false) return unless command puts command if print_command command += " &>/dev/null" if quiet if replace_process kernel_run command else cocaine_run command, quiet: quiet end end |
#serve ⇒ Object
105 106 107 |
# File 'lib/reup/helpers.rb', line 105 def serve run(serve_command, replace_process: true) end |
#serve_command ⇒ Object
62 63 64 |
# File 'lib/reup/helpers.rb', line 62 def serve_command @serve_command ||= env_file[env]["serve"]["command"] end |
#watch_files ⇒ Object
54 55 56 |
# File 'lib/reup/helpers.rb', line 54 def watch_files @watch_files ||= Array(env_file[env]["install"]["only_if_changed"]) end |