active_remote-bulk 0.1.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: 7bb1c7ca7d280a88b80fe1136fef3d06bb58a30d
4
+ data.tar.gz: 4d9aad14da64e922a5e8d69d5f825a0bcada570b
5
+ SHA512:
6
+ metadata.gz: 9c01e2f1439b1427368ad481811fe87a9659da27cee40ca502533a6a8fc6c7e2ef255cb8fa3980550f24b084110852dba915a1726d1ee1dac348186b03f1e3d0
7
+ data.tar.gz: 15d1fb84efd602f1cd7777813fdd9860cb39ff9de71291c24218cdda884e38d07cffe88365ec4d3c0ff06eb3509b6fc6913bf74537af1caf6b35089f6ea8dd57
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.ruby-*
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_remote-bulk.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Adam Hutchison
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,48 @@
1
+ # ActiveRemote::Bulk
2
+
3
+ Extracted from ActiveRemote
4
+
5
+ Implements methods for bulk creation, updating, and deletion of records
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'active_remote-bulk'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install active_remote-bulk
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ class Tag < ::ActiveRemote::Base
27
+ end
28
+
29
+ Tag.create_all(:name => "foo")
30
+ Tag.update_all(:guid => "1234", :name => "bar")
31
+ Tag.destroy_all(:guid => "1234")
32
+ ```
33
+
34
+ ## Development
35
+
36
+ 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.
37
+
38
+ 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).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Adam Hutchison/active_remote-bulk.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
48
+
@@ -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,31 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'active_remote/bulk/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'active_remote-bulk'
9
+ spec.version = ActiveRemote::Bulk::VERSION
10
+ spec.authors = ['Adam Hutchison']
11
+ spec.email = ['liveh2o@gmail.com']
12
+
13
+ spec.summary = 'Bulk methods for ActiveRemote'
14
+ spec.description = 'Bulk methods for ActiveRemote'
15
+ spec.homepage = 'https://github.com/mxenabled/active_remote-bulk'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'active_remote', '>= 2.4'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.14'
28
+ spec.add_development_dependency 'pry'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_remote/bulk"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require 'active_remote/bulk/version'
3
+
4
+ require 'active_remote'
5
+ require 'active_remote/bulk/errors'
6
+ require 'active_remote/bulk/persistence'
7
+
8
+ module ActiveRemote
9
+ module Bulk
10
+ end
11
+
12
+ class Base
13
+ include ::ActiveRemote::Bulk::Persistence
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ module ActiveRemote
3
+ module Bulk
4
+ class InvalidResponse < ::ActiveRemote::ActiveRemoteError
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+ require 'active_support/concern'
3
+
4
+ module ActiveRemote
5
+ module Bulk
6
+ module Persistence
7
+ extend ::ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+ # Create multiple records at the same time. Returns a collection of active
11
+ # remote objects from the passed records. Records that were not created
12
+ # are returned with error messages indicating what went wrong.
13
+ #
14
+ # ====Examples
15
+ #
16
+ # # A single hash
17
+ # Tag.create_all({ :name => 'foo' })
18
+ #
19
+ # # Hashes
20
+ # Tag.create_all({ :name => 'foo' }, { :name => 'bar' })
21
+ #
22
+ # # Active remote objects
23
+ # Tag.create_all(Tag.new(:name => 'foo'), Tag.new(:name => 'bar'))
24
+ #
25
+ # # Protobuf objects
26
+ # Tag.create_all(Generic::Remote::Tag.new(:name => 'foo'), Generic::Remote::Tag.new(:name => 'bar'))
27
+ #
28
+ # # Bulk protobuf object
29
+ # Tag.create_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:name => 'foo') ])
30
+ #
31
+ def create_all(*records)
32
+ response = rpc.execute(:create_all, _parse_records(records))
33
+
34
+ if response.respond_to?(:records)
35
+ serialize_records(response.records)
36
+ else
37
+ raise ::ActiveRemote::Bulk::InvalidResponse
38
+ end
39
+ end
40
+
41
+ # Delete multiple records at the same time. Returns a collection of active
42
+ # remote objects from the passed records. Records that were not deleted
43
+ # are returned with error messages indicating what went wrong.
44
+ #
45
+ # ====Examples
46
+ #
47
+ # # A single hash
48
+ # Tag.delete_all({ :guid => 'foo' })
49
+ #
50
+ # # Hashes
51
+ # Tag.delete_all({ :guid => 'foo' }, { :guid => 'bar' })
52
+ #
53
+ # # Active remote objects
54
+ # Tag.delete_all(Tag.new(:guid => 'foo'), Tag.new(:guid => 'bar'))
55
+ #
56
+ # # Protobuf objects
57
+ # Tag.delete_all(Generic::Remote::Tag.new(:guid => 'foo'), Generic::Remote::Tag.new(:guid => 'bar'))
58
+ #
59
+ # # Bulk protobuf object
60
+ # Tag.delete_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo') ])
61
+ #
62
+ def delete_all(*records)
63
+ response = rpc.execute(:delete_all, _parse_records(records))
64
+
65
+ if response.respond_to?(:records)
66
+ serialize_records(response.records)
67
+ else
68
+ raise ::ActiveRemote::Bulk::InvalidResponse
69
+ end
70
+ end
71
+
72
+ # Destroy multiple records at the same time. Returns a collection of active
73
+ # remote objects from the passed records. Records that were not destroyed
74
+ # are returned with error messages indicating what went wrong.
75
+ #
76
+ # ====Examples
77
+ #
78
+ # # A single hash
79
+ # Tag.destroy_all({ :guid => 'foo' })
80
+ #
81
+ # # Hashes
82
+ # Tag.destroy_all({ :guid => 'foo' }, { :guid => 'bar' })
83
+ #
84
+ # # Active remote objects
85
+ # Tag.destroy_all(Tag.new(:guid => 'foo'), Tag.new(:guid => 'bar'))
86
+ #
87
+ # # Protobuf objects
88
+ # Tag.destroy_all(Generic::Remote::Tag.new(:guid => 'foo'), Generic::Remote::Tag.new(:guid => 'bar'))
89
+ #
90
+ # # Bulk protobuf object
91
+ # Tag.destroy_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo') ])
92
+ #
93
+ def destroy_all(*records)
94
+ response = rpc.execute(:destroy_all, _parse_records(records))
95
+
96
+ if response.respond_to?(:records)
97
+ serialize_records(response.records)
98
+ else
99
+ raise ::ActiveRemote::Bulk::InvalidResponse
100
+ end
101
+ end
102
+
103
+ # Update multiple records at the same time. Returns a collection of active
104
+ # remote objects from the passed records. Records that were not updated
105
+ # are returned with error messages indicating what went wrong.
106
+ #
107
+ # ====Examples
108
+ #
109
+ # # A single hash
110
+ # Tag.update_all({ :guid => 'foo', :name => 'baz' })
111
+ #
112
+ # # Hashes
113
+ # Tag.update_all({ :guid => 'foo', :name => 'baz' }, { :guid => 'bar', :name => 'qux' })
114
+ #
115
+ # # Active remote objects
116
+ # Tag.update_all(Tag.new(:guid => 'foo', :name => 'baz'), Tag.new(:guid => 'bar', :name => 'qux'))
117
+ #
118
+ # # Protobuf objects
119
+ # Tag.update_all(Generic::Remote::Tag.new(:guid => 'foo', :name => 'baz'), Generic::Remote::Tag.new(:guid => 'bar', :name => 'qux'))
120
+ #
121
+ # # Bulk protobuf object
122
+ # Tag.update_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo', :name => 'baz') ])
123
+ #
124
+ def update_all(*records)
125
+ response = rpc.execute(:update_all, _parse_records(records))
126
+
127
+ if response.respond_to?(:records)
128
+ serialize_records(response.records)
129
+ else
130
+ raise ::ActiveRemote::Bulk::InvalidResponse
131
+ end
132
+ end
133
+
134
+ private
135
+
136
+ def _parse_records(*records)
137
+ records.flatten!
138
+
139
+ if records.first.respond_to?(:attributes)
140
+ records.collect!(&:attributes)
141
+ else
142
+ records.collect!(&:to_hash)
143
+ end
144
+
145
+ return records.first if records.first && records.first.key?(:records)
146
+
147
+ # If we made it this far, build a bulk-formatted hash.
148
+ { records: records }
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ module ActiveRemote
3
+ module Bulk
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_remote-bulk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Hutchison
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: active_remote
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Bulk methods for ActiveRemote
84
+ email:
85
+ - liveh2o@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - active_remote-bulk.gemspec
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/active_remote/bulk.rb
101
+ - lib/active_remote/bulk/errors.rb
102
+ - lib/active_remote/bulk/persistence.rb
103
+ - lib/active_remote/bulk/version.rb
104
+ homepage: https://github.com/mxenabled/active_remote-bulk
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.6.10
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Bulk methods for ActiveRemote
128
+ test_files: []