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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25723d77b3f99e8994da9fd4aa44eba091198831
4
- data.tar.gz: 9458dddba1f8fdff1041ab11cd79a5c83e9c8183
3
+ metadata.gz: e14f9aa4f66bd889b92a50d647f1e5960e97fa29
4
+ data.tar.gz: 981d3757563627830e3f9915cee805ce503a14b6
5
5
  SHA512:
6
- metadata.gz: 66d8f6cdb94ce27c648957e5089d7884101b0087a5916da253acfab3f4c2905b31ac8117282c1b73785fcad7d0589ce4c0692e6147609402e0f0cbdbffe4ddd1
7
- data.tar.gz: b5b0884a344d5f26b314231d569e6c300ead110eac7dd47217f396378c9ecc9573c35af615c23bbe0779880c03e5bee3973e9692ce813fa4ecdc6d84a7a38390
6
+ metadata.gz: 6e8fbd233dee70b732dc5740d10a537310318331520ec38b3b5cc0e512d126ebe083852552b756463825b2d104ca974caceb26175504df1ae56fb807eb0b0e71
7
+ data.tar.gz: 7a2cf02be31a566e191075c0ddfcc03974f304e082310a40aca9a0bcce60c69b74eb99df5bb3fb8798830c794bc25228759a8fa169c278e5762cd734cca9686d
@@ -1,19 +1,22 @@
1
- module Kanade
2
- module Converter
3
- class Base
4
- # STORED OBJECT --> JSON String
5
- def serialize(term, field_info)
6
- raise NotSupportedError
7
- end
8
-
9
- # JSON String / Input object --> Ruby object
10
- def deserialize(term, field_info)
11
- raise NotSupportedError
12
- end
13
-
14
- def self.configurable(name, default)
15
- end
16
-
17
- end
18
- end
19
- end
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
- term.to_s
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
- return term if term.is_a?(String)
14
- term.to_s
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
@@ -1,3 +1,3 @@
1
1
  module Kanade
2
- VERSION = '0.1.0.beta2'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -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.beta2
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-03 00:00:00.000000000 Z
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: 1.3.1
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
@@ -1,14 +0,0 @@
1
- # Alphabetically by category first, then by term.
2
- # For sorting, omit dot for dot files
3
-
4
- # Documentation
5
- doc
6
- .yardoc
7
-
8
- # Development file
9
- .devel
10
- pkg
11
-
12
- # IDE-specific
13
- *.swp
14
-
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.1
4
- notifications:
5
- email:
6
- on_success: change
7
- on_failure: change
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