mongoid-simple-userstamps 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 23fc551a807ce53504bc27bf5fee96c47f75e4c4
4
+ data.tar.gz: e6a2fa15f28b7bfc24d5d331272f52a95cd90014
5
+ SHA512:
6
+ metadata.gz: 712547f7c22ab893ca5f5bc8687272e3eaa1a9888935575d4eab42ac284f862ef8ae633e9fc006ac6f8ede6d728a02cee75ddba768bfc07753a12c6900b5912c
7
+ data.tar.gz: ab2cf7aaabe14c84d9894de176d355c735cbc13988b66ccee22e33d5cabf1c0b6b183566937f15263f05ba844e47e0bda76e2dc27fd549c8de88f8517e0af5ce
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongoid-normalize-strings.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Rafael Jurado
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Mongoid::Userstamps
2
+
3
+ Adds stamps relations to mongoid models.
4
+
5
+ ## Version Support
6
+
7
+ Mongoid 5.x
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'mongoid-simple-userstamps'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mongoid-simple-userstamps
22
+
23
+ ## Usage
24
+
25
+ * Include `Mongoid::Userstamps::User` in your 'User' model.
26
+ * Include `Mongoid::Userstamps::Model` in your models you want user stamps.
27
+ * Define current user.
28
+
29
+ ```ruby
30
+ class User
31
+ include Mongoid::Document
32
+ include Mongoid::Userstamps::User
33
+ end
34
+
35
+ class Post
36
+ include Mongoid::Document
37
+ include Mongoid::Userstamps::Model
38
+
39
+ field :title
40
+ end
41
+
42
+ user = User.create
43
+ Mongoid::Userstamps::Config.set_current(user)
44
+
45
+ pòst = Post.create
46
+ post.created_by # <User _id: 57305c268675c32e1c70a17e >
47
+ post.updated_by # nil
48
+
49
+ post.title = 'title'
50
+ post.save
51
+ post.updated_by # <User _id: 57305c268675c32e1c70a17e >
52
+ ```
53
+
54
+ ### Rails
55
+
56
+ * Define current user in your `application_controller.rb`
57
+
58
+ ```ruby
59
+ class ApplicationController < ActionController::Base
60
+ before_action :define_userstamps_current
61
+
62
+ protected
63
+
64
+ def define_userstamps_current
65
+ Mongoid::Userstamps::Config.set_current(current_user)
66
+ end
67
+ end
68
+ ```
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it (
73
+ http://github.com/<my-github-username>/mongoid-simple-userstamps/fork )
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ ##
2
+ # This module store Userstamps config
3
+ #
4
+ module Mongoid
5
+ module Userstamps
6
+ module Config
7
+ @@model = nil
8
+ @@current = nil
9
+
10
+ def self.current
11
+ @@current
12
+ end
13
+
14
+ def self.model
15
+ @@model
16
+ end
17
+
18
+ def self.set_current(current)
19
+ @@current = current
20
+ end
21
+
22
+ def self.set_model(user_class)
23
+ @@user_class = user_class
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ ##
2
+ # This module add user stamps to class
3
+ #
4
+ module Mongoid
5
+ module Userstamps
6
+ module Model
7
+ def self.included(base)
8
+ base.send(:belongs_to, :created_by, {polymorphic: true})
9
+ base.send(:belongs_to, :updated_by, {polymorphic: true})
10
+
11
+ base.send(:before_create) do
12
+ self.created_by = Mongoid::Userstamps::Config.current
13
+ end
14
+
15
+ base.send(:before_update) do
16
+ self.updated_by = Mongoid::Userstamps::Config.current
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ ##
2
+ # This module define stamps model
3
+ #
4
+ module Mongoid
5
+ module Userstamps
6
+ module User
7
+ def self.included(base)
8
+ Mongoid::Userstamps::Config.set_model(self)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Mongoid
2
+ module Userstamps
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require "mongoid-simple-userstamps/version"
2
+ require "mongoid-simple-userstamps/config"
3
+ require "mongoid-simple-userstamps/user"
4
+ require "mongoid-simple-userstamps/model"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongoid-simple-userstamps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mongoid-simple-userstamps"
8
+ spec.version = Mongoid::Userstamps::VERSION
9
+ spec.authors = ["Rafael Jurado"]
10
+ spec.email = ["rjurado@nosolosoftware.es"]
11
+ spec.summary = %q{Simple way to add user stamps to your models.}
12
+ spec.description = %q{Simple way to add user stamps to your models.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency 'rspec'
23
+ spec.add_dependency 'mongoid', "~> 5.0.0"
24
+ end
@@ -0,0 +1,7 @@
1
+ require 'mongoid'
2
+ require 'mongoid-simple-userstamps'
3
+
4
+ Mongoid.load!("spec/support/mongoid.yml", :test)
5
+
6
+ Mongoid.logger.level = Logger::ERROR
7
+ Mongo::Logger.logger.level = Logger::ERROR
@@ -0,0 +1,6 @@
1
+ test:
2
+ clients:
3
+ default:
4
+ database: userstamps_test
5
+ hosts:
6
+ - localhost:27017
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mongoid::Userstamp' do
4
+ class User
5
+ include Mongoid::Document
6
+ include Mongoid::Userstamps::User
7
+ end
8
+
9
+ class Post
10
+ include Mongoid::Document
11
+ include Mongoid::Userstamps::Model
12
+
13
+ field :title
14
+ end
15
+
16
+ before :all do
17
+ @user = User.create
18
+ Mongoid::Userstamps::Config.set_current(@user)
19
+ end
20
+
21
+ context 'when include Mongoid::Userstamps::Model' do
22
+ it 'add user stamps relations' do
23
+ post = Post.new
24
+ expect(post.created_by).to eq nil
25
+ expect(post.updated_by).to eq nil
26
+ end
27
+ end
28
+
29
+ context 'when create Post' do
30
+ it 'should save user stamps relations' do
31
+ post = Post.create
32
+ expect(post.created_by).to eq(@user)
33
+ end
34
+ end
35
+
36
+ context 'when update Post' do
37
+ it 'should save user stamps relations' do
38
+ post = Post.create
39
+ post.title = "title"
40
+ post.save
41
+ expect(post.updated_by).to eq(@user)
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-simple-userstamps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rafael Jurado
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-09 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mongoid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 5.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 5.0.0
55
+ description: Simple way to add user stamps to your models.
56
+ email:
57
+ - rjurado@nosolosoftware.es
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/mongoid-simple-userstamps.rb
68
+ - lib/mongoid-simple-userstamps/config.rb
69
+ - lib/mongoid-simple-userstamps/model.rb
70
+ - lib/mongoid-simple-userstamps/user.rb
71
+ - lib/mongoid-simple-userstamps/version.rb
72
+ - mongoid-simple-userstamps.gemspec
73
+ - spec/spec_helper.rb
74
+ - spec/support/mongoid.yml
75
+ - spec/userstamps_spec.rb
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Simple way to add user stamps to your models.
100
+ test_files:
101
+ - spec/spec_helper.rb
102
+ - spec/support/mongoid.yml
103
+ - spec/userstamps_spec.rb
104
+ has_rdoc: