mudbug 0.7.0.1 → 0.7.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/MANIFEST.txt +0 -1
  2. data/README.md +9 -10
  3. data/VERSION +1 -1
  4. data/bin/mb +34 -31
  5. data/mudbug.gemspec +6 -5
  6. metadata +18 -3
  7. data/lib/mb_config.rb +0 -60
data/MANIFEST.txt CHANGED
@@ -5,7 +5,6 @@ README.md
5
5
  LICENSE.txt
6
6
  rakefile.rb
7
7
  lib/mudbug.rb
8
- lib/mb_config.rb
9
8
  test/mudbug.rb
10
9
  examples/accepts_and_methods.rb
11
10
  bin/mb
data/README.md CHANGED
@@ -14,13 +14,13 @@ Features
14
14
  Installation
15
15
  ------------
16
16
  Install the gem:
17
-
18
- $ gem install mudbug
19
-
20
- Or, if using bundler, add to your Gemfile:
21
-
22
- gem 'mudbug', '~> 0.6'
23
-
17
+ ```
18
+ $ gem install mudbug # sudo as necessary
19
+ ```
20
+ Or, if using [Bundler](http://bundler.io/), add to your Gemfile:
21
+ ```ruby
22
+ gem 'mudbug', '~> 0.6'
23
+ ```
24
24
  Quick Start
25
25
  -----------
26
26
  Initialize it with a host:
@@ -89,7 +89,7 @@ resp = Mudbug.new('google.com').resource('/').get
89
89
  # etc.
90
90
  ```
91
91
 
92
- Here is the heart of Mudbug's [response processing](https://github.com/rickhull/mudbug/blob/master/lib/mudbug.rb#L45):
92
+ Here is the heart of Mudbug's [response processing](https://github.com/rickhull/mudbug/blob/master/lib/mudbug.rb#L51):
93
93
 
94
94
  ```ruby
95
95
  # this structure declares what we support in the request Accept: header
@@ -116,8 +116,7 @@ Careful with that axe, Eugene.
116
116
 
117
117
  Examples
118
118
  --------
119
- * accepts_and_methods [sample script](https://github.com/rickhull/mudbug/blob/master/examples/accepts_and_methods.rb)
120
- * accepts_and_methods [sample output](https://github.com/rickhull/mudbug/blob/master/examples/accepts_and_methods.txt)
119
+ * [accepts_and_methods](https://github.com/rickhull/mudbug/blob/master/examples/accepts_and_methods.rb) [(sample output)](https://github.com/rickhull/mudbug/blob/master/examples/accepts_and_methods.txt)
121
120
 
122
121
  Funny, that
123
122
  -----------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0.1
1
+ 0.7.1.1
data/bin/mb CHANGED
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'mb_config'
3
+ require 'dotcfg'
4
+ require 'mudbug'
5
+
6
+ CONFIG = DotCfg.new '~/.mudbug', :json
4
7
 
5
8
  def usage(msg = nil)
6
- puts "ERROR: #{msg}" if msg
9
+ print "ERROR: #{msg}\n\n" if msg
7
10
  puts <<EOF
8
11
  USAGE:
9
12
  mb [get|delete] [PATH] - GET or DELETE PATH
@@ -20,7 +23,7 @@ USAGE:
20
23
  * `accept` is optional; valid values include json, html, text
21
24
  EOF
22
25
  puts
23
- puts "CONFIG: #{MbConfig.dump}"
26
+ puts "CONFIG: #{CONFIG.pretty}"
24
27
 
25
28
  exit 1
26
29
  end
@@ -31,7 +34,7 @@ def conclude(msg)
31
34
  end
32
35
 
33
36
  #
34
- # Config section: handle commands that manipulate MbConfig
37
+ # Config section: handle commands that manipulate CONFIG
35
38
  # Should exit in all cases with conclude()
36
39
  #
37
40
 
@@ -47,20 +50,20 @@ if cfg_cmd
47
50
  val = ARGV.shift
48
51
  if val and !val.empty?
49
52
  if val.downcase == 'nil'
50
- MbConfig.delete cfg_cmd
51
- MbConfig.save
53
+ CONFIG.delete cfg_cmd
54
+ CONFIG.save
52
55
  conclude "removed config for #{cfg_cmd}"
53
56
  else
54
- MbConfig[cfg_cmd] = val
55
- MbConfig.save
57
+ CONFIG[cfg_cmd] = val
58
+ CONFIG.save
56
59
  end
57
60
  else
58
- val = MbConfig[cfg_cmd] or conclude "no #{cfg_cmd} is set"
61
+ val = CONFIG[cfg_cmd] or conclude "no #{cfg_cmd} is set"
59
62
  end
60
63
  conclude "Using #{cfg_cmd}: #{val}"
61
64
 
62
65
  when 'reset'
63
- MbConfig.reset
66
+ CONFIG.reset
64
67
  conclude "config was reset"
65
68
 
66
69
  when 'payload'
@@ -69,17 +72,17 @@ if cfg_cmd
69
72
  if val and !val.empty?
70
73
  case val.downcase
71
74
  when '-'
72
- MbConfig['payload'] = JSON.parse $stdin.read
73
- MbConfig.save
75
+ CONFIG['payload'] = JSON.parse $stdin.read
76
+ CONFIG.save
74
77
  when 'nil'
75
- MbConfig.delete 'payload'
76
- MbConfig.save
78
+ CONFIG.delete 'payload'
79
+ CONFIG.save
77
80
  conclude "removed config for payload"
78
81
  end
79
82
  else
80
- MbConfig['payload'] or conclude "no payload is set"
83
+ CONFIG['payload'] or conclude "no payload is set"
81
84
  end
82
- conclude "Using payload:\n#{JSON.pretty_generate MbConfig['payload']}"
85
+ conclude "Using payload:\n#{JSON.pretty_generate CONFIG['payload']}"
83
86
 
84
87
  when 'accept'
85
88
  ARGV.shift # confirmed cfg_cmd, go ahead and shift
@@ -90,8 +93,8 @@ if cfg_cmd
90
93
 
91
94
  case accepts.length
92
95
  when 0
93
- if MbConfig['accept']
94
- conclude "Using accept: #{MbConfig['accept'].join(' ')}"
96
+ if CONFIG['accept']
97
+ conclude "Using accept: #{CONFIG['accept'].join(' ')}"
95
98
  else
96
99
  conclude "no accept is set"
97
100
  end
@@ -101,26 +104,26 @@ if cfg_cmd
101
104
  else
102
105
  accepts.map! { |s| s.gsub %r{[ ,:]+}, '' }
103
106
  end
104
- MbConfig['accept'] = accepts
105
- MbConfig.save
106
- conclude "using accept: #{MbConfig['accept']}"
107
+ CONFIG['accept'] = accepts
108
+ CONFIG.save
109
+ conclude "using accept: #{CONFIG['accept']}"
107
110
 
108
111
  when 'config'
109
- conclude MbConfig.dump
112
+ conclude CONFIG.pretty
110
113
  end
111
114
  end
112
115
 
113
116
  #
114
- # OK, we're not manipulating MbConfig
115
- # Create Mudbug, determine method and path - from MbConfig and cmd line args
117
+ # OK, we're not manipulating CONFIG
118
+ # Create Mudbug, determine method and path - from CONFIG and cmd line args
116
119
  #
117
120
 
118
- # set the host, always from MbConfig
121
+ # set the host, always from CONFIG
119
122
  #
120
- usage "no host is set" unless MbConfig['host']
121
- mb = Mudbug.new MbConfig['host']
123
+ usage "no host is set" unless CONFIG['host']
124
+ mb = Mudbug.new CONFIG['host']
122
125
 
123
- mb.accept MbConfig['accept'].map(&:to_sym) if MbConfig['accept']
126
+ mb.accept CONFIG['accept'].map(&:to_sym) if CONFIG['accept']
124
127
 
125
128
  # set the method, possibly from CLI args
126
129
  #
@@ -128,7 +131,7 @@ case ARGV.first
128
131
  when 'get', 'post', 'put', 'delete'# , 'patch' # Soon(tm)
129
132
  method = ARGV.shift
130
133
  else
131
- method = MbConfig['method'] or usage "no method provided"
134
+ method = CONFIG['method'] or usage "no method provided"
132
135
  end
133
136
 
134
137
  # set the path, possibly from CLI args
@@ -137,7 +140,7 @@ case ARGV.first
137
140
  when %r{^\/} # starts with a slash
138
141
  path = ARGV.shift
139
142
  else
140
- path = MbConfig['path'] or usage "no path provided"
143
+ path = CONFIG['path'] or usage "no path provided"
141
144
  end
142
145
 
143
146
  # determine method
@@ -151,7 +154,7 @@ when 'post', 'put', 'patch'
151
154
  # get payload
152
155
  case ARGV.first
153
156
  when nil
154
- payload = MbConfig['payload'] or usage "no payload provided"
157
+ payload = CONFIG['payload'] or usage "no payload provided"
155
158
  when '-'
156
159
  begin
157
160
  payload = JSON.parse $stdin.read
data/mudbug.gemspec CHANGED
@@ -9,11 +9,12 @@ Gem::Specification.new do |s|
9
9
 
10
10
  s.executables << 'mb'
11
11
 
12
- s.add_runtime_dependency "rest-client", ["~> 1"]
13
- s.add_runtime_dependency "json", ["~> 1"]
14
- s.add_runtime_dependency "lager", [">= 0.2"]
15
- s.add_development_dependency "minitest", [">= 0"]
16
- s.add_development_dependency "buildar", ["~> 1.4"]
12
+ s.add_runtime_dependency "rest-client", "~> 1"
13
+ s.add_runtime_dependency "json", "~> 1"
14
+ s.add_runtime_dependency "lager", ">= 0.2"
15
+ s.add_runtime_dependency "dotcfg", "~> 0.2"
16
+ s.add_development_dependency "minitest", ">= 0"
17
+ s.add_development_dependency "buildar", "~> 1.4"
17
18
 
18
19
  # dynamic setup
19
20
  this_dir = File.expand_path('..', __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mudbug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.1
4
+ version: 0.7.1.1
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: 2013-07-19 00:00:00.000000000 Z
12
+ date: 2013-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.2'
62
+ - !ruby/object:Gem::Dependency
63
+ name: dotcfg
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '0.2'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.2'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: minitest
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -106,7 +122,6 @@ files:
106
122
  - LICENSE.txt
107
123
  - rakefile.rb
108
124
  - lib/mudbug.rb
109
- - lib/mb_config.rb
110
125
  - test/mudbug.rb
111
126
  - examples/accepts_and_methods.rb
112
127
  - bin/mb
data/lib/mb_config.rb DELETED
@@ -1,60 +0,0 @@
1
- require 'mudbug'
2
-
3
- module MbConfig
4
- FILE = File.expand_path '~/.mudbug'
5
- CFG = {}
6
-
7
- def self.[] key
8
- CFG[key]
9
- end
10
-
11
- def self.[]= key, value
12
- CFG[key] = value
13
- end
14
-
15
- def self.delete key
16
- CFG.delete key
17
- end
18
-
19
- # write CFG to FILE
20
- #
21
- def self.save
22
- File.open(FILE, 'w') { |f| f.write CFG.to_json }
23
- end
24
-
25
- # call reset as necessary
26
- #
27
- def self.load
28
- reset unless File.exists?(FILE)
29
- rescues = 0
30
- begin
31
- File.open(FILE, 'r') { |f|
32
- CFG.merge! JSON.parse f.read
33
- }
34
- rescue JSON::ParserError => e
35
- rescues += 1
36
- puts "#{e} (#{e.class})"
37
- if rescues < 2
38
- puts "Resetting #{FILE}"
39
- reset
40
- retry
41
- end
42
- Mudbug.lager.fatal { "MbConfig.load failed!" }
43
- raise e
44
- end
45
- end
46
-
47
- # write an empty hash/object
48
- #
49
- def self.reset
50
- File.open(FILE, 'w') { |f| f.write '{}' }
51
- end
52
-
53
- # dump the current CFG (may differ from FILE contents!)
54
- #
55
- def self.dump
56
- JSON.pretty_generate CFG
57
- end
58
- end
59
-
60
- MbConfig.load