cross_origin 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f049945e2e24d37459f557a062abe66fd78a4d71
4
+ data.tar.gz: cb53cf3deedd9c36190e212954dbf96074233815
5
+ SHA512:
6
+ metadata.gz: 97653cbbcc6c8e88a6c4238ff2d93027331d230a1f1181f092e3417a9b78258abd433d82aeb2656a74709b735fd91ea2240f2353cab2b4cdf809e8fd821dd017
7
+ data.tar.gz: ba58ab5a06600327e1798ac38bb3ebaf7ff8d56f216e29ae02a55de5a31caa903b87b32eb50a721f31b99cc2ef927cd2222ce48becc0818401cd50c6973a137f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,34 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Ruby Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
+ <option name="GEM_APP_TEST_PATH" value="$MODULE_DIR$/test" />
8
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="NewModuleRootManager">
13
+ <content url="file://$MODULE_DIR$">
14
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
15
+ <excludeFolder url="file://$MODULE_DIR$/.bundle" />
16
+ <excludeFolder url="file://$MODULE_DIR$/vendor/bundle" />
17
+ </content>
18
+ <orderEntry type="jdk" jdkName="RVM: ruby-2.2.1 [rails-4.2]" jdkType="RUBY_SDK" />
19
+ <orderEntry type="sourceFolder" forTests="false" />
20
+ <orderEntry type="library" scope="PROVIDED" name="activemodel (v4.2.5.1, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v4.2.5.1, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="bson (v3.2.6, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.2, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v0.7.0, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="json (v1.8.3, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.8.4, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="mongo (v2.1.2, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="mongoid (v5.0.1, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="origin (v2.1.1, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.5, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.2, RVM: ruby-2.2.1 [rails-4.2]) [gem]" level="application" />
33
+ </component>
34
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding">
4
+ <file url="PROJECT" charset="UTF-8" />
5
+ </component>
6
+ </project>
data/.idea/misc.xml ADDED
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectLevelVcsManager" settingsEditedManually="false">
4
+ <OptionsSetting value="true" id="Add" />
5
+ <OptionsSetting value="true" id="Remove" />
6
+ <OptionsSetting value="true" id="Checkout" />
7
+ <OptionsSetting value="true" id="Update" />
8
+ <OptionsSetting value="true" id="Status" />
9
+ <OptionsSetting value="true" id="Edit" />
10
+ <ConfirmationsSetting value="0" id="Add" />
11
+ <ConfirmationsSetting value="0" id="Remove" />
12
+ </component>
13
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.2.1" project-jdk-type="RUBY_SDK" />
14
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/cross_origin.iml" filepath="$PROJECT_DIR$/.idea/cross_origin.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ChangeListManager">
4
+ <option name="TRACKING_ENABLED" value="true" />
5
+ <option name="SHOW_DIALOG" value="false" />
6
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
7
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
8
+ <option name="LAST_RESOLUTION" value="IGNORE" />
9
+ </component>
10
+ <component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
11
+ <component name="CreatePatchCommitExecutor">
12
+ <option name="PATCH_PATH" value="" />
13
+ </component>
14
+ <component name="ProjectLevelVcsManager" settingsEditedManually="false">
15
+ <OptionsSetting value="true" id="Add" />
16
+ <OptionsSetting value="true" id="Remove" />
17
+ <OptionsSetting value="true" id="Checkout" />
18
+ <OptionsSetting value="true" id="Update" />
19
+ <OptionsSetting value="true" id="Status" />
20
+ <OptionsSetting value="true" id="Edit" />
21
+ <ConfirmationsSetting value="0" id="Add" />
22
+ <ConfirmationsSetting value="0" id="Remove" />
23
+ </component>
24
+ <component name="PropertiesComponent">
25
+ <property name="settings.editor.selected.configurable" value="configurable.group.appearance" />
26
+ <property name="settings.editor.splitter.proportion" value="0.2" />
27
+ </component>
28
+ <component name="ShelveChangesManager" show_recycled="false" />
29
+ <component name="TaskManager">
30
+ <task active="true" id="Default" summary="Default task">
31
+ <created>1460059436786</created>
32
+ <option name="number" value="Default" />
33
+ <updated>1460059436786</updated>
34
+ </task>
35
+ <servers />
36
+ </component>
37
+ <component name="VcsContentAnnotationSettings">
38
+ <option name="myLimit" value="2678400000" />
39
+ </component>
40
+ <component name="XDebuggerManager">
41
+ <breakpoint-manager />
42
+ <watches-manager />
43
+ </component>
44
+ </project>
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'mongoid', '>= 5.0.1'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 macarci
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,44 @@
1
+ # Cross Origin
2
+
3
+ With cross origin you can store and retrieve documents with your Mongoid models from multiples collections.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cross_origin'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cross_origin
20
+
21
+ ## Usage
22
+
23
+ Configurate your origins
24
+
25
+ ```ruby
26
+ CrossOrigin.config :test
27
+ ```
28
+
29
+ and include the module `CrossOrigin::Document` in your Mongoid class
30
+
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/macarci/cross_origin/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cross_origin"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cross_origin/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cross_origin'
8
+ spec.version = CrossOrigin::VERSION
9
+ spec.authors = ['macarci']
10
+ spec.email = ['macarci@gmail.com']
11
+
12
+ spec.summary = %q{Allows Mongoid models to store and retrieve documents from multiples collections.}
13
+ spec.homepage = 'https://github.com/macarci/cross_origin'
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_development_dependency 'bundler', '~> 1.8'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ end
@@ -0,0 +1,65 @@
1
+ module CrossOrigin
2
+ class Collection < Mongo::Collection
3
+
4
+ attr_reader :default_collection, :model
5
+
6
+ def initialize(default_collection, model)
7
+ default_collection.instance_values.each { |name, value| instance_variable_set(:"@#{name}", value) }
8
+ @default_collection = default_collection
9
+ @model = model
10
+ end
11
+
12
+ def find(filter = nil, options = {})
13
+ View.new(self, filter || {}, options, model)
14
+ end
15
+
16
+ class View < Mongo::Collection::View
17
+
18
+ attr_reader :model
19
+
20
+ def initialize(collection, selector, options, model)
21
+ super(collection, selector, options)
22
+ @model = model
23
+ end
24
+
25
+ def each(&block)
26
+ if block
27
+ super(&block)
28
+ cross_views.each { |view| view.each(&block) }
29
+ end
30
+ end
31
+
32
+ def count(options = {})
33
+ super + (options[:super] ? 0 : cross_views.inject(0) { |count, view| count + view.count })
34
+ end
35
+
36
+ def cross_views
37
+ views = []
38
+ skip, limit = self.skip, self.limit
39
+ opts = options
40
+ previous_view = self
41
+ count = 0
42
+ CrossOrigin.configurations.each do |config|
43
+ if skip || limit
44
+ opts = opts.dup
45
+ count += previous_view.count(super: true, skip: 0)
46
+ if skip
47
+ opts[:skip] = skip = (count < skip ? skip - count : 0)
48
+ end
49
+ if limit
50
+ current_skip = skip || 0
51
+ skipped_count = (current_skip > count ? 0 : count - current_skip)
52
+ opts[:limit] = limit = (limit > skipped_count ? limit - skipped_count : 0)
53
+ end
54
+ end
55
+ views << (previous_view = config.collection_for(model).find(selector, opts).modifiers(modifiers))
56
+ end
57
+ views
58
+ end
59
+
60
+ def new(options)
61
+ View.new(collection, selector, options, model)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,42 @@
1
+
2
+ module CrossOrigin
3
+ module Document
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ field :origin, type: Symbol, default: :default
8
+
9
+ attr_readonly :origin
10
+
11
+ validates_inclusion_of :origin, in: ->(doc) { doc.origin_enum }
12
+
13
+ def origin_enum
14
+ [:default] + CrossOrigin.names.to_a
15
+ end
16
+
17
+ def collection_name
18
+ origin == :default ? super : CrossOrigin[origin].collection_name_for(self.class)
19
+ end
20
+
21
+ def client_name
22
+ origin == :default ? super : CrossOrigin[origin].name
23
+ end
24
+ end
25
+
26
+ module ClassMethods
27
+
28
+ def collection
29
+ CrossOrigin::Collection.new(super, self)
30
+ end
31
+
32
+ def mongoid_root_class
33
+ @mongoid_root_class ||=
34
+ begin
35
+ root = self
36
+ root = root.superclass while root.superclass.include?(Mongoid::Document)
37
+ root
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module CrossOrigin
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,54 @@
1
+ require 'cross_origin/version'
2
+ require 'cross_origin/collection'
3
+ require 'cross_origin/document'
4
+
5
+ module CrossOrigin
6
+
7
+ class << self
8
+
9
+ def [](origin)
10
+ origin = origin.to_s.to_sym unless origin.is_a?(Symbol)
11
+ origin_options[origin]
12
+ end
13
+
14
+ def config(origin, options = {})
15
+ origin = origin.to_s.to_sym unless origin.is_a?(Symbol)
16
+ fail "Not allowed for origin name: #{origin}" if origin == :default
17
+ origin_options[origin] || (origin_options[origin] = Config.new(origin, options))
18
+ end
19
+
20
+ def configurations
21
+ origin_options.values
22
+ end
23
+
24
+ def names
25
+ origin_options.keys
26
+ end
27
+
28
+ private
29
+
30
+ def origin_options
31
+ @origin_options ||= {}
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ class Config
38
+
39
+ attr_reader :name, :options
40
+
41
+ def initialize(name, options)
42
+ @name = name
43
+ @options = options
44
+ end
45
+
46
+ def collection_name_for(model)
47
+ "#{name}_#{model.mongoid_root_class.storage_options_defaults[:collection]}"
48
+ end
49
+
50
+ def collection_for(model)
51
+ (Mongoid::Clients.clients[name] || Mongoid.default_client)[collection_name_for(model)]
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cross_origin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - macarci
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - macarci@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".idea/cross_origin.iml"
50
+ - ".idea/encodings.xml"
51
+ - ".idea/misc.xml"
52
+ - ".idea/modules.xml"
53
+ - ".idea/workspace.xml"
54
+ - CODE_OF_CONDUCT.md
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/console
60
+ - bin/setup
61
+ - cross_origin.gemspec
62
+ - lib/cross_origin.rb
63
+ - lib/cross_origin/collection.rb
64
+ - lib/cross_origin/document.rb
65
+ - lib/cross_origin/version.rb
66
+ homepage: https://github.com/macarci/cross_origin
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.2.2
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Allows Mongoid models to store and retrieve documents from multiples collections.
90
+ test_files: []