Module: GemSuit::Application::Utils::InstanceMethods
- Defined in:
- lib/gem_suit/application/utils.rb
Instance Attribute Summary collapse
-
#root_path ⇒ Object
Returns the value of attribute root_path.
-
#validate_root_path ⇒ Object
Returns the value of attribute validate_root_path.
Instance Method Summary collapse
- #bundle_install ⇒ Object
- #bundle_install? ⇒ Boolean
- #execute(command, text = "") ⇒ Object
- #expand_path(path) ⇒ Object
- #log(action, string_or_force = nil, force = nil) ⇒ Object
- #mysql_password ⇒ Object
- #new_file?(file) ⇒ Boolean
- #original(file) ⇒ Object
- #rails_gem_version ⇒ Object
- #rails_version ⇒ Object
- #shared_path ⇒ Object
- #stashed(file) ⇒ Object
- #templates_path ⇒ Object
- #validate_root_path!(path) ⇒ Object
Instance Attribute Details
#root_path ⇒ Object
Returns the value of attribute root_path.
27 28 29 |
# File 'lib/gem_suit/application/utils.rb', line 27 def root_path @root_path end |
#validate_root_path ⇒ Object
Returns the value of attribute validate_root_path.
27 28 29 |
# File 'lib/gem_suit/application/utils.rb', line 27 def validate_root_path @validate_root_path end |
Instance Method Details
#bundle_install ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gem_suit/application/utils.rb', line 29 def bundle_install return unless bundle_install? if verbose execute "bundle install", "(this can take several minutes...)" else puts "Running `bundle install` (this can take several minutes...)".yellow puts "(in #{root_path})" `cd #{root_path} && bundle install` end end |
#bundle_install? ⇒ Boolean
40 41 42 |
# File 'lib/gem_suit/application/utils.rb', line 40 def bundle_install? `cd #{root_path} && bundle check`.any?{|line| line.include? "`bundle install`"} end |
#execute(command, text = "") ⇒ Object
112 113 114 115 116 |
# File 'lib/gem_suit/application/utils.rb', line 112 def execute(command, text = "") return if command.to_s.gsub(/\s/, "").size == 0 log :executing, "#{command} #{text}" `cd #{root_path} && #{command}` end |
#expand_path(path) ⇒ Object
69 70 71 72 73 |
# File 'lib/gem_suit/application/utils.rb', line 69 def (path) Pathname.new(path).absolute? ? path : File.(path, root_path) end |
#log(action, string_or_force = nil, force = nil) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/gem_suit/application/utils.rb', line 118 def log(action, string_or_force = nil, force = nil) if %w(TrueClass FalseClass).include? string_or_force.class.name string = nil force = string_or_force else string = string_or_force force = false end return unless verbose || force output = [string || action] output.unshift action.to_s.capitalize.ljust(10, " ") unless string.nil? puts output.join(" ") end |
#mysql_password ⇒ Object
107 108 109 110 |
# File 'lib/gem_suit/application/utils.rb', line 107 def mysql_password file = File.("mysql", shared_path) "#{File.new(file).read}".strip if File.exists? file end |
#new_file?(file) ⇒ Boolean
83 84 85 86 87 88 |
# File 'lib/gem_suit/application/utils.rb', line 83 def new_file?(file) return false unless File.exists? (".new_files") root = Pathname.new root_path relative_path = Pathname.new(file).relative_path_from(root).to_s File.readlines((".new_files")).any?{|line| line.strip == relative_path} end |
#original(file) ⇒ Object
75 76 77 |
# File 'lib/gem_suit/application/utils.rb', line 75 def original(file) file.gsub(/\.#{STASHED_EXT}$/, "") end |
#rails_gem_version ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/gem_suit/application/utils.rb', line 94 def rails_gem_version case rails_version when 2 File.readlines(("config/environment.rb")).each do |line| match = line.match /RAILS_GEM_VERSION\s*=\s*["']([\d\.]+)["']/ return $1 if match end when 3 files = [(stashed("Gemfile")), ("Gemfile")] Gemfile.new(*files).gems["rails"][:version] end end |
#rails_version ⇒ Object
90 91 92 |
# File 'lib/gem_suit/application/utils.rb', line 90 def rails_version root_path.match(/\/rails-(\d)\//)[1].to_i end |
#shared_path ⇒ Object
61 62 63 |
# File 'lib/gem_suit/application/utils.rb', line 61 def shared_path File.("../../shared", root_path) end |
#stashed(file) ⇒ Object
79 80 81 |
# File 'lib/gem_suit/application/utils.rb', line 79 def stashed(file) file.match(/\.#{STASHED_EXT}$/) ? file : "#{file}.#{STASHED_EXT}" end |
#templates_path ⇒ Object
65 66 67 |
# File 'lib/gem_suit/application/utils.rb', line 65 def templates_path File.("../../templates", root_path) end |
#validate_root_path!(path) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/gem_suit/application/utils.rb', line 44 def validate_root_path!(path) unless path.match(/rails-\d/) log "Running a #{self.class.name} instance from an invalid path: '#{path}' needs to match ".red + "/rails-\\d/".yellow exit end end |