hyperdrive 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07f5a0eb011e90e579c34dce6b40de76283317ab
4
- data.tar.gz: e8a2a287eeb5eab40734d3a7280b63542277ef68
3
+ metadata.gz: d771b35e3bf1f63f0319a13657e7cf5b8eed07b4
4
+ data.tar.gz: 0a023a7d94436547475ca7c3c52a2e879edeabde
5
5
  SHA512:
6
- metadata.gz: 292b94365b311ae7c868982be4216a26ebb184b8b34761409d624479cf5fccbc6265fbd8e200bfbef9f69c66448bbff4e51f00e40d042010376b41c5e137b1e3
7
- data.tar.gz: 3878db43f89d42c364cc1da9dedd8c2a07eb8ea2c60919a3618bf4365fea8c9d2a65d073835b54c8fd70d7f0fae3d26f34a2121473cdd62bd3cb4f828677e044
6
+ metadata.gz: e57fcc5a0fc983d0eef36c18773346c3b013c3be3f59e2081ccf94c96dc930f040faaac655c695fe5e55076690f4fa7cec3cbf8d34be6b976530b7ece110f4d2
7
+ data.tar.gz: 4b79e421774282b70f94d40354d62957e4db5d9c5b839888193a6f71228417b9c463e62244409985ef8323782e85dc3ccf47e7a8d27078d89e59b227de6f8b94
@@ -6,13 +6,15 @@ module Hyperdrive
6
6
  attr_reader :id, :namespace, :endpoint, :params, :filters, :request_handlers, :version
7
7
  attr_accessor :name, :description
8
8
 
9
- def initialize(name, hyperdrive_config = hyperdrive.config)
10
- @namespace = name.to_s.en.plural
11
- @endpoint = "/#{namespace}"
9
+ def initialize(resource, options = {})
10
+ @resource = resource.to_s.split('_')
11
+ @resource[-1] = @resource[-1].en.plural
12
+ @namespace = @resource.join(':')
13
+ @endpoint = options.fetch(:endpoint) { "/#{@resource.join('/')}" }
12
14
  @params = default_params
13
15
  @filters = default_filters
14
16
  @request_handlers = default_request_handlers
15
- @config = hyperdrive_config
17
+ @config = hyperdrive.config
16
18
  @id = [@config[:vendor], @namespace].join(':')
17
19
  end
18
20
 
@@ -41,11 +43,12 @@ module Hyperdrive
41
43
 
42
44
  def acceptable_content_types(http_request_method)
43
45
  content_types = []
46
+ media_type_namepace = @resource.join('.')
44
47
  @config[:media_types].each do |media_type|
45
48
  available_versions(http_request_method).each do |version|
46
- content_types << "application/vnd.#{@config[:vendor]}.#{namespace}.#{version}+#{media_type}"
49
+ content_types << "application/vnd.#{@config[:vendor]}.#{media_type_namepace}.#{version}+#{media_type}"
47
50
  end
48
- content_types << "application/vnd.#{@config[:vendor]}.#{namespace}+#{media_type}"
51
+ content_types << "application/vnd.#{@config[:vendor]}.#{media_type_namepace}+#{media_type}"
49
52
  content_types << "application/vnd.#{@config[:vendor]}+#{media_type}"
50
53
  end
51
54
  content_types
@@ -1,3 +1,3 @@
1
1
  module Hyperdrive
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -2,12 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  describe Hyperdrive::Resource do
4
4
  before do
5
- @resource = Hyperdrive::Resource.new(:thing, { vendor: 'hyperdrive', media_types: ['json'] })
5
+ @resource = Hyperdrive::Resource.new(:thing)
6
6
  @resource.register_param(:name, 'Thing Name')
7
7
  @resource.register_filter(:parent_id, 'Parent ID', required: true)
8
8
  @resource.register_request_handler(:get, Proc.new { |env| 'v1' })
9
9
  @resource.register_request_handler(:get, Proc.new { |env| 'v2' }, 'v2')
10
- @media_types = ["application/vnd.hyperdrive.things.v2+json",
10
+ @media_types = ["application/vnd.hyperdrive.things.v2+hal+json",
11
+ "application/vnd.hyperdrive.things.v1+hal+json",
12
+ "application/vnd.hyperdrive.things+hal+json",
13
+ "application/vnd.hyperdrive+hal+json",
14
+ "application/vnd.hyperdrive.things.v2+json",
11
15
  "application/vnd.hyperdrive.things.v1+json",
12
16
  "application/vnd.hyperdrive.things+json",
13
17
  "application/vnd.hyperdrive+json"]
@@ -126,4 +130,40 @@ describe Hyperdrive::Resource do
126
130
  it "returns a hash representation of the resource" do
127
131
  @resource.to_hash.must_be_kind_of Hash
128
132
  end
133
+
134
+ context "compound namspaces" do
135
+ before do
136
+ @compound_resource = Hyperdrive::Resource.new(:goof_ball)
137
+ end
138
+
139
+ it "has an ID" do
140
+ @compound_resource.id.must_equal "hyperdrive:goof:balls"
141
+ end
142
+
143
+ it "has a namespace" do
144
+ @compound_resource.namespace.must_equal 'goof:balls'
145
+ end
146
+
147
+ it "has an endpoint" do
148
+ @compound_resource.endpoint.must_equal '/goof/balls'
149
+ end
150
+ end
151
+
152
+ context "options" do
153
+ before do
154
+ @resource_with_options = Hyperdrive::Resource.new(:great_thing, endpoint: '/great-things')
155
+ end
156
+
157
+ it "has an ID" do
158
+ @resource_with_options.id.must_equal "hyperdrive:great:things"
159
+ end
160
+
161
+ it "has a namespace" do
162
+ @resource_with_options.namespace.must_equal 'great:things'
163
+ end
164
+
165
+ it "has an endpoint" do
166
+ @resource_with_options.endpoint.must_equal '/great-things'
167
+ end
168
+ end
129
169
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperdrive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - StyleSeek Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-10 00:00:00.000000000 Z
11
+ date: 2014-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: linguistics