fetching 0.5.0 → 0.6.0
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.
- checksums.yaml +7 -0
- data/.rubocop.yml +37 -0
- data/Gemfile +1 -1
- data/fetching.gemspec +3 -3
- data/lib/fetching/fetching_array.rb +1 -1
- data/lib/fetching/fetching_hash.rb +1 -1
- data/lib/fetching/version.rb +1 -1
- data/lib/fetching.rb +24 -15
- data/spec/fetching_array_spec.rb +17 -8
- data/spec/fetching_hash_spec.rb +11 -2
- data/spec/fetching_spec.rb +16 -11
- data/spec/support/vim_formatter.rb +10 -10
- metadata +15 -24
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 17a2d47d0a5f371c2f183a86e4f0251f8b84d522
|
4
|
+
data.tar.gz: 78bd54db29bee8f7a3f86f8e168279e4ee00474e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 04933886fb1e0623087cea84a87da2a2af2c541af9d1a0ada4ad4ae4e4b685c7c0273f156f87483ca5f9cbcf7725a4255b34ef51f6d0d21b31008cd777cca1eb
|
7
|
+
data.tar.gz: 347ff59ef74c2076c0514b943d30c3b7a94f5d27b8e4777df5635629bf9e2809db3a9cc2c3d246e994dc628c3269e6e9cff71457a5697ce5d80b42c002ff7075
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- Gemfile
|
4
|
+
- Rakefile
|
5
|
+
|
6
|
+
Documentation:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Encoding:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
EmptyLinesAroundBody:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
LineLength:
|
16
|
+
Max: 100
|
17
|
+
|
18
|
+
MethodDefParentheses:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
NumericLiterals:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
RegexpLiteral:
|
25
|
+
MaxSlashes: 0
|
26
|
+
Exclude:
|
27
|
+
- Guardfile
|
28
|
+
|
29
|
+
SpecialGlobalVars:
|
30
|
+
Exclude:
|
31
|
+
- fetching.gemspec
|
32
|
+
|
33
|
+
StringLiterals:
|
34
|
+
EnforcedStyle: double_quotes
|
35
|
+
|
36
|
+
TrailingComma:
|
37
|
+
EnforcedStyleForMultiline: comma
|
data/Gemfile
CHANGED
data/fetching.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "fetching/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "fetching"
|
8
8
|
spec.version = Fetching::VERSION
|
9
9
|
spec.authors = ["Michael Gee", "Mark Lorenz"]
|
10
10
|
spec.email = ["mgee@covermymeds.com", "mlorenz@covermymeds.com"]
|
11
|
-
spec.description = %q
|
11
|
+
spec.description = %q(More sass in more structs.)
|
12
12
|
|
13
13
|
spec.summary = <<-HEREDOC
|
14
14
|
This gem is a work in progress. The implementation code is not what's
|
data/lib/fetching/version.rb
CHANGED
data/lib/fetching.rb
CHANGED
@@ -4,7 +4,7 @@ require "fetching/fetching_hash"
|
|
4
4
|
|
5
5
|
module Kernel
|
6
6
|
|
7
|
-
def Fetching(arg)
|
7
|
+
def Fetching(arg) # rubocop:disable MethodName
|
8
8
|
Fetching.from(arg)
|
9
9
|
end
|
10
10
|
|
@@ -12,26 +12,25 @@ end
|
|
12
12
|
|
13
13
|
class Fetching
|
14
14
|
|
15
|
-
WHITELIST = %w
|
16
|
-
|
17
|
-
|
15
|
+
WHITELIST = %w(
|
16
|
+
class object_id == equal?
|
17
|
+
define_singleton_method instance_eval
|
18
|
+
respond_to?
|
19
|
+
instance_variables instance_variable_get
|
20
|
+
)
|
18
21
|
|
19
22
|
all_methods = instance_methods.map(&:to_s).grep(/\A[^_]/)
|
20
23
|
(all_methods - WHITELIST).each(&method(:undef_method))
|
21
24
|
|
22
25
|
def self.from(value)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
FetchingHash.new(value.to_hash)
|
28
|
-
else
|
29
|
-
value
|
30
|
-
end
|
26
|
+
return value.to_fetching if value.respond_to? :to_fetching
|
27
|
+
return FetchingArray.new(value.to_ary) if value.respond_to? :to_ary
|
28
|
+
return FetchingHash.new(value.to_hash) if value.respond_to? :to_hash
|
29
|
+
value
|
31
30
|
end
|
32
31
|
|
33
|
-
def self.from_json json
|
34
|
-
from(JSON.parse json)
|
32
|
+
def self.from_json json
|
33
|
+
from(JSON.parse json)
|
35
34
|
end
|
36
35
|
|
37
36
|
def initialize table
|
@@ -46,12 +45,22 @@ class Fetching
|
|
46
45
|
self.class.hash ^ @table.hash
|
47
46
|
end
|
48
47
|
|
48
|
+
def to_fetching
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
49
52
|
def to_s
|
50
53
|
@table.to_s
|
51
54
|
end
|
52
55
|
|
53
56
|
def inspect
|
54
|
-
"#<#{self.class.name}: @table=#{
|
57
|
+
"#<#{self.class.name}: @table=#{@table}>"
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def respond_to_missing? _method_name, _include_private = false
|
63
|
+
false
|
55
64
|
end
|
56
65
|
|
57
66
|
end
|
data/spec/fetching_array_spec.rb
CHANGED
@@ -2,14 +2,23 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Fetching::FetchingArray do
|
4
4
|
|
5
|
+
specify "a Fetching object as a value" do
|
6
|
+
ary = Fetching([1, 2])
|
7
|
+
hsh = Fetching(one: 1)
|
8
|
+
[ary, hsh].each do |obj|
|
9
|
+
fetching_ary = Fetching [obj]
|
10
|
+
expect(fetching_ary.first).to equal(obj)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
5
14
|
specify "#map" do
|
6
15
|
ary = [1, 2]
|
7
16
|
fetching_ary = Fetching(ary)
|
8
|
-
expect(fetching_ary.map(&:to_s)).to eq(%w
|
17
|
+
expect(fetching_ary.map(&:to_s)).to eq(%w(1 2))
|
9
18
|
end
|
10
19
|
|
11
20
|
specify "Fetching should go deep" do
|
12
|
-
Fetching([{one: 1}]).each do |element|
|
21
|
+
Fetching([{ one: 1 }]).each do |element|
|
13
22
|
expect(element.one).to eq(1)
|
14
23
|
end
|
15
24
|
end
|
@@ -17,7 +26,7 @@ describe Fetching::FetchingArray do
|
|
17
26
|
specify "#first" do
|
18
27
|
ary = []
|
19
28
|
sassy_ary = Fetching(ary)
|
20
|
-
expect{ sassy_ary.first }.to raise_error(IndexError)
|
29
|
+
expect { sassy_ary.first }.to raise_error(IndexError)
|
21
30
|
end
|
22
31
|
|
23
32
|
describe "array methods" do
|
@@ -25,11 +34,11 @@ describe Fetching::FetchingArray do
|
|
25
34
|
let(:fetching) { Fetching(array) }
|
26
35
|
|
27
36
|
describe "#empty?" do
|
28
|
-
it("should be false"){ expect(fetching.empty?).to be_false }
|
37
|
+
it("should be false") { expect(fetching.empty?).to be_false }
|
29
38
|
|
30
39
|
context "when empty" do
|
31
40
|
let(:array) { [] }
|
32
|
-
it("should be true"){ expect(fetching.empty?).to be_true }
|
41
|
+
it("should be true") { expect(fetching.empty?).to be_true }
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
@@ -50,13 +59,13 @@ describe Fetching::FetchingArray do
|
|
50
59
|
end
|
51
60
|
|
52
61
|
specify "#sort" do
|
53
|
-
sorter = ->(x, y){ y <=> x }
|
62
|
+
sorter = ->(x, y) { y <=> x }
|
54
63
|
sorted = Fetching(array.sort(&sorter))
|
55
64
|
expect(fetching.sort(&sorter)).to eq(sorted)
|
56
65
|
end
|
57
66
|
|
58
67
|
specify "#sort_by" do
|
59
|
-
sorter = ->(i){ 1/i
|
68
|
+
sorter = ->(i) { 1.0 / i }
|
60
69
|
sorted = Fetching(array.sort_by(&sorter))
|
61
70
|
expect(fetching.sort_by(&sorter)).to eq(sorted)
|
62
71
|
end
|
@@ -70,7 +79,7 @@ describe Fetching::FetchingArray do
|
|
70
79
|
specify "out of bounds" do
|
71
80
|
at = 5
|
72
81
|
expected_message = "index #{at} outside of array bounds: -3...3"
|
73
|
-
expect{ fetching.values_at(at) }.to raise_error(IndexError, expected_message)
|
82
|
+
expect { fetching.values_at(at) }.to raise_error(IndexError, expected_message)
|
74
83
|
end
|
75
84
|
end
|
76
85
|
|
data/spec/fetching_hash_spec.rb
CHANGED
@@ -2,8 +2,17 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Fetching::FetchingHash do
|
4
4
|
|
5
|
+
specify "a Fetching object as a value" do
|
6
|
+
ary = Fetching([1, 2])
|
7
|
+
hsh = Fetching(one: 1)
|
8
|
+
[ary, hsh].each do |obj|
|
9
|
+
fetching_ary = Fetching key: obj
|
10
|
+
expect(fetching_ary.key).to equal(obj)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
5
14
|
specify "#to_hash" do
|
6
|
-
hash = {one: 1, two: 2}
|
15
|
+
hash = { one: 1, two: 2 }
|
7
16
|
fetching_hash = Fetching(hash)
|
8
17
|
expect(fetching_hash.to_hash).to eq(hash)
|
9
18
|
end
|
@@ -16,7 +25,7 @@ describe Fetching::FetchingHash do
|
|
16
25
|
end
|
17
26
|
|
18
27
|
specify "#to_hash does a deep copy" do
|
19
|
-
hash = {one: 1, two: {three: 3}}
|
28
|
+
hash = { one: 1, two: { three: 3 } }
|
20
29
|
fetching_hash = Fetching(hash)
|
21
30
|
expect(fetching_hash.to_hash).to eq(hash)
|
22
31
|
end
|
data/spec/fetching_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Fetching do
|
4
4
|
|
5
5
|
let(:input) { { one: 1, two: two, ary: ary, object_ary: object_ary } }
|
6
|
-
let(:two) { { "two"=>2 } }
|
6
|
+
let(:two) { { "two" => 2 } }
|
7
7
|
let(:ary) { [1, 2] }
|
8
8
|
let(:object_ary) { [{}, last_object] }
|
9
9
|
let(:last_object) { { three: 3 } }
|
@@ -18,22 +18,20 @@ describe Fetching do
|
|
18
18
|
|
19
19
|
describe "an unknown hash key" do
|
20
20
|
it "raises NoMethodError" do
|
21
|
-
expected_message =
|
21
|
+
expected_message = <<-EOM.gsub(/^ +/, "").strip
|
22
|
+
not_a_key not found
|
23
|
+
you have:
|
24
|
+
{:one=>1, :two=>{\"two\"=>2}, :ary=>[1, 2], :object_ary=>[{}, {:three=>3}]}
|
25
|
+
EOM
|
22
26
|
|
23
|
-
expect{ subject.not_a_key }.to raise_error(NoMethodError, expected_message)
|
27
|
+
expect { subject.not_a_key }.to raise_error(NoMethodError, expected_message)
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
27
31
|
describe "an unknown array index" do
|
28
32
|
it "raises NoMethodError" do
|
29
33
|
expected_message = "index 3 outside of array bounds: -2...2"
|
30
|
-
expect{ subject.ary[ary.size + 1] }.to raise_error(IndexError, expected_message)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "a bad closure" do
|
35
|
-
it "raises the expected error" do
|
36
|
-
expect { Fetching.from_json("{}", :not_a_key) }.to raise_error(NoMethodError)
|
34
|
+
expect { subject.ary[ary.size + 1] }.to raise_error(IndexError, expected_message)
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
@@ -43,8 +41,15 @@ describe Fetching do
|
|
43
41
|
end
|
44
42
|
|
45
43
|
it "has a nice #inspect" do
|
46
|
-
|
44
|
+
table = "{:one=>1, :two=>{\"two\"=>2}, :ary=>[1, 2], :object_ary=>[{}, {:three=>3}]}"
|
45
|
+
nice_inspect = "#<Fetching::FetchingHash: @table=#{table}>"
|
47
46
|
expect(subject.inspect).to eq(nice_inspect)
|
48
47
|
end
|
49
48
|
|
49
|
+
specify ".from_json" do
|
50
|
+
json = '{ "some_key": 1 }'
|
51
|
+
expected = Fetching(JSON.parse(json))
|
52
|
+
expect(described_class.from_json(json)).to eq(expected)
|
53
|
+
end
|
54
|
+
|
50
55
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Adapted from https://github.com/bronson/vim-runtest/blob/master/rspec_formatter.rb.
|
2
|
-
require
|
2
|
+
require "rspec/core/formatters/base_text_formatter"
|
3
3
|
|
4
4
|
class VimFormatter < RSpec::Core::Formatters::BaseTextFormatter
|
5
5
|
|
@@ -9,27 +9,27 @@ class VimFormatter < RSpec::Core::Formatters::BaseTextFormatter
|
|
9
9
|
frame =~ %r{\b(spec/.*_spec\.rb:\d+)(?::|\z)}
|
10
10
|
end
|
11
11
|
message = format_message exception.message
|
12
|
-
path = format_caller(path ||
|
13
|
-
output.puts "#{path}: #{example.example_group.description.strip} "
|
12
|
+
path = format_caller(path || " ")
|
13
|
+
output.puts "#{path}: #{example.example_group.description.strip} " \
|
14
14
|
"#{example.description.strip}: #{message.strip}" if path
|
15
15
|
end
|
16
16
|
|
17
|
-
def example_pending *
|
17
|
+
def example_pending *_args; end
|
18
18
|
|
19
|
-
def dump_failures *
|
19
|
+
def dump_failures *_args; end
|
20
20
|
|
21
|
-
def dump_pending *
|
21
|
+
def dump_pending *_args; end
|
22
22
|
|
23
|
-
def message
|
23
|
+
def message _msg; end
|
24
24
|
|
25
|
-
def dump_summary *
|
25
|
+
def dump_summary *_args; end
|
26
26
|
|
27
|
-
def seed *
|
27
|
+
def seed *_args; end
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def format_message msg
|
32
|
-
msg.gsub("\n",
|
32
|
+
msg.gsub("\n", " ")[0, 80]
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fetching
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Michael Gee
|
@@ -10,12 +9,11 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-18 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: bundler
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
18
|
- - ~>
|
21
19
|
- !ruby/object:Gem::Version
|
@@ -23,7 +21,6 @@ dependencies:
|
|
23
21
|
type: :development
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
25
|
- - ~>
|
29
26
|
- !ruby/object:Gem::Version
|
@@ -31,49 +28,43 @@ dependencies:
|
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: rake
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- -
|
32
|
+
- - '>='
|
37
33
|
- !ruby/object:Gem::Version
|
38
34
|
version: '0'
|
39
35
|
type: :development
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- -
|
39
|
+
- - '>='
|
45
40
|
- !ruby/object:Gem::Version
|
46
41
|
version: '0'
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: rspec
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- -
|
46
|
+
- - '>='
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: '0'
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- -
|
53
|
+
- - '>='
|
61
54
|
- !ruby/object:Gem::Version
|
62
55
|
version: '0'
|
63
56
|
- !ruby/object:Gem::Dependency
|
64
57
|
name: pry-plus
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
59
|
requirements:
|
68
|
-
- -
|
60
|
+
- - '>='
|
69
61
|
- !ruby/object:Gem::Version
|
70
62
|
version: '0'
|
71
63
|
type: :development
|
72
64
|
prerelease: false
|
73
65
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
66
|
requirements:
|
76
|
-
- -
|
67
|
+
- - '>='
|
77
68
|
- !ruby/object:Gem::Version
|
78
69
|
version: '0'
|
79
70
|
description: More sass in more structs.
|
@@ -85,6 +76,7 @@ extensions: []
|
|
85
76
|
extra_rdoc_files: []
|
86
77
|
files:
|
87
78
|
- .gitignore
|
79
|
+
- .rubocop.yml
|
88
80
|
- Gemfile
|
89
81
|
- LICENSE.txt
|
90
82
|
- README.md
|
@@ -102,28 +94,27 @@ files:
|
|
102
94
|
homepage: ''
|
103
95
|
licenses:
|
104
96
|
- MIT
|
97
|
+
metadata: {}
|
105
98
|
post_install_message:
|
106
99
|
rdoc_options: []
|
107
100
|
require_paths:
|
108
101
|
- lib
|
109
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
103
|
requirements:
|
112
|
-
- -
|
104
|
+
- - '>='
|
113
105
|
- !ruby/object:Gem::Version
|
114
106
|
version: '0'
|
115
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
-
none: false
|
117
108
|
requirements:
|
118
|
-
- -
|
109
|
+
- - '>='
|
119
110
|
- !ruby/object:Gem::Version
|
120
111
|
version: '0'
|
121
112
|
requirements: []
|
122
113
|
rubyforge_project:
|
123
|
-
rubygems_version:
|
114
|
+
rubygems_version: 2.0.6
|
124
115
|
signing_key:
|
125
|
-
specification_version:
|
126
|
-
summary:
|
116
|
+
specification_version: 4
|
117
|
+
summary: 'This gem is a work in progress. The implementation code is not what''s
|
127
118
|
important. What is important: Don''t de-serialize API responses in to hashes and
|
128
119
|
arrays. Use a "strict" object that inforces key presence, and array bounds.}'
|
129
120
|
test_files:
|