kanade 0.1.0.beta2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kanade/converter/base.rb +22 -19
- data/lib/kanade/converter/symbol.rb +24 -3
- data/lib/kanade/version.rb +1 -1
- data/spec/converter/symbol_spec.rb +108 -0
- metadata +6 -11
- data/.editorconfig +0 -15
- data/.gitignore +0 -14
- data/.rspec +0 -2
- data/.travis.yml +0 -7
- data/Gemfile.lock +0 -59
- data/Rakefile +0 -23
- data/kanade.gemspec +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e14f9aa4f66bd889b92a50d647f1e5960e97fa29
|
4
|
+
data.tar.gz: 981d3757563627830e3f9915cee805ce503a14b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e8fbd233dee70b732dc5740d10a537310318331520ec38b3b5cc0e512d126ebe083852552b756463825b2d104ca974caceb26175504df1ae56fb807eb0b0e71
|
7
|
+
data.tar.gz: 7a2cf02be31a566e191075c0ddfcc03974f304e082310a40aca9a0bcce60c69b74eb99df5bb3fb8798830c794bc25228759a8fa169c278e5762cd734cca9686d
|
@@ -1,19 +1,22 @@
|
|
1
|
-
module Kanade
|
2
|
-
module Converter
|
3
|
-
class Base
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
module Kanade
|
2
|
+
module Converter
|
3
|
+
class Base
|
4
|
+
# TODO use module.included
|
5
|
+
# Engine.register_converter!(self)
|
6
|
+
|
7
|
+
# STORED OBJECT --> JSON String
|
8
|
+
def serialize(term, field_info)
|
9
|
+
raise NotSupportedError
|
10
|
+
end
|
11
|
+
|
12
|
+
# JSON String / Input object --> Ruby object
|
13
|
+
def deserialize(term, field_info)
|
14
|
+
raise NotSupportedError
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configurable(name, default)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -5,16 +5,37 @@ module Kanade
|
|
5
5
|
|
6
6
|
def serialize(term, field_info)
|
7
7
|
return nil if term.nil?
|
8
|
-
|
8
|
+
map = field_info.options[:mapping]
|
9
|
+
map_entry = map[term] unless map.nil?
|
10
|
+
return map_entry unless map_entry.nil?
|
11
|
+
term.to_s.upcase
|
9
12
|
end
|
10
13
|
|
11
14
|
def deserialize(term, field_info)
|
15
|
+
# TODO WARNING: This is not thread safe!
|
16
|
+
# Consider moving this into field definition instead
|
17
|
+
build_field_info(field_info) if field_info.options[:mapping_inverted].nil?
|
18
|
+
|
12
19
|
return nil if term.nil?
|
13
|
-
|
14
|
-
|
20
|
+
inv = field_info.options[:mapping_inverted][term]
|
21
|
+
return inv unless inv.nil?
|
22
|
+
|
23
|
+
# TODO use contract!
|
24
|
+
term.to_s.downcase.to_sym
|
15
25
|
end
|
16
26
|
|
17
27
|
configurable :symbol_contract, :camel_case
|
28
|
+
|
29
|
+
private
|
30
|
+
def build_field_info fi
|
31
|
+
if fi.options[:mapping].nil?
|
32
|
+
inverted = {}
|
33
|
+
else
|
34
|
+
inverted = fi.options[:mapping].invert
|
35
|
+
end
|
36
|
+
|
37
|
+
fi.options[:mapping_inverted] = inverted
|
38
|
+
end
|
18
39
|
end
|
19
40
|
end
|
20
41
|
end
|
data/lib/kanade/version.rb
CHANGED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Kanade::Converter::Symbol do
|
4
|
+
|
5
|
+
let(:converter) { Kanade::Converter::Symbol.new }
|
6
|
+
|
7
|
+
let(:field_info) do
|
8
|
+
f = Kanade::FieldInfo.new
|
9
|
+
f.options = {}
|
10
|
+
f
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:mapping) do
|
14
|
+
{
|
15
|
+
stop: 'SRV_STOP',
|
16
|
+
ready: 'SRV_READY'
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'can serialize' do
|
21
|
+
subject { converter.serialize(term, field_info) }
|
22
|
+
|
23
|
+
context 'nil object' do
|
24
|
+
let(:term) { nil }
|
25
|
+
it { is_expected.to be_nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'single word' do
|
29
|
+
let(:term) { :nil }
|
30
|
+
it { is_expected.to eq('NIL') }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'multiple word' do
|
34
|
+
let(:term) { :mantap_sekali }
|
35
|
+
it { is_expected.to eq('MANTAP_SEKALI') }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'can deserialize' do
|
40
|
+
subject { converter.deserialize(term, field_info) }
|
41
|
+
|
42
|
+
context 'nil object' do
|
43
|
+
let(:term) { nil }
|
44
|
+
it { is_expected.to be_nil }
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'single word' do
|
48
|
+
let(:term) { 'NIL' }
|
49
|
+
it { is_expected.to eq( :nil ) }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'multiple word' do
|
53
|
+
let(:term) { 'MANTAP_SEKALI' }
|
54
|
+
it { is_expected.to eq(:mantap_sekali) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'can serialize with mapping' do
|
59
|
+
before { field_info.options[:mapping] = mapping }
|
60
|
+
subject { converter.serialize(term, field_info) }
|
61
|
+
|
62
|
+
context 'nil object' do
|
63
|
+
let(:term) { nil }
|
64
|
+
it { is_expected.to be_nil }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'single word' do
|
68
|
+
let(:term) { :nil }
|
69
|
+
it { is_expected.to eq('NIL') }
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'multiple word' do
|
73
|
+
let(:term) { :mantap_sekali }
|
74
|
+
it { is_expected.to eq('MANTAP_SEKALI') }
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'mapping' do
|
78
|
+
let(:term) { :ready }
|
79
|
+
it { is_expected.to eq('SRV_READY') }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'can deserialize with mapping' do
|
84
|
+
before { field_info.options[:mapping] = mapping }
|
85
|
+
subject { converter.deserialize(term, field_info) }
|
86
|
+
|
87
|
+
context 'nil object' do
|
88
|
+
let(:term) { nil }
|
89
|
+
it { is_expected.to be_nil }
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'single word' do
|
93
|
+
let(:term) { 'NIL' }
|
94
|
+
it { is_expected.to eq( :nil ) }
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'multiple word' do
|
98
|
+
let(:term) { 'MANTAP_SEKALI' }
|
99
|
+
it { is_expected.to eq(:mantap_sekali) }
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'mapping' do
|
103
|
+
let(:term) { 'SRV_READY' }
|
104
|
+
it { is_expected.to eq(:ready) }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mufid Afif
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -115,18 +115,11 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- ".editorconfig"
|
119
|
-
- ".gitignore"
|
120
|
-
- ".rspec"
|
121
|
-
- ".travis.yml"
|
122
118
|
- Gemfile
|
123
|
-
- Gemfile.lock
|
124
119
|
- LICENSE
|
125
120
|
- README-id.md
|
126
121
|
- README.md
|
127
122
|
- ROADMAP.md
|
128
|
-
- Rakefile
|
129
|
-
- kanade.gemspec
|
130
123
|
- lib/kanade.rb
|
131
124
|
- lib/kanade/all.rb
|
132
125
|
- lib/kanade/config/default.rb
|
@@ -149,6 +142,7 @@ files:
|
|
149
142
|
- lib/kanade/naming_strategy/snake_case.rb
|
150
143
|
- lib/kanade/version.rb
|
151
144
|
- spec/converter/string_spec.rb
|
145
|
+
- spec/converter/symbol_spec.rb
|
152
146
|
- spec/fixtures/catalog.rb
|
153
147
|
- spec/fixtures/catalog_camel_case.json
|
154
148
|
- spec/fixtures/catalog_pascal_case.json
|
@@ -182,9 +176,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
176
|
version: '0'
|
183
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
178
|
requirements:
|
185
|
-
- - "
|
179
|
+
- - ">="
|
186
180
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
181
|
+
version: '0'
|
188
182
|
requirements: []
|
189
183
|
rubyforge_project:
|
190
184
|
rubygems_version: 2.5.1
|
@@ -193,6 +187,7 @@ specification_version: 4
|
|
193
187
|
summary: Strong-typed JSON to Ruby object serializer/deserializer
|
194
188
|
test_files:
|
195
189
|
- spec/converter/string_spec.rb
|
190
|
+
- spec/converter/symbol_spec.rb
|
196
191
|
- spec/fixtures/catalog.rb
|
197
192
|
- spec/fixtures/catalog_camel_case.json
|
198
193
|
- spec/fixtures/catalog_pascal_case.json
|
data/.editorconfig
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# This file is for unifying the coding style for different editors and IDEs
|
2
|
-
# editorconfig.org
|
3
|
-
|
4
|
-
root = true
|
5
|
-
|
6
|
-
[*]
|
7
|
-
end_of_line = lf
|
8
|
-
charset = utf-8
|
9
|
-
trim_trailing_whitespace = true
|
10
|
-
insert_final_newline = true
|
11
|
-
indent_style = space
|
12
|
-
indent_size = 2
|
13
|
-
|
14
|
-
# [*.md]
|
15
|
-
# trim_trailing_whitespace = false
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile.lock
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
kanade (0.1.0.beta2)
|
5
|
-
activesupport
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activesupport (5.0.0.1)
|
11
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
-
i18n (~> 0.7)
|
13
|
-
minitest (~> 5.1)
|
14
|
-
tzinfo (~> 1.1)
|
15
|
-
coderay (1.1.1)
|
16
|
-
concurrent-ruby (1.0.2)
|
17
|
-
diff-lcs (1.2.5)
|
18
|
-
i18n (0.7.0)
|
19
|
-
method_source (0.8.2)
|
20
|
-
minitest (5.9.0)
|
21
|
-
pry (0.10.3)
|
22
|
-
coderay (~> 1.1.0)
|
23
|
-
method_source (~> 0.8.1)
|
24
|
-
slop (~> 3.4)
|
25
|
-
rake (11.2.2)
|
26
|
-
rspec (3.5.0)
|
27
|
-
rspec-core (~> 3.5.0)
|
28
|
-
rspec-expectations (~> 3.5.0)
|
29
|
-
rspec-mocks (~> 3.5.0)
|
30
|
-
rspec-core (3.5.4)
|
31
|
-
rspec-support (~> 3.5.0)
|
32
|
-
rspec-expectations (3.5.0)
|
33
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
-
rspec-support (~> 3.5.0)
|
35
|
-
rspec-mocks (3.5.0)
|
36
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.5.0)
|
38
|
-
rspec-support (3.5.0)
|
39
|
-
slop (3.6.0)
|
40
|
-
thread_safe (0.3.5)
|
41
|
-
timecop (0.8.1)
|
42
|
-
tzinfo (1.2.2)
|
43
|
-
thread_safe (~> 0.1)
|
44
|
-
yard (0.8.7.6)
|
45
|
-
|
46
|
-
PLATFORMS
|
47
|
-
ruby
|
48
|
-
|
49
|
-
DEPENDENCIES
|
50
|
-
bundler (~> 1.12)
|
51
|
-
kanade!
|
52
|
-
pry
|
53
|
-
rake
|
54
|
-
rspec (~> 3.5)
|
55
|
-
timecop
|
56
|
-
yard
|
57
|
-
|
58
|
-
BUNDLED WITH
|
59
|
-
1.13.1
|
data/Rakefile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
require "yard"
|
4
|
-
require 'bundler'
|
5
|
-
|
6
|
-
begin
|
7
|
-
Bundler.setup :default, :development
|
8
|
-
Bundler::GemHelper.install_tasks
|
9
|
-
rescue Bundler::BundlerError => error
|
10
|
-
$stderr.puts error.message
|
11
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
12
|
-
exit error.status_code
|
13
|
-
end
|
14
|
-
|
15
|
-
RSpec::Core::RakeTask.new(:spec)
|
16
|
-
|
17
|
-
desc "Generate all of the docs"
|
18
|
-
YARD::Rake::YardocTask.new do |config|
|
19
|
-
config.files = Dir["lib/**/*.rb"]
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "Default: run tests and generate docs"
|
23
|
-
task :default => [ :spec, :yard ]
|
data/kanade.gemspec
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
|
-
require 'kanade/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = "kanade"
|
9
|
-
spec.version = Kanade::VERSION
|
10
|
-
spec.authors = ["Mufid Afif"]
|
11
|
-
spec.email = ["mufid@outlook.com"]
|
12
|
-
spec.summary = %q{ Strong-typed JSON to Ruby object serializer/deserializer }
|
13
|
-
spec.description = %q{ Strong-typed JSON to Ruby object serializer/deserializer }
|
14
|
-
spec.homepage = "https://github.com/mufid/kanade"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
-
f.start_with?("bower_components") || f.start_with?("website") || f.start_with?("bin") || f.start_with?("example")
|
19
|
-
end
|
20
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
-
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
# We use active support inflection, case conversion, and a lot more.
|
24
|
-
# Yes yes yes we need to be independent from active support, but this
|
25
|
-
# is good enough for now.
|
26
|
-
spec.add_dependency "activesupport"
|
27
|
-
|
28
|
-
spec.add_development_dependency "bundler", "~> 1.12"
|
29
|
-
spec.add_development_dependency "rake"
|
30
|
-
spec.add_development_dependency "yard"
|
31
|
-
spec.add_development_dependency "pry"
|
32
|
-
spec.add_development_dependency "rspec", "~> 3.5"
|
33
|
-
spec.add_development_dependency "timecop"
|
34
|
-
end
|