blockhead 0.1.0 → 0.1.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 +4 -4
- data/lib/blockhead.rb +0 -12
- data/lib/blockhead/extractors/abstract.rb +4 -0
- data/lib/blockhead/extractors/value.rb +2 -6
- data/lib/blockhead/marshaller.rb +3 -1
- data/lib/blockhead/version.rb +1 -1
- data/spec/blockhead/schema_spec.rb +25 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a25635acbe737a9bb1a835991c44832f3ac02388
|
4
|
+
data.tar.gz: 56b936c08c511abc20980fed4063f47618440c09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 158300c7966ca2ef3c6f0e9a2e03d47dd679e1bc0daf4c6693d358d4361b3e11a67b603b75b18c2cb7b0953df8d9089664353b019a8f0a283ff7674a430e0600
|
7
|
+
data.tar.gz: 572f8400f3652eb2a73fd592156e0d868e9742b8e9cd4b91c56ce2ca7a6eed8e5e4bd782ac04869f49f5ba9a945dde9b915e5e6084328a739ba4a9bb11b63a48
|
data/lib/blockhead.rb
CHANGED
@@ -10,16 +10,4 @@ require 'blockhead/extractors/proc'
|
|
10
10
|
require 'blockhead/extractors/value'
|
11
11
|
|
12
12
|
module Blockhead
|
13
|
-
|
14
|
-
def self.configure
|
15
|
-
yield self if block_given?
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.pretty_print=(enabled = true)
|
19
|
-
@pretty_print = enabled
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.pretty_print
|
23
|
-
@pretty_print
|
24
|
-
end
|
25
13
|
end
|
@@ -12,16 +12,12 @@ module Blockhead
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def value
|
15
|
-
if object.is_a?(String) &&
|
16
|
-
|
15
|
+
if object.is_a?(String) && args.first == :pretty_print
|
16
|
+
object.split(/ |\_/).map(&:capitalize).join(' ').strip
|
17
17
|
else
|
18
18
|
object
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
22
|
-
def pretty
|
23
|
-
object.split(/ |\_/).map(&:capitalize).join(' ').strip
|
24
|
-
end
|
25
21
|
end
|
26
22
|
end
|
27
23
|
end
|
data/lib/blockhead/marshaller.rb
CHANGED
@@ -13,12 +13,14 @@ module Blockhead
|
|
13
13
|
|
14
14
|
def method_missing(name, *args, &block)
|
15
15
|
@arg = args.first
|
16
|
-
key = OptionKey.new(name,
|
16
|
+
key = OptionKey.new(name, arg).key
|
17
17
|
attributes[key] = ValueExtractor.new(_call(name), *args, &block).extract
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
+
attr_reader :arg
|
23
|
+
|
22
24
|
def _call(name)
|
23
25
|
if @arg == :wrap
|
24
26
|
object
|
data/lib/blockhead/version.rb
CHANGED
@@ -2,29 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'debugger'
|
3
3
|
require 'ostruct'
|
4
4
|
|
5
|
-
describe Blockhead, '#config' do
|
6
|
-
class MessyObject
|
7
|
-
def title
|
8
|
-
" title stuffs \n"
|
9
|
-
end
|
10
|
-
|
11
|
-
def foo
|
12
|
-
12
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'prettifies object attributes that are string values' do
|
17
|
-
Blockhead.configure do |config|
|
18
|
-
config.pretty_print = true
|
19
|
-
end
|
20
|
-
|
21
|
-
schema = Blockhead::Schema.define MessyObject.new do
|
22
|
-
title
|
23
|
-
end.marshal
|
24
|
-
expect(schema[:title]).to eq 'Title Stuffs'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
5
|
describe Blockhead::Schema, '::define' do
|
29
6
|
class Tester
|
30
7
|
def title
|
@@ -48,6 +25,16 @@ describe Blockhead::Schema, '::define' do
|
|
48
25
|
end
|
49
26
|
end
|
50
27
|
|
28
|
+
class BadFormatting
|
29
|
+
def title
|
30
|
+
" title and things\r\n "
|
31
|
+
end
|
32
|
+
|
33
|
+
def another_field
|
34
|
+
" another thing \n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
51
38
|
it 'returns a hash' do
|
52
39
|
schema = schema_with { title }
|
53
40
|
|
@@ -147,7 +134,7 @@ describe Blockhead::Schema, '::define' do
|
|
147
134
|
expect(schema.marshal).to eq 'header' => 'Title', 'body' => 'Description'
|
148
135
|
end
|
149
136
|
|
150
|
-
it 'raises
|
137
|
+
it 'raises TypeError on nil aliases' do
|
151
138
|
expect {
|
152
139
|
schema_with do
|
153
140
|
title as: header
|
@@ -177,6 +164,18 @@ describe Blockhead::Schema, '::define' do
|
|
177
164
|
expect(schema.marshal).to eq result
|
178
165
|
end
|
179
166
|
|
167
|
+
it 'cleans fields when passed :cleanup' do
|
168
|
+
schema = schema_with(BadFormatting) do
|
169
|
+
title :pretty_print
|
170
|
+
another_field
|
171
|
+
end.marshal
|
172
|
+
|
173
|
+
expect(schema).to eq(
|
174
|
+
title: 'Title And Things',
|
175
|
+
another_field: " another thing \n"
|
176
|
+
)
|
177
|
+
end
|
178
|
+
|
180
179
|
it 'handles nested objects with aliases' do
|
181
180
|
schema = schema_with do
|
182
181
|
nested_obj as: :cart do
|
@@ -209,7 +208,7 @@ describe Blockhead::Schema, '::define' do
|
|
209
208
|
expect(schema.marshal).to eq title: 'Title', empty_array: []
|
210
209
|
end
|
211
210
|
|
212
|
-
def schema_with(&block)
|
213
|
-
Blockhead::Schema.define(
|
211
|
+
def schema_with(klass = Tester, &block)
|
212
|
+
Blockhead::Schema.define(klass.new, &block)
|
214
213
|
end
|
215
214
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blockhead
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Franco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|