puman 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 372d5d603fe45e6cacc8de0b833e488d3e390c55
4
- data.tar.gz: 4997b7fab1986fa223e8cf9d433e1ffbfac34799
3
+ metadata.gz: 971cb6d76dc593c0e5c2ee86670a340863c632b7
4
+ data.tar.gz: cc9256b18f1dd845290b7d03564fa3b4fef2f6aa
5
5
  SHA512:
6
- metadata.gz: b461545bcb64f83571964527bce78e0c6c67659ec1be5138ee4f330d0456961ecbd1ccb6944613558c0e4d594c251d4a51bf98913f57e6144e8383d37490361d
7
- data.tar.gz: 9b18c34c21095ec575a9e29efa86377289f93cf4b74e8efdc59ff7ac85e964ca64513ac6ff613200e7ad85ea3720c70788d59a5d65942e052e34fceaac481dd4
6
+ metadata.gz: 91a82d8ff43aad290b333a1bb420277618e852d146b09f495cbd5c1c83aa961e244536934876c4815b84d484e5bc386c0da0064f040cae4e7eab65cc5ee0503c
7
+ data.tar.gz: 481011e38f64100d605b665edf34209b8fdb784f6a95e3f0f83472c18fc04caf450be0805af15336ac0cab42255e3027e9cde0dd291503839f82db1db762ca7f
data/lib/puman.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require "puman/version"
2
+ require "puman/app"
2
3
  require "puman/cli"
data/lib/puman/app.rb ADDED
@@ -0,0 +1,80 @@
1
+ module Puman
2
+ PUMA_DEV_DIR = File.join(Dir.home, '.puma-dev')
3
+
4
+ class App
5
+ attr_accessor :name, :host_port
6
+
7
+ def initialize(name, host_port)
8
+ @name = name
9
+ @host_port = host_port
10
+ end
11
+ end
12
+
13
+ class AppList
14
+ attr_accessor :symlink_apps, :proxy_apps
15
+
16
+ def initialize
17
+ @symlink_apps = []
18
+ @proxy_apps = []
19
+ Dir.chdir PUMA_DEV_DIR do
20
+ Dir.glob('*').each do |file|
21
+ if File.symlink?(file)
22
+ @symlink_apps.push App.new(file, nil)
23
+ else
24
+ host_port = File.read(file)
25
+ @proxy_apps.push App.new(file, host_port)
26
+ end
27
+ end
28
+ end
29
+ @proxy_max_length = @proxy_apps.map {|app| app.host_port.strip.size}.max
30
+ end
31
+
32
+ def list
33
+ string = []
34
+ string << "-- symlink apps --"
35
+ @symlink_apps.sort_by(&:name).each do |app|
36
+ string << app.name
37
+ end
38
+
39
+ string << ''
40
+ string << "-- proxy apps --"
41
+ @proxy_apps.sort_by(&:host_port).each do |app|
42
+ string << "#{app.host_port.strip.rjust(@proxy_max_length)} => #{app.name}"
43
+ end
44
+ string.join("\n")
45
+ end
46
+
47
+ def server_command
48
+ name = File.basename(git_dir_or_current_dir)
49
+ apps = @proxy_apps.select{|app| app.name == name}
50
+ if apps.size != 1
51
+ puts 'no or multiple apps are defind.'
52
+ else
53
+ app = apps.first
54
+ "bundle exec rails server -p #{app.host_port}" if app.host_port.match /^\d+$/
55
+ end
56
+ end
57
+
58
+ def include?(name)
59
+ (@symlink_apps + @proxy_apps).map(&:name).include?(name)
60
+ end
61
+
62
+ private
63
+
64
+ def root_directory?(path)
65
+ File.directory?(path) && File.expand_path(path) == File.expand_path(File.join(path, '..'))
66
+ end
67
+
68
+ def git_dir_or_current_dir
69
+ current_path = Dir.pwd
70
+ until root_directory?(current_path)
71
+ if File.exist?(File.join(current_path, '.git'))
72
+ return current_path
73
+ else
74
+ current_path = File.dirname(current_path)
75
+ end
76
+ end
77
+ Dir.pwd
78
+ end
79
+ end
80
+ end
data/lib/puman/cli.rb CHANGED
@@ -1,40 +1,14 @@
1
1
  require 'thor'
2
+ require_relative 'app'
3
+ require 'pry'
2
4
 
3
5
  module Puman
4
- App = Struct.new(:name, :host_port)
5
-
6
6
  class CLI < Thor
7
7
  default_command :server
8
8
 
9
9
  def initialize(args, opts, config)
10
10
  super
11
- correct_apps
12
- end
13
-
14
- desc "list", "list all apps linked with puma-dev"
15
- def list
16
- puts "-- symlink apps --"
17
- @symlink_apps.sort_by(&:name).each do |app|
18
- puts app.name
19
- end
20
-
21
- puts
22
- puts "-- proxy apps --"
23
- @proxy_apps.sort_by(&:host_port).each do |app|
24
- puts "#{app.host_port.strip.rjust(@proxy_max_length)} => #{app.name}"
25
- end
26
- end
27
-
28
- desc "server", "run rails server"
29
- def server
30
- name = File.basename(git_dir_or_current_dir)
31
- apps = @proxy_apps.select{|app| app.name == name}
32
- if apps.size != 1
33
- puts 'no or multiple apps are defind.'
34
- else
35
- app = apps.first
36
- exec "bundle exec rails server -p #{app.host_port}" if app.host_port.match /^\d+$/
37
- end
11
+ @app_list = AppList.new
38
12
  end
39
13
 
40
14
  desc 'version', 'version'
@@ -42,45 +16,28 @@ module Puman
42
16
  puts Puman::VERSION
43
17
  end
44
18
 
45
- # TODO
46
- # desc "proxify", "make a text file with new host and port"
47
- # def proxify
48
- # puts 'hello'
49
- # end
50
-
51
- private
52
-
53
- def correct_apps
54
- return if !@proxy_apps.nil? && !@symlink_apps.nil?
55
- @proxy_apps = []
56
- @symlink_apps = []
57
- Dir.chdir File.join(Dir.home, '.puma-dev') do
58
- Dir.glob('*').each do |file|
59
- if File.symlink?(file)
60
- @symlink_apps.push App.new(file, nil)
61
- else
62
- host_port = File.read(file)
63
- @proxy_apps.push App.new(file, host_port)
64
- end
65
- end
66
- end
67
- @proxy_max_length = @proxy_apps.map {|app| app.host_port.strip.size}.max
19
+ desc "list", "list all apps linked with puma-dev"
20
+ def list
21
+ puts @app_list.list
68
22
  end
69
23
 
70
- def root_directory?(path)
71
- File.directory?(path) && File.expand_path(path) == File.expand_path(File.join(path, '..'))
24
+ desc "server", "run rails server"
25
+ def server
26
+ exec @app_list.server_command
72
27
  end
73
28
 
74
- def git_dir_or_current_dir
75
- current_path = Dir.pwd
76
- until root_directory?(current_path)
77
- if File.exist?(File.join(current_path, '.git'))
78
- return current_path
79
- else
80
- current_path = File.dirname(current_path)
81
- end
29
+ desc "symlink DIR_PATH", "create symlink into puma-dev directory."
30
+ def symlink(dir)
31
+ file = File.expand_path(dir)
32
+ return puts 'invalid argument.' unless File.exists?(file)
33
+
34
+ link_name = File.basename(file)
35
+ if @app_list.include?(link_name)
36
+ puts 'already exists.'
37
+ else
38
+ FileUtils::ln_s(File.join(Dir.pwd, link_name), File.join(PUMA_DEV_DIR, link_name))
39
+ puts 'symlink created.'
82
40
  end
83
- Dir.pwd
84
41
  end
85
42
  end
86
43
  end
data/lib/puman/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Puman
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/puman.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.13"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "fakefs"
26
27
  spec.add_development_dependency "pry-byebug"
27
28
  spec.add_dependency "thor"
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pi-chan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-28 00:00:00.000000000 Z
11
+ date: 2017-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakefs
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: pry-byebug
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -99,6 +113,7 @@ files:
99
113
  - bin/setup
100
114
  - exe/puman
101
115
  - lib/puman.rb
116
+ - lib/puman/app.rb
102
117
  - lib/puman/cli.rb
103
118
  - lib/puman/version.rb
104
119
  - puman.gemspec