class Prysless::Store

Public: Pry store allowing to pass and persist data between sessions

Data can be accessed either via hash notation or metheod notation
This is a core functionality of prysless since we want to be able
to share states with other processes (namely: the shell) without
copy/paste.

Examples

Store.new['lol'] = 'test'
Store.new['lol]
    => 'test'
Store.new.lil = 'blah'
Store.new.lil
    => 'blah'

Public Class Methods

new() click to toggle source
# File lib/prysless.rb, line 26
def initialize
    configuration_directory = "#{ENV['HOME']}/.config"
    FileUtils.mkdir_p configuration_directory
    @store = PStore.new("#{configuration_directory}/prysless.pstore")
end

Public Instance Methods

[](key) click to toggle source

Public: reads data from the store

key - the value of the key to retrieve

Examples

[]= 'lol'
    => 'test'

Returns the data to read

# File lib/prysless.rb, line 55
def [] key
    @store.transaction { @store[key] }
end
[]=(key, value) click to toggle source

Public: saves data to the store

key - the name of the key to store value - the value associated with the key

Examples

[]= 'lol', 'test'
    => 'test'

Returns the data that was saved

# File lib/prysless.rb, line 42
def []= key, value
    @store.transaction { @store[key] = value }
end

Private Instance Methods

method_missing(method, *params, &block) click to toggle source

Internal: either writes or read data to/from the store

Examples

method_missing :blah=, ['test'] # writes data
    => 'test'
method_missing :blah # reads data
    => 'test'

Return the data that was saved or read

# File lib/prysless.rb, line 69
def method_missing method, *params, &block
    method = method.to_s
    if method[-1..-1] == '='
        self[method[0..-2]] = params[0]
    else
        self[method]
    end
end