grifter 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "grifter"
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robert Schultheis"]
12
- s.date = "2013-05-09"
12
+ s.date = "2013-05-14"
13
13
  s.description = "convention based approach to interfacing with an HTTP JSON API."
14
14
  s.email = "rob@knewton.com"
15
15
  s.executables = ["grift"]
@@ -49,12 +49,11 @@ class Grifter
49
49
 
50
50
  def load_grifter_file filename
51
51
  Log.debug "Loading extension file '#{filename}'"
52
- anon_mod = Module.new
53
52
  #by evaling in a anonymous module, we protect this class's namespace
54
- load_dir = File.dirname(filename)
55
- $: << load_dir
56
- anon_mod.class_eval(IO.read(filename), filename, 1)
57
- $:.pop
53
+ anon_mod = Module.new
54
+ with_local_load_path File.dirname(filename) do
55
+ anon_mod.class_eval(IO.read(filename), filename, 1)
56
+ end
58
57
  self.extend anon_mod
59
58
  end
60
59
 
@@ -63,7 +62,9 @@ class Grifter
63
62
  raise "No such file '#{filename}'" unless File.exist? filename
64
63
  #by running in a anonymous class, we protect this class's namespace
65
64
  anon_class = BlankSlate.new(self)
66
- anon_class.instance_eval(IO.read(filename), filename, 1)
65
+ with_local_load_path File.dirname(filename) do
66
+ anon_class.instance_eval(IO.read(filename), filename, 1)
67
+ end
67
68
  end
68
69
 
69
70
  #calls all methods that end with grifter_authenticate
@@ -74,4 +75,14 @@ class Grifter
74
75
  self.send(m)
75
76
  end
76
77
  end
78
+
79
+ private
80
+ def with_local_load_path load_path, &block
81
+ $: << load_path
82
+ rtn = yield block
83
+ #delete only the first occurrence, in case something else if changing load path too
84
+ idx = $:.index(load_path)
85
+ $:.delete_at(idx) if idx
86
+ rtn
87
+ end
77
88
  end
@@ -18,7 +18,6 @@ class Grifter
18
18
  rescue Exception
19
19
  obj.to_s
20
20
  end
21
- #module_function :jsonify
22
21
 
23
22
  #attempts to parse json strings into native ruby objects
24
23
  def objectify json_string
@@ -32,7 +31,6 @@ class Grifter
32
31
  Log.debug "Unable to parse non-json object: #{e.to_s}"
33
32
  json_string
34
33
  end
35
- #module_function :objectify
36
34
 
37
35
  end
38
36
  end
@@ -50,4 +50,28 @@ describe Grifter::JsonHelpers do
50
50
  end
51
51
 
52
52
  end
53
+
54
+ describe :objectify do
55
+ it "should turn a json map string into a Hash" do
56
+ hsh = {'str' => 'abc', 'int' => 123, 'dec' => 12.34, 'bool' => true}
57
+ json = JSON.generate hsh
58
+ json_helper.objectify(json).should eql hsh
59
+ end
60
+
61
+ it "turn a json array string into an Array" do
62
+ arr = [1, 2.34, 'three', true]
63
+ json = JSON.generate arr
64
+ json_helper.objectify(json).should =~ arr
65
+ end
66
+
67
+ it "should return a non-string object as itself" do
68
+ obj = 12.34
69
+ json_helper.objectify(obj).should eql obj
70
+ end
71
+
72
+ it "should return a non-json string as itself" do
73
+ str = 'abc;123'
74
+ json_helper.objectify(str).should eql str
75
+ end
76
+ end
53
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grifter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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-05-09 00:00:00.000000000 Z
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  segments:
145
145
  - 0
146
- hash: 95742656892023611
146
+ hash: -4169256621702839743
147
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  none: false
149
149
  requirements: