pry-session 0.0.1 → 0.0.3

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: f5d82a094e75964f402bc6c5addcb5795577da58
4
- data.tar.gz: 1f204cfdea718763d50e1bdba69594af60abc272
3
+ metadata.gz: 0c115f7b2a6b699b497efd1890dc3fd4c8bcba64
4
+ data.tar.gz: 14c279c74c0a44ae4dfb495f7a5d25d54dc1edce
5
5
  SHA512:
6
- metadata.gz: 2f191bac1ef2cc903ecc1ed4093fe336ff480b89b10427d386c55bbcc3447a0543407773e9bb687a6863a29ad45ceb27920fac8c8042af06247e96425d86f7d7
7
- data.tar.gz: f2022e6c3dcdc0c880b1dba29174a59cb328fdab8ade3ae981fed3bd01d926dce118f808f814f0433152e38e45083645f0a4e36fe61ea02f9a5717db71ceac73
6
+ metadata.gz: b2aced1f7e63e5ffc22979ad018a8c7c97c241beca3db66a087a7631d3b993902b5554b510f14ccf4c2890f0ea63f90b25fce34f220143755ea7fb22a1f233a5
7
+ data.tar.gz: f2b8ecc228e29b60310fb70c9253630bc14d99522c7cb29cf1342d90cca6ea2b083754d7d30a602b3471a20bd15dd02b12237996e978dc3a9168d12a6d5cc9e2
data/README.md CHANGED
@@ -1,16 +1,70 @@
1
- # Pry::Session
1
+ # Pry-Session
2
+
3
+ (Save and load) http://showterm.io/b8d9f8e6ec11b76f6aea0
2
4
 
3
5
  Save a session:
4
- ```ruby
5
- save-session testing
6
+ ```
7
+ [2] pry(main)> a = 1
8
+ => 1
9
+ [3] pry(main)> Person = Struct.new(:name, :age)
10
+ => Person
11
+ [4] pry(main)> brandon = Person.new 'brandon', 23
12
+ => #<struct Person name="brandon", age=23>
13
+ [5] pry(main)> save-session person
14
+ [6] pry(main)> exit
15
+ ```
16
+
17
+ Reload a session in a new Pry session:
18
+ ```
19
+ [1] pry(main)> brandon
20
+ NameError: undefined local variable or method `brandon' for main:Object
21
+ from (pry):1:in `__pry__'
22
+ [2] pry(main)> load-session person
23
+ [4] pry(main)> a = 1
24
+
25
+ [5] pry(main)> Person = Struct.new(:name, :age)
26
+
27
+ [6] pry(main)> brandon = Person.new 'brandon', 23
28
+
29
+ => #<struct Person name="brandon", age=23>
30
+ [7] pry(main)> brandon
31
+ => #<struct Person name="brandon", age=23>
32
+ [8] pry(main)> # MAGIC!
33
+ [9] pry(main)> exit
34
+
6
35
  ```
7
36
 
8
- Reload a session:
9
- ```ruby
10
- load-session testing
37
+ List your sessions: http://showterm.io/9b843c6f8bfd8057f0d5e
11
38
  ```
39
+ [1] pry(main)> list-sessions
40
+ test 6 bytes 2014-06-11 01:19:43 -0500
41
+ testing 33 bytes 2014-06-11 01:20:45 -0500
42
+ person 102 bytes 2014-06-11 01:25:05 -0500
43
+ [2] pry(main)> list-sessions test
44
+ test 6 bytes 2014-06-11 01:19:43 -0500
45
+ [3] pry(main)> list-sessions -g te
46
+ test 6 bytes 2014-06-11 01:19:43 -0500
47
+ testing 33 bytes 2014-06-11 01:20:45 -0500
48
+ [5] pry(main)> list-sessions -g te -s name:desc
49
+ testing 33 bytes 2014-06-11 01:20:45 -0500
50
+ test 6 bytes 2014-06-11 01:19:43 -0500
51
+ [6] pry(main)> list-sessions -g te -s size:desc
52
+ testing 33 bytes 2014-06-11 01:20:45 -0500
53
+ test 6 bytes 2014-06-11 01:19:43 -0500
54
+ [7] pry(main)> list-sessions -g te -s date:desc
55
+ test 6 bytes 2014-06-11 01:19:43 -0500
56
+ testing 33 bytes 2014-06-11 01:20:45 -0500
57
+ ```
58
+
59
+ Edit a session: http://showterm.io/a6ef896322bd8fab71a85
60
+ ```
61
+ [1] pry(main)> edit-session test
62
+ ```
63
+
64
+ ## To Do
12
65
 
13
- Simple as that!
66
+ * Add output silencers by default on session loads
67
+ * Add a new-session option to reset the current session history counters
14
68
 
15
69
  ## Installation
16
70
 
@@ -1,9 +1,28 @@
1
1
  require "pry-session/version"
2
2
  require 'pry'
3
3
 
4
+ # Makes for some cleaner code
5
+ require 'pipeable'
6
+ class Object; include Pipeable end
7
+
4
8
  module PrySession
5
9
  SESSION_DIR = "#{Dir.home}/.pry-sessions"
6
10
 
11
+ class FileMeta
12
+ attr_accessor :name, :path, :size, :ctime
13
+
14
+ def initialize(args={})
15
+ @name = args[:name]
16
+ @path = args[:path]
17
+ @size = args[:size]
18
+ @ctime = args[:ctime]
19
+ end
20
+
21
+ def to_s
22
+ "%-15s %10s bytes %-25s" % [name, size, ctime]
23
+ end
24
+ end
25
+
7
26
  Commands = Pry::CommandSet.new do
8
27
  # Have to force a session refresh on this, talk to core team later.
9
28
  # create_command 'new-session', 'Starts a new session' do
@@ -25,7 +44,9 @@ module PrySession
25
44
  Saves the current session.
26
45
  BANNER
27
46
 
28
- def options(opts) end
47
+ def options(opts)
48
+ opts.on :c, :commands, "Includes pry commands"
49
+ end
29
50
 
30
51
  def process
31
52
  session = Pry.history.to_a.last(Pry.history.session_line_count)
@@ -36,13 +57,19 @@ module PrySession
36
57
  end
37
58
 
38
59
  create_command 'load-session', 'Starts a new session' do
60
+ # opts for later: [-sio] (name)
39
61
  banner <<-BANNER
40
62
  Usage: load-session (name)
41
63
 
42
64
  Loads a session.
43
65
  BANNER
44
66
 
45
- def options(opts) end
67
+ def options(opts)
68
+ # TODO
69
+ # opts.on :s, :silent, "Silences both input and output"
70
+ # opts.on :i, 'show-input', "Shows only input"
71
+ # opts.on :o, 'show-output', "Shows only output"
72
+ end
46
73
 
47
74
  def process
48
75
  raise 'No sessions to load!' unless Dir.exists?(SESSION_DIR)
@@ -50,6 +77,79 @@ module PrySession
50
77
  _pry_.input = File.open("#{SESSION_DIR}/#{args.first}", 'r')
51
78
  end
52
79
  end
80
+
81
+ create_command 'edit-session', 'Edits an existing session' do
82
+ banner <<-BANNER
83
+ Usage: edit-session (name)
84
+
85
+ Edits a session.
86
+ BANNER
87
+
88
+ def options(opts) end
89
+
90
+ def process
91
+ raise 'No sessions to load!' unless Dir.exists?(SESSION_DIR)
92
+
93
+ # Yes, cheating
94
+ _pry_.input = StringIO.new("edit #{SESSION_DIR}/#{args.first}")
95
+ end
96
+ end
97
+
98
+ create_command 'list-sessions', 'Lists all existing sessions' do
99
+ banner <<-BANNER
100
+ Usage: list-sessions (name)
101
+
102
+ Lists sessions.
103
+ BANNER
104
+
105
+ def options(opts)
106
+ opts.on :s, :sort, "Sorts sessions by [name|ctime|size]\nex: --sort name:[asc|desc]",
107
+ argument: :required, as: Array, delimiter: ':'
108
+
109
+ opts.on :g, :grep, "Greps for sessions by name", argument: :required, as: Regexp
110
+ end
111
+
112
+ def process
113
+ raise 'No sessions to load!' unless Dir.exists?(SESSION_DIR)
114
+ raise 'Cannot filter and grep!' if opts[:g] && opts[:f]
115
+
116
+ # Mapper for transforming file names into a meta info container
117
+ file_mapper = -> f {
118
+ "#{SESSION_DIR}/#{f}".pipe { |path|
119
+ FileMeta.new name: f, path: path, size: File.size(path), ctime: File.ctime(path)
120
+ }
121
+ }
122
+
123
+ # Selecter for finding by name or regex
124
+ selecter = (opts[:g] || args.first).pipe { |query|
125
+ if query
126
+ query.is_a?(Regexp) ?
127
+ -> s { query.match s.name } :
128
+ -> s { s.name == query }
129
+ else
130
+ -> s { s }
131
+ end
132
+ }
133
+
134
+ # Sorter to arrange results
135
+ sorter = if opts[:s] && %w(name size ctime).include?(opts[:s].first)
136
+ opts[:s].first.pipe { |field|
137
+ opts[:s][1] == 'asc' ?
138
+ -> a,b { a.send(field) <=> b.send(field) } :
139
+ -> a,b { b.send(field) <=> a.send(field) }
140
+ }
141
+ else
142
+ -> a,b { a.ctime <=> b.ctime }
143
+ end
144
+
145
+ Dir.entries(SESSION_DIR)
146
+ .reject { |f| /^..?$/.match f } # Get rid of current and parent dir
147
+ .map(&file_mapper) # Map filenames to metainformation
148
+ .select(&selecter) # Select matches
149
+ .sort(&sorter) # Sort those results
150
+ .each { |f| output.puts f } # Output them
151
+ end
152
+ end
53
153
  end
54
154
  end
55
155
 
@@ -1,3 +1,3 @@
1
1
  module PrySession
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -21,5 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
23
 
24
- spec.add_runtime_dependency "pry" #, '0.9.12.6'
24
+ spec.add_runtime_dependency "pry"
25
+ spec.add_runtime_dependency "pipeable"
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-session
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Weaver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-11 00:00:00.000000000 Z
11
+ date: 2014-06-13 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: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pipeable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Save and load sessions in Pry
56
70
  email:
57
71
  - keystonelemur@gmail.com