narkisr-snipplr 0.0.5 → 0.0.6

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.
Files changed (2) hide show
  1. data/lib/interface/bash_api.rb +18 -11
  2. metadata +1 -1
@@ -59,17 +59,21 @@ end
59
59
 
60
60
  class BashAPI
61
61
  attr_reader :entry
62
+
63
+ def initialize
64
+ @flagsToActions={
65
+ :d => proc{@entry.delete(@f.d)} , :g=>proc{puts @entry.get_content(@f.g).source},
66
+ :l=>proc{@entry.find_all_entries.each{|e| puts e.eid+' '+e.title}},
67
+ :c=>proc{post_request}
68
+ }
69
+ end
70
+
62
71
  def process
63
72
  @f = ARGV.flags
64
73
  FileUtils.mkdir(ENV['HOME']+'/.snipplr') if !File.exist?(ENV['HOME']+'/.snipplr')
65
74
  key=(@f.key ? @f.key : (IO.read(ENV['HOME']+'/.snipplr/api_key')).chomp!)
66
75
  @entry=SnipplrEntry.new(key)
67
- @entry.find_all_entries.each{|e| puts e.eid+' '+e.title} if @f.l
68
- @meta=eval('{'+@f.meta+'}') if @f.meta
69
- delete_entry if @f.d
70
- post_request if @f.c
71
- print_entry if @f.g
72
- puts 'Use the -h option for help' if !@f.values.find { |val| val}
76
+ process_calls
73
77
  end
74
78
 
75
79
  private
@@ -86,12 +90,15 @@ class BashAPI
86
90
  @entry.post_entry(@meta)
87
91
  end
88
92
 
89
- def print_entry
90
- puts @entry.get_content(@f.g).source
93
+ def proc(&proc)
94
+ proc
91
95
  end
92
-
93
- def delete_entry
94
- @entry.delete(@f.d)
96
+
97
+ def process_calls
98
+ @meta=eval('{'+@f.meta+'}') if @f.meta
99
+ @flagsToActions.each_pair { |flag,act| act.call if @f.send(flag) }
100
+ puts 'Use the -h option for help' if !@f.values.find { |val| val}
95
101
  end
96
102
 
103
+
97
104
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: narkisr-snipplr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronen Narkis