dao-gateway 1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dao-gateway.gemspec +27 -0
- data/lib/dao/gateway/base.rb +79 -0
- data/lib/dao/gateway/invalid_record.rb +12 -0
- data/lib/dao/gateway/record_not_found.rb +5 -0
- data/lib/dao/gateway/scope_transformer.rb +44 -0
- data/lib/dao/gateway/transaction_not_supported.rb +5 -0
- data/lib/dao/gateway/version.rb +5 -0
- data/lib/dao/gateway.rb +13 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a333a3af2fed768ff134e876f7499671dce28fae
|
4
|
+
data.tar.gz: 1bac797dacc1daa57720af7c229ebfe260b5c1b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b8b8787d3c05ab7be3fbc7387806c7ed9658249eb7c03374dcf918fa7f4c07e06c544a1c823fd356d45c58c8e07dc020ea2a60f12e3d9c4ca2f3e99dc704a4b
|
7
|
+
data.tar.gz: 316cae5284892c87afbeb2fcea83197b9397a53ea4e7542ec1c802f187c917bc9f52e080c820aac9c9ccfac0ceb53d83d146ec3e8b198d8ef8e60495e06b79f5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 llxff
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Dao::Gateway
|
2
|
+
|
3
|
+
[](https://travis-ci.org/dao-rb/dao-gateway)
|
4
|
+
[](https://codeclimate.com/github/dao-rb/dao-gateway)
|
5
|
+
[](https://codeclimate.com/github/dao-rb/dao-gateway/coverage)
|
6
|
+
|
7
|
+
This is a basic class for your gateway.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'dao-gateway'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install dao-gateway
|
24
|
+
|
25
|
+
|
26
|
+
## Development
|
27
|
+
|
28
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
29
|
+
|
30
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dao-rb/dao-gateway.
|
35
|
+
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
40
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dao/gateway"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/dao-gateway.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'dao/gateway/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'dao-gateway'
|
7
|
+
spec.version = Dao::Gateway::VERSION
|
8
|
+
spec.authors = ['llxff', 'ssnikolay']
|
9
|
+
spec.email = ['ll.wg.bin@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Base gateway interface for dao-rb/repository'
|
12
|
+
spec.description = 'Base gateway interface for dao-rb/repository'
|
13
|
+
spec.homepage = 'https://github.com/dao-rb/dao-gateway'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.2.2'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
26
|
+
spec.add_development_dependency 'rspec-its'
|
27
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Dao
|
2
|
+
module Gateway
|
3
|
+
class Base
|
4
|
+
attr_reader :source, :transformer, :black_list_attributes
|
5
|
+
|
6
|
+
def initialize(source, transformer)
|
7
|
+
@source = source
|
8
|
+
@transformer = transformer
|
9
|
+
|
10
|
+
@black_list_attributes = @transformer.export_attributes_black_list
|
11
|
+
end
|
12
|
+
|
13
|
+
def map(object, associations)
|
14
|
+
import(object, associations)
|
15
|
+
end
|
16
|
+
|
17
|
+
def save!(_domain, _attributes)
|
18
|
+
fail 'save! is not implemented'
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(_domain_id)
|
22
|
+
fail 'delete is not implemented'
|
23
|
+
end
|
24
|
+
|
25
|
+
def chain(_scope, _method_name, _args, &_block)
|
26
|
+
fail 'chain is not implemented'
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_relations(scope, _relations)
|
30
|
+
scope
|
31
|
+
end
|
32
|
+
|
33
|
+
def with_transaction(&_block)
|
34
|
+
raise TransactionNotSupported
|
35
|
+
end
|
36
|
+
|
37
|
+
def serializable_relations(relations)
|
38
|
+
convert_array(relations)
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def export(_base, _record = nil)
|
44
|
+
fail 'export is not implemented'
|
45
|
+
end
|
46
|
+
|
47
|
+
def import(_relation, _associations)
|
48
|
+
fail 'import is not implemented'
|
49
|
+
end
|
50
|
+
|
51
|
+
def record(_domain_id)
|
52
|
+
fail 'record is not implemented'
|
53
|
+
end
|
54
|
+
|
55
|
+
def convert_array(array)
|
56
|
+
array.collect do |value|
|
57
|
+
if value.is_a? Hash
|
58
|
+
convert_hash(value)
|
59
|
+
else
|
60
|
+
value
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def convert_hash(hash)
|
66
|
+
hash.each_with_object({}) do |(key, value), new_hash|
|
67
|
+
new_hash[key] =
|
68
|
+
if value.is_a? Array
|
69
|
+
{ include: convert_array(value) }
|
70
|
+
elsif value.is_a? Hash
|
71
|
+
{ include: convert_hash(value) }
|
72
|
+
else
|
73
|
+
{ include: value }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Dao
|
2
|
+
module Gateway
|
3
|
+
class ScopeTransformer
|
4
|
+
attr_reader :entity
|
5
|
+
attr_accessor :associations
|
6
|
+
|
7
|
+
def initialize(entity)
|
8
|
+
@entity = entity
|
9
|
+
@associations = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def many(relation)
|
13
|
+
transform(relation)
|
14
|
+
end
|
15
|
+
|
16
|
+
def one(relation)
|
17
|
+
transform(relation).first
|
18
|
+
end
|
19
|
+
|
20
|
+
def other(relation)
|
21
|
+
relation
|
22
|
+
end
|
23
|
+
|
24
|
+
def export_attributes_black_list
|
25
|
+
[]
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def transform(relation, &block)
|
31
|
+
Enumerator.new do |collection|
|
32
|
+
entities = relation
|
33
|
+
entities = relation.collect(&block) if block_given?
|
34
|
+
entities.each do |attributes|
|
35
|
+
collection << @entity.new(attributes).tap do |entity|
|
36
|
+
entity.initialized_with = associations
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
data/lib/dao/gateway.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'dao/gateway/version'
|
2
|
+
|
3
|
+
require 'dao/gateway/record_not_found'
|
4
|
+
require 'dao/gateway/transaction_not_supported'
|
5
|
+
require 'dao/gateway/invalid_record'
|
6
|
+
|
7
|
+
require 'dao/gateway/scope_transformer'
|
8
|
+
require 'dao/gateway/base'
|
9
|
+
|
10
|
+
module Dao
|
11
|
+
module Gateway
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dao-gateway
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- llxff
|
8
|
+
- ssnikolay
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-06-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.11'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.11'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.4'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.4'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec-its
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: Base gateway interface for dao-rb/repository
|
71
|
+
email:
|
72
|
+
- ll.wg.bin@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- dao-gateway.gemspec
|
87
|
+
- lib/dao/gateway.rb
|
88
|
+
- lib/dao/gateway/base.rb
|
89
|
+
- lib/dao/gateway/invalid_record.rb
|
90
|
+
- lib/dao/gateway/record_not_found.rb
|
91
|
+
- lib/dao/gateway/scope_transformer.rb
|
92
|
+
- lib/dao/gateway/transaction_not_supported.rb
|
93
|
+
- lib/dao/gateway/version.rb
|
94
|
+
homepage: https://github.com/dao-rb/dao-gateway
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 2.2.2
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.5.1
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Base gateway interface for dao-rb/repository
|
118
|
+
test_files: []
|