Top Level Namespace
Defined Under Namespace
Constant Summary collapse
- CARRIERWAVE_SANITIZE_REGEXP =
日本語ファイル名のまま保存
/[^[:word:]①-⑨【】「」『』():・&、 \(\)\.\-\+]/
- CarrierwaveStringIO =
後方互換性の維持
Bizside::CarrierwaveStringIO
Class Method Summary collapse
- .add_on_name ⇒ Object
- .ask(prompt, options = {}) ⇒ Object
- .ask_env(env_key, options = {}) ⇒ Object
- .ask_host(prompt, options = {}) ⇒ Object
- .ask_yes(prompt, options = {}) ⇒ Object
- .dev_default_host ⇒ Object
- .gem_dir ⇒ Object
- .interactive? ⇒ Boolean
- .ip_addresses ⇒ Object
- .prefix ⇒ Object
- .rails_env ⇒ Object
- .rails_root ⇒ Object
- .render(template, options = {}) ⇒ Object
- .run(*commands) ⇒ Object
- .yes_confirmed?(yes_value, options = {}) ⇒ Boolean
Class Method Details
.add_on_name ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/bizside/task_helper.rb', line 88 def self.add_on_name ret = ENV['ADD_ON_NAME'] unless ret ret = Bizside.config.add_on_name if Bizside.config.add_on_name? end ret end |
.ask(prompt, options = {}) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/bizside/task_helper.rb', line 115 def self.ask(prompt, = {}) raise 'プロンプトは必須です。' if prompt.to_s.empty? if [:default].to_s.empty? print prompt + ': ' elsif [:password] print prompt + " [FILTERED]: " else print prompt + " [#{[:default]}]: " end answer = '' if answer.empty? and .has_key?(:env_key) answer = ENV[[:env_key].to_s].to_s end if answer.empty? if interactive? if [:password] system("stty -echo") at_exit do system("stty echo") end end answer = STDIN.gets.strip if [:password] system("stty echo") puts end else puts end else if [:password] puts 'FILTERED' else puts answer end end if answer.empty? and .has_key?(:default) answer = [:default].to_s end if answer.empty? and [:required] raise "必須です。処理を中止します。" end if block_given? answer = yield answer end answer end |
.ask_env(env_key, options = {}) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/bizside/task_helper.rb', line 177 def self.ask_env(env_key, = {}) cache_file = 'tmp/cache/env' cache = File.exist?(cache_file) ? YAML.load_file(cache_file) : {} if .fetch(:cache, false) = .merge(default: cache.fetch(env_key, [:default])) end ENV[env_key] ||= ask(env_key, .merge(env_key: env_key)) if .fetch(:cache, false) FileUtils.mkdir_p(File.dirname(cache_file)) cache[env_key] = ENV[env_key] File.write(cache_file, YAML.dump(cache)) else if File.exist?(cache_file) and cache[env_key] cache.delete(env_key) File.write(cache_file, YAML.dump(cache)) end end ENV[env_key] end |
.ask_host(prompt, options = {}) ⇒ Object
215 216 217 218 219 220 221 |
# File 'lib/bizside/task_helper.rb', line 215 def self.ask_host(prompt, = {}) if .has_key?(:default) ask(prompt, ) else ask(prompt, .merge(default: dev_default_host)) end end |
.ask_yes(prompt, options = {}) ⇒ Object
172 173 174 175 |
# File 'lib/bizside/task_helper.rb', line 172 def self.ask_yes(prompt, = {}) answer = ask(prompt, ) yes_confirmed?(answer, :fail_on_error => true) end |
.dev_default_host ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/bizside/task_helper.rb', line 223 def self.dev_default_host ret = nil udp = UDPSocket.new begin # クラスBの先頭アドレス,echoポート 実際にはパケットは送信されない。 udp.connect("128.0.0.0", 7) ret = Socket.unpack_sockaddr_in(udp.getsockname)[1] ensure udp.close end ret end |
.gem_dir ⇒ Object
111 112 113 |
# File 'lib/bizside/task_helper.rb', line 111 def self.gem_dir File.('../../../..', __FILE__) end |
.interactive? ⇒ Boolean
107 108 109 |
# File 'lib/bizside/task_helper.rb', line 107 def self.interactive? yes_confirmed?(ENV['INTERACTIVE'] || 'true') end |
.ip_addresses ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/bizside/task_helper.rb', line 250 def self.ip_addresses unless @_ip_addresses @_ip_addresses = [] `/sbin/ip route`.split("\n").each do |line| elements = line.split.map(&:strip) if index = elements.index('src') @_ip_addresses << elements[index + 1] end end @_ip_addresses end @_ip_addresses end |
.prefix ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/bizside/task_helper.rb', line 96 def self.prefix ret = ENV['PREFIX'] unless ret ret = Bizside.config.prefix if Bizside.config.prefix? end raise 'prefix は / から指定してください。' if ret and not ret.start_with?('/') ret ||= '/' + add_on_name if Bizside.config.add_on_name? ret ||= ask('プリフィックス', :required => true) ret end |
.rails_env ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/bizside/task_helper.rb', line 49 def self.rails_env ret = 'development' # RAILS_ENV が未指定の時は、BIZSIDE_ENV を利用できるか確認する if ENV['RAILS_ENV'].to_s.empty? unless ENV['BIZSIDE_ENV'].to_s.empty? case ENV['BIZSIDE_ENV'] when 'production', 'staging', 'education' ret = ENV['RAILS_ENV'] = 'production' else ret = ENV['RAILS_ENV'] = ENV['BIZSIDE_ENV'] end end end if ENV['RAILS_ENV'].to_s.empty? puts 'RAILS_ENVを選択してください。' puts ' 1 - production' puts '* 2 - development' puts ' 3 - test' puts print '> ' if interactive? selected = STDIN.gets.strip.to_i ret = ['production', 'development', 'test'][selected - 1] if selected > 0 else puts raise "必須です。処理を中止します。" end else ret = ENV['RAILS_ENV'] puts "RAILS_ENV: #{ret}" end ENV['RAILS_ENV'] ||= ret ret end |
.rails_root ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bizside/task_helper.rb', line 7 def self.rails_root if ENV['RAILS_ROOT'].to_s.empty? if interactive? case ENV['RAILS_ENV'] when 'production' ret = "/home/#{ENV['USER']}/rails_apps/#{self.add_on_name}/current" else if defined?(Rails) ret = Rails.root.to_s else ret = `pwd`.strip end end print "RAILS_ROOT [#{ret}]: " answer = STDIN.gets.strip ret = answer unless answer.empty? else case ENV['RAILS_ENV'] when 'test' if defined?(Rails) ret = Rails.root.to_s else ret = `pwd`.strip end end puts "RAILS_ROOT [#{ret}]: " end else ret = ENV['RAILS_ROOT'] puts "RAILS_ROOT [#{ret}]: " end ENV['RAILS_ROOT'] ||= ret if ENV['RAILS_ROOT'].to_s.empty? raise "必須です。処理を中止します。" end ret end |
.render(template, options = {}) ⇒ Object
245 246 247 248 |
# File 'lib/bizside/task_helper.rb', line 245 def self.render(template, = {}) FileUtils.mkdir_p(File.dirname([:to])) File.write([:to], ERB.new(File.read(template), 0, '-').result) end |
.run(*commands) ⇒ Object
238 239 240 241 242 243 |
# File 'lib/bizside/task_helper.rb', line 238 def self.run(*commands) commands.each do |c| puts c fail unless system(c) end end |
.yes_confirmed?(yes_value, options = {}) ⇒ Boolean
202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/bizside/task_helper.rb', line 202 def self.yes_confirmed?(yes_value, = {}) ret = Bizside::Yes.confirmed?(yes_value) if ret.nil? if [:fail_on_error] fail "yes/no または true/false 形式で入力してください。answer=#{yes_value}" else ret = false end end ret end |