spigot 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d0f2434369eece13dd6bc280d7a2c2fb3cb4b2a
4
- data.tar.gz: 5c5699bda0ecc9a464d4219abcf4db3f8129f666
3
+ metadata.gz: b31cf21b89e530eb6984aecbe4a22e0bbd82f6f3
4
+ data.tar.gz: bc24b6dc03440a7236c4bdc9e5cdb937a2841341
5
5
  SHA512:
6
- metadata.gz: 3c12327728519a76eec52fef7eb654ed983b8ec4ae1c65a6ec91bb566813e5606a90f60edf544f77e798fa323753a4e976911b802c7cd1bb6775ed42cbc21a1d
7
- data.tar.gz: 93f560a2b2556dd456d9749ddee6e4e810f8749ca18e43412aa96484feabd7ff4b58043d64b8a7eada19469ad2cac2f5e4c5e432b4ecbed69a4f8b44fb149702
6
+ metadata.gz: a17888d4095a7d086a6ef85bd62f886521f0c1cac607e97ea7937d1bd6902ef479873cb9ab7c25056516dd58795cfdc68f71ab8c55165c380fa5b1d21235237f
7
+ data.tar.gz: 434d19e5f3b2a847aa1a2e0328cc50a11d20c07673e177332a2fb87005fe8ae5bb53da09a9a543008f5b3df0faae7a321d0766c13e66170a4e4107c25224ee27
data/README.md CHANGED
@@ -35,6 +35,25 @@ Spigot produces a map of the raw API data you receive to columns in your databas
35
35
 
36
36
  Much better.
37
37
 
38
+ ## Usage
39
+
40
+ This is an example implementation. Assuming you have a User model in your database and you wish to capture the `id`, `name`, `login`, and `avatar_url` from the API payload.
41
+
42
+ require 'open-uri'
43
+ require 'json'
44
+
45
+ Spigot.resource :user do
46
+ id :github_id
47
+ name :name
48
+ login :username
49
+ avatar_url :image_url
50
+ end
51
+
52
+ data = JSON.parse open('https://api.github.com/users/mwerner').read
53
+ User.spigot.create(data)
54
+ # #<User id: 1, name: "Matthew Werner", github_id: 50568, username: "mwerner", avatar_url: "https://avatars.githubusercontent.com/u/50568">
55
+
56
+
38
57
  ## Installation
39
58
 
40
59
  Add this line to your application's Gemfile:
@@ -5,7 +5,7 @@ module Spigot
5
5
  @name = name
6
6
  @value = args
7
7
  @children = []
8
- instance_eval(&block) if block_given?
8
+ instance_eval(&block) if @value.nil? && block_given?
9
9
  @parse = block unless @children.any?
10
10
  end
11
11
 
@@ -1,4 +1,4 @@
1
1
  # Spigot::VERSION
2
2
  module Spigot
3
- VERSION = '0.3.2'
3
+ VERSION = '0.3.3'
4
4
  end
@@ -77,6 +77,13 @@ describe Spigot::Map::Definition do
77
77
  subject.instance_variable_get(:@parse).should_not be_nil
78
78
  subject.instance_variable_get(:@children).length.should eq(0)
79
79
  end
80
+
81
+ it 'requires a attribute param to parse block' do
82
+ subject = Spigot::Map::Definition.define(resource, :foo, 'bar') { |val| "formatted-#{val}" }
83
+ subject.instance_variable_get(:@parse).should_not be_nil
84
+ subject.instance_variable_get(:@children).length.should eq(0)
85
+ subject.parse(foo: 'baz').should eq({bar: 'formatted-baz'})
86
+ end
80
87
  end
81
88
 
82
89
  context '#to_hash' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spigot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Werner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-16 00:00:00.000000000 Z
11
+ date: 2014-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord