halibut 0.4.0 → 0.4.1

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTE5OTFlZmM2MWFlYmVmNTgyZDE5ZDBjYTlkMTY3ZjZkNGZkZjI1Zg==
4
+ MWYxOTQ4OTZiYzU2ZWQyZjk1OTE3NzVmMTA3OTVkMzBhMTQ5NmIyYQ==
5
5
  data.tar.gz: !binary |-
6
- NTc2NDIzNWUwMzhhZjMwYzkyNjg1NTFlMzYxZTg2M2JmOTZiZDE4OA==
7
- !binary "U0hBNTEy":
6
+ NDYzNzNhZjdkZWYxOTg1NjQzOWEzYWQwM2UzZTk0N2FmOWNhYTc1Zg==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- OGYxZTU0OTljZGJjMjdiYTM2MjU3YWVjYTRhMWVmZWI1ZDljZjc4NTIwYWI2
10
- ZGZmMTg4NzJmNjRjMmQyYTdhNGM0MTlmNjRhNTc1NDg0NmQxYzJkZGEzZTVk
11
- YTJiOTcwMjFjYWRlNDVmNzU5OTcyMWQ2MDE1ZDBjMzExOTA5M2U=
9
+ OTdjNmE0Mzg3MDlmZmJlMzc2ZGI1YzE3ZTc4OGZiMjdmNDc2ZDhhMzUwOTM4
10
+ ODA4NDhkNGQ1MjlkMjhjNzY3N2MyMzM4YWVmMjdiM2Q1YmY2NGM0MmM3OGYy
11
+ Y2U1NDNkMjNmOGNkYjBjYmUzYjQxNTI2ZGU2ZWM0MWU4Y2MzY2I=
12
12
  data.tar.gz: !binary |-
13
- MDMzZjk4NGI5MmE2MjZlYjdmOWI4MDA4MjExM2JiNzJhYjdkZDE3NmQ1MWU4
14
- MTM0NWNkZTFjNmZhYTdmNzYzNTM4NjVjMzFlMWZjODk3YzcxYTcyN2I2MTc5
15
- MzU4ZGE4Y2NkYTAyNTVjMTNlZDU1MDkwZTM0YmM2ZDUyMDQwZTA=
13
+ ZDAxZTlhYjRjNzEyOTM4ODg3ZmJmYzczMGU1YTVhMDBlNmZmNzcwNWYyNzhk
14
+ NmU4MTJmNWVjYTQzNWE5OTEzMDUzYjNkYzcxODk5ZjM4ZjQ5YTNjMzQyYTZk
15
+ YzYwOGU2ZjMxOGIzMWJhZWFkZDY5YWVmMGM1NTYwZTk0NmE1OGE=
@@ -1,9 +1,17 @@
1
1
  language: ruby
2
2
  bundler_args: --without testing
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - ruby-head
7
- - jruby-19mode
8
- - jruby-head
9
- - rbx-2.1.1
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - ruby-head
7
+ - jruby-19mode
8
+ - jruby-head
9
+ - rbx-2.1.1
10
+ deploy:
11
+ provider: rubygems
12
+ api_key:
13
+ secure: cMM9SSWMkq6G10Sxs2CXDacurZOkJiaHPHgfffE/6SadZ2nYxPiR637VVq1CspT0rs5La9qUQD7ZwRQ046WfPw84rx5iu8J+sBf7bTrI0OcQLJHcbCGUaFpH01JVD6Nhch5ZrOcts3Xzm7hbOxgEHqATMbCgGb2q9vBORhatnj4=
14
+ gem: halibut
15
+ on:
16
+ tags: true
17
+ repo: locks/halibut
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # Halibut [![endorse](http://api.coderwall.com/locks/endorsecount.png)](http://coderwall.com/locks) [![Stories in Ready](http://badge.waffle.io/locks/halibut.png)](http://waffle.io/locks/halibut)
2
2
 
3
-
4
3
  [![Gem Version](https://badge.fury.io/rb/halibut.png)](http://badge.fury.io/rb/halibut)
5
4
  [![Build Status](https://secure.travis-ci.org/locks/halibut.png?branch=master)](https://travis-ci.org/locks/halibut)
6
5
  [![Coverage Status](https://coveralls.io/repos/locks/halibut/badge.png?branch=master)](https://coveralls.io/r/locks/halibut)
@@ -18,11 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.required_ruby_version = '>= 1.9.3'
19
19
 
20
20
  gem.add_dependency "multi_json"
21
- gem.add_dependency "addressable"
22
21
 
23
22
  # this version of minitest adds parallelization
24
23
  gem.add_development_dependency "rake"
25
24
  gem.add_development_dependency "minitest", ">= 4.2"
26
25
  gem.add_development_dependency "hash-differ"
27
-
28
26
  end
@@ -1,18 +1,17 @@
1
1
  require "halibut/version"
2
2
 
3
3
  # Halibut is the main namespace
4
- module Halibut
5
- autoload :Builder, 'halibut/builder'
6
- autoload :Document, 'halibut/document'
7
- end
4
+ module Halibut; end
5
+
6
+ require 'halibut/builder'
8
7
 
9
8
  # The Adapter namespace contains classes that aid in the
10
9
  # mapping of HAL Resources into a specific format.
11
- module Halibut::Adapter
12
- autoload :JSON, 'halibut/adapter/json'
13
- end
10
+ module Halibut::Adapter; end
11
+
12
+ require 'halibut/adapter/json'
14
13
 
15
14
  # Halibut::Core contains the domain objects that reflect the HAL specs.
16
- module Halibut::Core
17
- autoload :Resource, 'halibut/core/resource'
18
- end
15
+ module Halibut::Core; end
16
+
17
+ require 'halibut/core/resource'
@@ -1,30 +1,67 @@
1
1
  require 'multi_json'
2
-
3
2
  require 'halibut/core'
4
3
 
5
4
  module Halibut::Adapter
6
5
 
6
+ # This adapter converts Halibut::HAL::Resources to JSON encoded strings and back.
7
+ #
8
+ # resource = Halibut::Builder.new('http://example.com') do
9
+ # link "posts", '/posts'
10
+ # link "author", 'http://locks.io'
11
+ #
12
+ # property "title", 'Entry point'
13
+ # end.resource
14
+ #
15
+ # dumped = Halibut::Adapter::JSON.dump resource
16
+ # # => "{\"title\":\"Entry point\",\"_links\":{\"self\":{\"href\":\"http://example.com\"},\"posts\":{\"href\":\"/posts\"},\"author\":{\"href\":\"http://locks.io\"}}}"
17
+ #
18
+ # loaded = Halibut::Adapter::JSON.load dumped
19
+ # resource == loaded
20
+ # # => true
21
+ #
7
22
  module JSON
8
- def self.load(json)
23
+
24
+ # Returns an Halibut::HAL::Resource from a JSON string
25
+ def self.parse(json)
9
26
  ResourceExtractor.new(json).resource
10
27
  end
11
28
 
29
+ # Returns a JSON string representation of an Halibut::HAL::Resource
12
30
  def self.dump(resource)
13
31
  MultiJson.dump resource.to_hash
14
32
  end
15
33
 
16
34
  private
35
+
36
+ # @deprecated Please use Halibut::Adapter::JSON.dump instead.
17
37
  def self.extended(base)
18
38
  base.extend InstanceMethods
19
39
  end
20
40
 
21
41
  module InstanceMethods
42
+ # @deprecated This might go.
22
43
  def to_json
44
+ warn "[Deprecation] Don't depend on this, as it might disappear soon."
23
45
  MultiJson.dump self.to_hash
24
46
  end
25
47
  end
26
48
 
49
+ # ResourceExtractor is responsible for deserializing an HAL resource
50
+ # from the JSON representation.
51
+ #
52
+ # extractor = ResourceExtractor.new({})
53
+ # # => #<Halibut::Adapter::JSON::ResourceExtractor:0x007f8adb92f2a8
54
+ # extractor.resource
55
+ # # => #<Halibut::HAL::Resource:0x007f8add058fb0
56
+ #
27
57
  class ResourceExtractor
58
+
59
+ # Straight-forward, just pass in the JSON string you want to extract the
60
+ # resource from.
61
+ #
62
+ # json = '{"_links":{"self":{"href":"http://example.com"}}}'
63
+ # ResourceExtractor.new('{}')
64
+ #
28
65
  def initialize(json)
29
66
  @halibut = Halibut::Core::Resource.new
30
67
  @json = MultiJson.load(json)
@@ -34,6 +71,7 @@ module Halibut::Adapter
34
71
  extract_embedded_resources
35
72
  end
36
73
 
74
+ # This method should be called when the the resource extracted is needed
37
75
  def resource
38
76
  @halibut
39
77
  end
@@ -68,7 +106,7 @@ module Halibut::Adapter
68
106
  embeds = ([] << values).flatten
69
107
 
70
108
  embeds.map {|embed| MultiJson.dump embed }
71
- .map {|embed| Halibut::Adapter::JSON.load embed }
109
+ .map {|embed| Halibut::Adapter::JSON.parse embed }
72
110
  .each {|embed| @halibut.embed_resource(relation, embed) }
73
111
  end
74
112
  end
@@ -125,6 +125,5 @@ module Halibut
125
125
  @resource.embed_resource(@rel, embedded.resource)
126
126
  end
127
127
  end
128
-
129
128
  end
130
129
  end
@@ -1,6 +1,7 @@
1
1
  module Halibut
2
2
  module Core
3
- autoload :Resource, 'halibut/core/resource'
4
- autoload :Link, 'halibut/core/link'
5
3
  end
6
- end
4
+ end
5
+
6
+ require 'halibut/core/resource'
7
+ require 'halibut/core/link'
@@ -135,5 +135,4 @@ module Halibut::Core
135
135
  end
136
136
  end
137
137
  end
138
-
139
138
  end
@@ -1,4 +1,5 @@
1
1
  require 'halibut/core/relation_map'
2
+ require 'halibut/core/link'
2
3
 
3
4
  module Halibut::Core
4
5
 
@@ -23,7 +23,5 @@ module Halibut
23
23
  def to_s
24
24
  @curie and "#{@curie}:#{@name}" or @name
25
25
  end
26
-
27
26
  end
28
-
29
- end
27
+ end
@@ -1,4 +1,4 @@
1
1
  module Halibut
2
2
  # Semver version (I'll try, pinkie promise)
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
@@ -17,7 +17,7 @@ describe Halibut::Adapter::JSON do
17
17
  end
18
18
 
19
19
  it "deserializes from JSON" do
20
- subject = Halibut::Adapter::JSON.load(load_json "serialize")
20
+ subject = Halibut::Adapter::JSON.parse(load_json "serialize")
21
21
 
22
22
  order = Halibut::Core::Resource.new "/orders/123"
23
23
  order.set_property "total", 30.00
@@ -36,7 +36,7 @@ describe Halibut::Adapter::JSON do
36
36
  end
37
37
 
38
38
  it "provides to_json helper" do
39
- json = Halibut::Adapter::JSON.load(load_json "serialize")
39
+ json = Halibut::Adapter::JSON.parse(load_json "serialize")
40
40
  json = Halibut::Adapter::JSON.dump(json)
41
41
 
42
42
  order = Halibut::Core::Resource.new "/orders/123"
@@ -61,7 +61,7 @@ describe Halibut::Adapter::JSON do
61
61
  files = read_files[]
62
62
 
63
63
  refilled = files.map {|f| MultiJson.load f }
64
- resources = files.map {|f| Halibut::Adapter::JSON.load f }.map &:to_hash
64
+ resources = files.map {|f| Halibut::Adapter::JSON.parse f }.map &:to_hash
65
65
 
66
66
  zipped = refilled.zip resources
67
67
  zipped.each do |json, hal|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: halibut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Mendes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-14 00:00:00.000000000 Z
11
+ date: 2013-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: addressable
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -137,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
123
  version: '0'
138
124
  requirements: []
139
125
  rubyforge_project:
140
- rubygems_version: 2.0.0
126
+ rubygems_version: 2.1.11
141
127
  signing_key:
142
128
  specification_version: 4
143
129
  summary: A HAL parser and builder for use in Hypermedia APIs
@@ -154,4 +140,3 @@ test_files:
154
140
  - spec/fixtures/simple.json
155
141
  - spec/link_relation_spec.rb
156
142
  - spec/spec_helper.rb
157
- has_rdoc: