halogen 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +244 -0
- data/Rakefile +6 -0
- data/examples/extensions.md +25 -0
- data/examples/simple.rb +142 -0
- data/halogen.gemspec +32 -0
- data/lib/halogen.rb +157 -0
- data/lib/halogen/collection.rb +44 -0
- data/lib/halogen/configuration.rb +15 -0
- data/lib/halogen/definition.rb +73 -0
- data/lib/halogen/definitions.rb +23 -0
- data/lib/halogen/embeds.rb +105 -0
- data/lib/halogen/embeds/definition.rb +19 -0
- data/lib/halogen/errors.rb +7 -0
- data/lib/halogen/hash_util.rb +37 -0
- data/lib/halogen/links.rb +41 -0
- data/lib/halogen/links/definition.rb +59 -0
- data/lib/halogen/properties.rb +40 -0
- data/lib/halogen/properties/definition.rb +8 -0
- data/lib/halogen/railtie.rb +11 -0
- data/lib/halogen/resource.rb +58 -0
- data/lib/halogen/version.rb +5 -0
- data/spec/halogen/collection_spec.rb +78 -0
- data/spec/halogen/configuration_spec.rb +11 -0
- data/spec/halogen/definition_spec.rb +108 -0
- data/spec/halogen/definitions_spec.rb +24 -0
- data/spec/halogen/embeds/definition_spec.rb +23 -0
- data/spec/halogen/embeds_spec.rb +201 -0
- data/spec/halogen/links/definition_spec.rb +68 -0
- data/spec/halogen/links_spec.rb +59 -0
- data/spec/halogen/properties_spec.rb +41 -0
- data/spec/halogen/resource_spec.rb +77 -0
- data/spec/halogen_spec.rb +127 -0
- data/spec/spec_helper.rb +11 -0
- metadata +179 -0
@@ -0,0 +1,127 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Halogen do
|
6
|
+
let :klass do
|
7
|
+
Class.new { include Halogen }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Halogen::ClassMethods do
|
11
|
+
describe '#resource' do
|
12
|
+
it 'includes resource module' do
|
13
|
+
klass = Class.new { include Halogen }
|
14
|
+
|
15
|
+
expect(klass).to receive(:define_resource)
|
16
|
+
|
17
|
+
klass.resource :foo
|
18
|
+
|
19
|
+
expect(klass.included_modules.include?(Halogen::Resource)).to eq(true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#collection' do
|
24
|
+
it 'includes collection module' do
|
25
|
+
klass = Class.new { include Halogen }
|
26
|
+
|
27
|
+
expect(klass).to receive(:define_collection)
|
28
|
+
|
29
|
+
klass.collection :foo
|
30
|
+
|
31
|
+
expect(klass.included_modules.include?(Halogen::Collection)).to eq(true)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Halogen::InstanceMethods do
|
37
|
+
describe '#initialize' do
|
38
|
+
it 'symbolizes option keys' do
|
39
|
+
repr = klass.new(
|
40
|
+
'embed' => { 'foo' => 'bar' },
|
41
|
+
'ignore' => 'this',
|
42
|
+
:convert => 'that')
|
43
|
+
|
44
|
+
expect(repr.options).to eq(
|
45
|
+
embed: { 'foo' => 'bar' },
|
46
|
+
ignore: 'this',
|
47
|
+
convert: 'that'
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#render' do
|
53
|
+
let :rendered do
|
54
|
+
klass.new.render
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'renders simple link' do
|
58
|
+
klass.link(:label) { 'href' }
|
59
|
+
|
60
|
+
expect(rendered[:_links][:label]).to eq(href: 'href')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'does not include link if conditional checks fail' do
|
64
|
+
klass.send(:define_method, :return_false) { false }
|
65
|
+
klass.send(:define_method, :return_nil) { nil }
|
66
|
+
|
67
|
+
klass.link(:label) { 'href' }
|
68
|
+
|
69
|
+
klass.link(:label_2, if: false) { 'href' }
|
70
|
+
klass.link(:label_3, if: proc { false }) { 'href' }
|
71
|
+
klass.link(:label_4, if: proc { nil }) { 'href' }
|
72
|
+
klass.link(:label_5, if: :return_false) { 'href' }
|
73
|
+
|
74
|
+
expect(rendered[:_links].keys).to eq([:label])
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'includes link if conditional checks pass' do
|
78
|
+
klass.send(:define_method, :return_true) { true }
|
79
|
+
klass.send(:define_method, :return_one) { 1 }
|
80
|
+
|
81
|
+
klass.link(:label) { 'href' }
|
82
|
+
|
83
|
+
klass.link(:label_2, if: true) { 'href' }
|
84
|
+
klass.link(:label_3, if: proc { true }) { 'href' }
|
85
|
+
klass.link(:label_4, if: proc { 1 }) { 'href' }
|
86
|
+
klass.link(:label_5, if: :return_true) { 'href' }
|
87
|
+
|
88
|
+
expected = [:label, :label_2, :label_3, :label_4, :label_5]
|
89
|
+
expect(rendered[:_links].keys).to eq(expected)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#depth' do
|
94
|
+
it 'is zero for top level representer' do
|
95
|
+
expect(klass.new.depth).to eq(0)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'has expected value for embedded children' do
|
99
|
+
parent = klass.new
|
100
|
+
|
101
|
+
child = klass.new
|
102
|
+
allow(child).to receive(:parent).and_return(parent)
|
103
|
+
|
104
|
+
grandchild = klass.new
|
105
|
+
allow(grandchild).to receive(:parent).and_return(child)
|
106
|
+
|
107
|
+
expect(parent.depth).to eq(0)
|
108
|
+
expect(child.depth).to eq(1)
|
109
|
+
expect(grandchild.depth).to eq(2)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#to_json' do
|
114
|
+
it 'converts rendered representer to json' do
|
115
|
+
expect(klass.new.to_json).to eq('{}')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '.config' do
|
121
|
+
it 'yields configuration instance' do
|
122
|
+
Halogen.configure do |config|
|
123
|
+
expect(config).to eq(Halogen.config)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: halogen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Heather Rivers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
97
|
+
description: Provides a framework-agnostic interface for generating HAL+JSON representations
|
98
|
+
of resources
|
99
|
+
email:
|
100
|
+
- heather@modeanalytics.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- examples/extensions.md
|
112
|
+
- examples/simple.rb
|
113
|
+
- halogen.gemspec
|
114
|
+
- lib/halogen.rb
|
115
|
+
- lib/halogen/collection.rb
|
116
|
+
- lib/halogen/configuration.rb
|
117
|
+
- lib/halogen/definition.rb
|
118
|
+
- lib/halogen/definitions.rb
|
119
|
+
- lib/halogen/embeds.rb
|
120
|
+
- lib/halogen/embeds/definition.rb
|
121
|
+
- lib/halogen/errors.rb
|
122
|
+
- lib/halogen/hash_util.rb
|
123
|
+
- lib/halogen/links.rb
|
124
|
+
- lib/halogen/links/definition.rb
|
125
|
+
- lib/halogen/properties.rb
|
126
|
+
- lib/halogen/properties/definition.rb
|
127
|
+
- lib/halogen/railtie.rb
|
128
|
+
- lib/halogen/resource.rb
|
129
|
+
- lib/halogen/version.rb
|
130
|
+
- spec/halogen/collection_spec.rb
|
131
|
+
- spec/halogen/configuration_spec.rb
|
132
|
+
- spec/halogen/definition_spec.rb
|
133
|
+
- spec/halogen/definitions_spec.rb
|
134
|
+
- spec/halogen/embeds/definition_spec.rb
|
135
|
+
- spec/halogen/embeds_spec.rb
|
136
|
+
- spec/halogen/links/definition_spec.rb
|
137
|
+
- spec/halogen/links_spec.rb
|
138
|
+
- spec/halogen/properties_spec.rb
|
139
|
+
- spec/halogen/resource_spec.rb
|
140
|
+
- spec/halogen_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
homepage: https://github.com/mode/halogen
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - "~>"
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '2.0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.2.2
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: HAL+JSON generator
|
166
|
+
test_files:
|
167
|
+
- spec/halogen/collection_spec.rb
|
168
|
+
- spec/halogen/configuration_spec.rb
|
169
|
+
- spec/halogen/definition_spec.rb
|
170
|
+
- spec/halogen/definitions_spec.rb
|
171
|
+
- spec/halogen/embeds/definition_spec.rb
|
172
|
+
- spec/halogen/embeds_spec.rb
|
173
|
+
- spec/halogen/links/definition_spec.rb
|
174
|
+
- spec/halogen/links_spec.rb
|
175
|
+
- spec/halogen/properties_spec.rb
|
176
|
+
- spec/halogen/resource_spec.rb
|
177
|
+
- spec/halogen_spec.rb
|
178
|
+
- spec/spec_helper.rb
|
179
|
+
has_rdoc:
|