dao-gateway-active_resource 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b177bf24454de496c068100e9fec858c2b44ef8
4
+ data.tar.gz: 061c7e8b2d85b8077a6efa5ea50358526f0e2e6f
5
+ SHA512:
6
+ metadata.gz: 7b78ae37a1497957adf07d02f146a29cecbd8b09929cd0bb307ab1d4f1a889ca34caba9f93e6df8d95c768f2f7623cbb4762b33eaadf4b84b1a45a767f9cc37a
7
+ data.tar.gz: 5b958ceca6a20b744574babe225736edd33affb7c442d5e167df4f46b6cad665d6e7f32edd2f16a245a53fd609bd2459b9a990addfc3c3dce3f199b48e003ed2
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
11
+ .ruby-version
12
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Александр Фомин
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.
@@ -0,0 +1,62 @@
1
+ # Dao::Gateway::ActiveResource
2
+
3
+ [![Build Status](https://travis-ci.org/dao-rb/dao-gateway-active_resource.svg?branch=master)](https://travis-ci.org/dao-rb/dao-gateway-active_resource)
4
+ [![Code Climate](https://codeclimate.com/github/dao-rb/dao-gateway-active_resource/badges/gpa.svg)](https://codeclimate.com/github/dao-rb/dao-gateway-active_resource)
5
+ [![Test Coverage](https://codeclimate.com/github/dao-rb/dao-gateway-active_resource/badges/coverage.svg)](https://codeclimate.com/github/dao-rb/dao-gateway-active_resource/coverage)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dao-gateway-active_resource'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dao-gateway-active_resource
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'dao/entity'
27
+ require 'dao/repository'
28
+ require 'dao/gateway/active_resource'
29
+
30
+ class Post < ActiveResource::Base
31
+ end
32
+
33
+ class PostEntity < Dao::Entity::Base
34
+ attribute :id, Integer
35
+ attribute :body, String
36
+ end
37
+
38
+ class PostRepository < Dao::Repository::Base
39
+ entity PostEntity
40
+ gateway Dao::Gateway::ActiveResource::Base, Post, Dao::Gateway::ActiveResource::BaseTransformer
41
+ end
42
+
43
+ post = PostRepository.last
44
+
45
+ post.id # => 1
46
+ post.body # => "Post body"
47
+ ```
48
+
49
+ ## Development
50
+
51
+ 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.
52
+
53
+ 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).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dao-rb/dao-gateway-active_resource.
58
+
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'dao/gateway/active_resource'
5
+
6
+ require 'irb'
7
+ IRB.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'dao/gateway/active_resource/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'dao-gateway-active_resource'
7
+ spec.version = Dao::Gateway::ActiveResource::VERSION
8
+ spec.authors = ['llxff', 'ssnikolay']
9
+ spec.email = ['ll.wg.bin@gmail.com']
10
+
11
+ spec.summary = 'Gateway for Active Resource'
12
+ spec.description = 'Gateway for Active Resource'
13
+ spec.homepage = 'https://github.com/dao-rb/dao-gateway-active_resource'
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.add_dependency 'dao-gateway', '~> 1.0'
22
+ spec.add_dependency 'activeresource', '>= 4.1'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.11'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.4'
27
+ spec.add_development_dependency 'rspec-its'
28
+ spec.add_development_dependency 'dao-entity', '~> 1.0'
29
+ end
@@ -0,0 +1,15 @@
1
+ require 'dao/gateway'
2
+ require 'dao/gateway/active_resource/version'
3
+
4
+ require 'active_resource'
5
+ require 'active_support/hash_with_indifferent_access'
6
+
7
+ require 'dao/gateway/active_resource/base'
8
+ require 'dao/gateway/active_resource/base_transformer'
9
+
10
+ module Dao
11
+ module Gateway
12
+ module ActiveResource
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,56 @@
1
+ module Dao
2
+ module Gateway
3
+ module ActiveResource
4
+ class Base < Dao::Gateway::Base
5
+ def map(object, _)
6
+ import(object)
7
+ end
8
+
9
+ def save!(domain, _)
10
+ record = export(domain, record(domain.id))
11
+ record.save!
12
+
13
+ domain.attributes = import(record).attributes
14
+ domain
15
+ rescue ::ActiveResource::ResourceInvalid
16
+ raise Dao::Gateway::InvalidRecord.new(record.errors.to_hash)
17
+ end
18
+
19
+ def chain(scope, method_name, args, &block)
20
+ scope.public_send(method_name, *args, &block)
21
+ rescue ::ActiveResource::ResourceNotFound => e
22
+ raise Dao::Gateway::RecordNotFound, e.message
23
+ end
24
+
25
+ protected
26
+
27
+ def export(base, record = nil)
28
+ return unless base
29
+ record ||= source.new
30
+ attributes = base.attributes.except(*@black_list_attributes).stringify_keys
31
+
32
+ record.attributes = attributes
33
+ record
34
+ end
35
+
36
+ def import(relation)
37
+ unless relation.nil?
38
+ if relation.is_a?(::ActiveResource::Collection)
39
+ @transformer.many(relation)
40
+ elsif relation.is_a?(source)
41
+ @transformer.one(relation)
42
+ else
43
+ @transformer.other(relation)
44
+ end
45
+ end
46
+ end
47
+
48
+ def record(domain_id)
49
+ source.find(domain_id) if domain_id.present?
50
+ rescue ::ActiveResource::ResourceNotFound
51
+ nil
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,27 @@
1
+ module Dao
2
+ module Gateway
3
+ module ActiveResource
4
+ class BaseTransformer < Dao::Gateway::ScopeTransformer
5
+ def many(relation)
6
+ super(relation)
7
+ end
8
+
9
+ def one(relation)
10
+ super(Array(relation))
11
+ end
12
+
13
+ private
14
+
15
+ def transform(relation)
16
+ super(relation) do |record|
17
+ collect_attributes(record)
18
+ end
19
+ end
20
+
21
+ def collect_attributes(record)
22
+ HashWithIndifferentAccess.new(record.try(:serializable_hash))
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module Dao
2
+ module Gateway
3
+ module ActiveResource
4
+ VERSION = '1.0.0'
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dao-gateway-active_resource
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-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: dao-gateway
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: activeresource
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '4.1'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '4.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.11'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.11'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.4'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.4'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec-its
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: dao-entity
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.0'
112
+ description: Gateway for Active Resource
113
+ email:
114
+ - ll.wg.bin@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - dao-gateway-active_resource.gemspec
129
+ - lib/dao/gateway/active_resource.rb
130
+ - lib/dao/gateway/active_resource/base.rb
131
+ - lib/dao/gateway/active_resource/base_transformer.rb
132
+ - lib/dao/gateway/active_resource/version.rb
133
+ homepage: https://github.com/dao-rb/dao-gateway-active_resource
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.5.1
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Gateway for Active Resource
157
+ test_files: []