prysless 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -6,7 +6,9 @@
6
6
  [![Inline docs](http://inch-ci.org/github/yazgoo/prysless.png?branch=master)](http://inch-ci.org/github/yazgoo/prysless)
7
7
  [![Gem Version](https://badge.fury.io/rb/prysless.svg)](http://badge.fury.io/rb/prysless)
8
8
 
9
- TODO: Write a gem description
9
+ prysless aims to integrate ruby programs in terminal sessions with lowest harm.
10
+
11
+ It is based on pry REPL, hence the name.
10
12
 
11
13
  ## Installation
12
14
 
@@ -22,9 +24,64 @@ Or install it yourself as:
22
24
 
23
25
  $ gem install prysless
24
26
 
25
- ## Usage
27
+ ## Configuring
28
+
29
+ All the configuring is done via environment variables,
30
+ so to me it adds up to editing my bashrc
31
+
32
+ * PRYSLESS\_LIBRARY\_PATH: path to load additional libraries, ":"-separated
33
+ * PRYSLESS\_REQUIRE: variable definitions
34
+ * PRYSLESS\_ALIASES: shell command aliases
35
+
36
+ For example:
37
+
38
+ export PRYSLESS_ALIASES='l=ls:c=cd'
39
+ export PRYSLESS_LIBRARY_PATH="$HOME/dev/ec2l/lib"
40
+ export PRYSLESS_REQUIRE="e=ec2l/Ec2l/Client.new:a=pry/[]"
41
+
42
+ PRYSLESS\_REQUIRE tells prysless what objects to preload and how to name them.
43
+
44
+ So, for example:
45
+
46
+ e=ec2l/Ec2l/Client.new
47
+
48
+ Will load into the variable named e Ec2l::Client.new after requiring 'ec2l'.
49
+
50
+ Because I use the development version of ec2l and not the gem directly,
51
+ I added my ec2l development library directory to PRYSLESS\_LIBRARY\_PATH.
52
+
53
+ Also, I like to add an alias to prysless\_store command:
54
+
55
+ alias p=prysless_store
56
+
57
+ ## Using
58
+
59
+ Just run
60
+
61
+ prysless
62
+
63
+ Once in pry shell, you'll be able to access the variables you defined:
64
+
65
+ ```ruby
66
+ [1] pry(<Prysless::Shell>)> e
67
+ => <Ec2l::Client:0x000000022f5e70
68
+ ...
69
+ [2] pry(<Prysless::Shell>)> cd e
70
+
71
+ [4] pry(<Ec2l::Client>):1> show-doc ins
72
+ ```
73
+
74
+ Lets say you need to share data between your session and an external program:
75
+
76
+ ```ruby
77
+ [8] pry(#<Prysless::Shell>)> s.blah = 'test'
78
+ => "test"
79
+ ```
80
+
81
+ Now on your shell, provided 'p' is an alias to prysless\_store:
26
82
 
27
- TODO: Write usage instructions here
83
+ $ echo I need to $(p blah) some more
84
+ I need to test some more
28
85
 
29
86
  ## Contributing
30
87
 
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require 'prysless'
3
+ store = Prysless::Store.new
4
+ if ARGV.size > 1
5
+ store[ARGV[0]] = ARGV[1]
6
+ else
7
+ puts store[ARGV[0]]
8
+ end
@@ -1,14 +1,84 @@
1
1
  require "prysless/version"
2
2
  require 'pry'
3
+ require 'pstore'
4
+ require 'fileutils'
3
5
  # Public: Utilities to make ruby object accessible via pry
4
6
  #
5
7
  # Examples
6
8
  #
7
9
  # Prysless::Shell.new
8
10
  module Prysless
11
+ # Public: Pry store allowing to pass and persist data between sessions
12
+ # Data can be accessed either via hash notation or metheod notation
13
+ # This is a core functionality of prysless since we want to be able
14
+ # to share states with other processes (namely: the shell) without
15
+ # copy/paste.
16
+ #
17
+ # Examples
18
+ #
19
+ # Store.new['lol'] = 'test'
20
+ # Store.new['lol]
21
+ # => 'test'
22
+ # Store.new.lil = 'blah'
23
+ # Store.new.lil
24
+ # => 'blah'
25
+ class Store
26
+ def initialize
27
+ configuration_directory = "#{ENV['HOME']}/.config"
28
+ FileUtils.mkdir_p configuration_directory
29
+ @store = PStore.new("#{configuration_directory}/prysless.pstore")
30
+ end
31
+ # Public: saves data to the store
32
+ #
33
+ # key - the name of the key to store
34
+ # value - the value associated with the key
35
+ #
36
+ # Examples
37
+ #
38
+ # []= 'lol', 'test'
39
+ # => 'test'
40
+ #
41
+ # Returns the data that was saved
42
+ def []= key, value
43
+ @store.transaction { @store[key] = value }
44
+ end
45
+ # Public: reads data from the store
46
+ #
47
+ # key - the value of the key to retrieve
48
+ #
49
+ # Examples
50
+ #
51
+ # []= 'lol'
52
+ # => 'test'
53
+ #
54
+ # Returns the data to read
55
+ def [] key
56
+ @store.transaction { @store[key] }
57
+ end
58
+ private
59
+ # Internal: either writes or read data to/from the store
60
+ #
61
+ # Examples
62
+ #
63
+ # method_missing :blah=, ['test'] # writes data
64
+ # => 'test'
65
+ # method_missing :blah # reads data
66
+ # => 'test'
67
+ #
68
+ # Return the data that was saved or read
69
+ def method_missing method, *params, &block
70
+ method = method.to_s
71
+ if method[-1..-1] == '='
72
+ self[method[0..-2]] = params[0]
73
+ else
74
+ self[method]
75
+ end
76
+ end
77
+ end
9
78
  # Public: Pry shell allowing to use user defined objects, based on two variables:
10
79
  # * PRYSLESS_LIBRARY_PATH: path to load additional libraries, ":"-separated
11
80
  # * PRYSLESS_REQUIRE: variable definitions
81
+ # * PRYSLESS_ALIASES: shell command aliases
12
82
  #
13
83
  # Examples
14
84
  #
@@ -21,22 +91,25 @@ module Prysless
21
91
  load_objects
22
92
  shell
23
93
  end
24
- private
94
+ private
25
95
  def shell() binding.pry end
26
96
  def var name
27
- value = ENV[name]
97
+ value = ENV["PRYSLESS_#{name}"]
28
98
  value = if value == nil then [] else value.split(":") end
29
99
  value.each { |p| yield p }
30
100
  end
31
101
  def load_objects
32
102
  @a = {}
33
- var('PRYSLESS_LIBRARY_PATH') { |p| $LOAD_PATH << p }
34
- var('PRYSLESS_REQUIRE') do |p|
103
+ @aliases = {}
104
+ var('ALIASES') { |a| k, v = a.split('=', 2); @aliases[k] = v }
105
+ var('LIBRARY_PATH') { |p| $LOAD_PATH << p }
106
+ var('REQUIRE') do |p|
35
107
  name , value = p.split("=", 2)
36
108
  gem, object = value.split("/", 2)
37
109
  require gem
38
110
  @a[name] = eval(object.gsub("/", "::"))
39
111
  end
112
+ @a['s'] = Store.new
40
113
  end
41
114
  # Internal: try and find user defined variable named with the method
42
115
  # if its result is nil, super
@@ -52,10 +125,11 @@ private
52
125
  #
53
126
  # Return the declared variable from PRYSLESS_REQUIRE or calls super
54
127
  def method_missing method, *params, &block
55
- if @a[method.to_s]
56
- @a[method.to_s]
128
+ meth = method.to_s
129
+ if @a[meth] then @a[meth]
57
130
  else
58
- super
131
+ meth = @aliases[meth] if @aliases[meth]
132
+ `#{([meth] + params).join " "}`.split("\n")
59
133
  end
60
134
  end
61
135
  end
@@ -1,3 +1,3 @@
1
1
  module Prysless
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -16,7 +16,17 @@ class PryslessTest < Test::Unit::TestCase
16
16
  rescue Exception => e
17
17
  x = e
18
18
  end
19
- assert_not_nil e
19
+ end
20
+ def test_store
21
+ Dir.mktmpdir do |dir|
22
+ ENV['HOME'] = dir
23
+ s = Prysless::Store.new
24
+ s['lol'] = 'lil'
25
+ assert s['lol'] == 'lil'
26
+ s.test = 'blah'
27
+ assert s.test == 'blah'
28
+ assert s.test == s['test']
29
+ end
20
30
  end
21
31
  end
22
32
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prysless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-20 00:00:00.000000000 Z
12
+ date: 2014-07-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -64,6 +64,7 @@ email:
64
64
  - yazgoo@github.com
65
65
  executables:
66
66
  - prysless
67
+ - prysless_store
67
68
  extensions: []
68
69
  extra_rdoc_files: []
69
70
  files:
@@ -74,6 +75,7 @@ files:
74
75
  - README.md
75
76
  - Rakefile
76
77
  - bin/prysless
78
+ - bin/prysless_store
77
79
  - lib/prysless.rb
78
80
  - lib/prysless/version.rb
79
81
  - prysless.gemspec
@@ -93,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
95
  version: '0'
94
96
  segments:
95
97
  - 0
96
- hash: -4030277097249573203
98
+ hash: -2956483254067792842
97
99
  required_rubygems_version: !ruby/object:Gem::Requirement
98
100
  none: false
99
101
  requirements:
@@ -102,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
104
  version: '0'
103
105
  segments:
104
106
  - 0
105
- hash: -4030277097249573203
107
+ hash: -2956483254067792842
106
108
  requirements: []
107
109
  rubyforge_project:
108
110
  rubygems_version: 1.8.23