grape-entity-hypertext_application_language 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c4634707e3d908cef570a755aa838a0bebbc247d
4
+ data.tar.gz: e38b227961f6ba48a795963202a491216a32e466
5
+ SHA512:
6
+ metadata.gz: b0756ea175bde52a889d9559091a948d5eab02b0b5b261a6865bc7c13833ae06e602afa517e04725a07b5b71ef2c65142e99c1985a95da95dea67e1abc3f0da8
7
+ data.tar.gz: 0c060c2c56f5412412167404cdf598295c9d78671b1166ce52beacb45ca7c6256ec71ee3adef3884b647ef3d6e7cb71e08a3576e99b43a930ab34fee75ec1a6f
data/.gitignore ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # Grape Entity Extensions for HAL
2
+
3
+ Converts a Grape entity to a Hypertext Application Language representation.
4
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'grape-entity-hypertext_application_language'
3
+ spec.version = '0.0.0'
4
+ spec.summary = %q{Grape Entity extensions for Hypertext Application Language}
5
+ spec.description = %q{}
6
+ spec.homepage = 'http://stateless.co/hal_specification.html'
7
+ spec.authors = ['Roy Ratcliffe']
8
+ spec.email = ['roy@pioneeringsoftware.co.uk']
9
+ spec.files = `git ls-files -z`.split("\x0")
10
+ spec.license = 'MIT'
11
+
12
+ spec.add_dependency 'grape-entity'
13
+ spec.add_dependency 'hypertext_application_language'
14
+
15
+ spec.add_development_dependency 'bundler'
16
+ spec.add_development_dependency 'rake'
17
+ end
@@ -0,0 +1 @@
1
+ require 'hypertext_application_language/grape/entity'
@@ -0,0 +1,25 @@
1
+ require 'grape_entity/entity'
2
+
3
+ module Grape
4
+ class Entity
5
+ def to_hal(env: {})
6
+ representation = HypertextApplicationLanguage::Representation.new
7
+
8
+ rel = object.class.table_name
9
+ representation.with_link(HypertextApplicationLanguage::Link::SELF_REL, "#{rel}/#{object.id}")
10
+
11
+ object.class.reflections.each do |name, reflection|
12
+ href = unless %i(has_one belongs_to).include?(reflection.macro) && (association = object.send(name))
13
+ "#{representation.link.href}/#{name}"
14
+ else
15
+ "#{reflection.plural_name}/#{association.id}"
16
+ end
17
+ representation.with_link(name, href)
18
+ end
19
+
20
+ representation.properties = serializable_hash
21
+
22
+ representation
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grape-entity-hypertext_application_language
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Roy Ratcliffe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grape-entity
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hypertext_application_language
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
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ''
70
+ email:
71
+ - roy@pioneeringsoftware.co.uk
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - README.md
79
+ - Rakefile
80
+ - grape-entity-hypertext_application_language.gemspec
81
+ - lib/grape-entity-hypertext_application_language.rb
82
+ - lib/hypertext_application_language/grape/entity.rb
83
+ homepage: http://stateless.co/hal_specification.html
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Grape Entity extensions for Hypertext Application Language
107
+ test_files: []
108
+ has_rdoc: