mongoid_accountify 0.1.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.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'mongoid', '~> 3.0.4'
4
+
5
+ group :development do
6
+ gem 'redcarpet', '~> 2.1.0'
7
+ gem 'jeweler', '~> 1.8.3'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.2.8)
5
+ activesupport (= 3.2.8)
6
+ builder (~> 3.0.0)
7
+ activesupport (3.2.8)
8
+ i18n (~> 0.6)
9
+ multi_json (~> 1.0)
10
+ builder (3.0.0)
11
+ git (1.2.5)
12
+ i18n (0.6.1)
13
+ jeweler (1.8.4)
14
+ bundler (~> 1.0)
15
+ git (>= 1.2.5)
16
+ rake
17
+ rdoc
18
+ json (1.7.5)
19
+ mongoid (3.0.5)
20
+ activemodel (~> 3.1)
21
+ moped (~> 1.1)
22
+ origin (~> 1.0)
23
+ tzinfo (~> 0.3.22)
24
+ moped (1.2.1)
25
+ multi_json (1.3.6)
26
+ origin (1.0.8)
27
+ rake (0.9.2.2)
28
+ rdoc (3.12)
29
+ json (~> 1.4)
30
+ redcarpet (2.1.1)
31
+ tzinfo (0.3.33)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ jeweler (~> 1.8.3)
38
+ mongoid (~> 3.0.4)
39
+ redcarpet (~> 2.1.0)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Mathias Schneider
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # MongoidAccountify
2
+
3
+ MongoidAccountify adds a relation to models to a Account model and sets it on model initialization.
4
+
5
+ ## Install
6
+
7
+ ```ruby
8
+ gem 'mongoid_accountify'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ # Default config
15
+ Mongoid::Accountify.configure do |c|
16
+ c.account_reader = :current_account
17
+ c.account_model = :account
18
+ c.account_relation = :account
19
+ end
20
+
21
+ # Example model
22
+ class Person
23
+ include Mongoid::Document
24
+ include Mongoid::Accountify
25
+ end
26
+
27
+ # Build instance
28
+ p = Person.new
29
+
30
+ # Account instance
31
+ p.account
32
+ # => <Account _id: 50470dce6f51b7c68e000009>
33
+ ```
34
+
35
+ ## Credits
36
+
37
+ Copyright (c) 2012 Mathias Schneider <http://www.codecrafts.de>
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'bundler'
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts 'Run `bundle install` to install missing gems'
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake'
15
+ require 'jeweler'
16
+
17
+ $:.push File.expand_path('../lib', __FILE__)
18
+ require 'mongoid/accountify/version'
19
+
20
+ Jeweler::Tasks.new do |gem|
21
+ gem.name = 'mongoid_accountify'
22
+ gem.version = Mongoid::Accountify::Version::STRING
23
+ gem.homepage = 'https://github.com/hiasinho/mongoid_accountify'
24
+ gem.license = 'MIT'
25
+ gem.summary = %Q{Account related models within mongoid}
26
+ gem.email = 'hiasinho@me.com'
27
+ gem.authors = ['Mathias Schneider']
28
+ end
29
+
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ task :default => :version
@@ -0,0 +1,37 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Mongoid
3
+ module Accountify
4
+ extend ActiveSupport::Concern
5
+
6
+ autoload :Version, 'mongoid/accountify/version'
7
+ autoload :Railtie, 'mongoid/accountify/railtie'
8
+ autoload :Config, 'mongoid/accountify/config'
9
+ autoload :Account, 'mongoid/accountify/account'
10
+
11
+ included do
12
+
13
+ belongs_to Mongoid::Accountify.configuration.account_relation
14
+ validates_presence_of Mongoid::Accountify.configuration.account_relation
15
+
16
+ after_initialize :set_account
17
+
18
+ protected
19
+ def set_account
20
+ return unless Mongoid::Accountify.configuration.account_model.respond_to? :current
21
+ field = "#{Mongoid::Accountify.configuration.account_relation.to_s}=".to_sym
22
+
23
+ self.send(field, Mongoid::Accountify.configuration.account_model.current)
24
+ end
25
+ end
26
+
27
+ class << self
28
+ def configure(&block)
29
+ @configuration = Mongoid::Accountify::Config.new(&block)
30
+ end
31
+
32
+ def configuration
33
+ @configuration ||= Mongoid::Accountify::Config.new
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Mongoid
3
+ module Accountify
4
+ module Account
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ def current?
9
+ !Thread.current[:account].nil? && self.id == Thread.current[:account].id
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+ def current
15
+ Thread.current[:account]
16
+ end
17
+
18
+ def current=(value)
19
+ Thread.current[:account] = value
20
+ end
21
+
22
+ def do_as(account, &block)
23
+ old = self.current
24
+
25
+ begin
26
+ self.current = account
27
+ response = block.call unless block.nil?
28
+ ensure
29
+ self.current = old
30
+ end
31
+
32
+ response
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Mongoid
3
+ module Accountify
4
+ class Config
5
+ attr_accessor :account_reader
6
+ attr_accessor :account_model
7
+ attr_accessor :account_relation
8
+
9
+ def initialize(&block)
10
+ @account_reader = :current_account
11
+ @account_model = :account
12
+ @account_relation = :account
13
+
14
+ instance_eval(&block) if block_given?
15
+ end
16
+
17
+ def account_model
18
+ @account_model.to_s.classify.constantize
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Mongoid
3
+ module Accountify
4
+ class Railtie < Rails::Railtie
5
+ ActiveSupport.on_load :action_controller do
6
+ before_filter do |c|
7
+ unless Mongoid::Accountify.configuration.account_model.respond_to? :current
8
+ Mongoid::Accountify.configuration.account_model.send(
9
+ :include,
10
+ Mongoid::Accountify::Account
11
+ )
12
+ end
13
+
14
+ Mongoid::Accountify.configuration.account_model.current = c.send(Mongoid::Accountify.configuration.account_reader)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Mongoid
3
+ module Accountify
4
+ module Version
5
+ MAJOR = 0
6
+ MINOR = 1
7
+ PATCH = 1
8
+ BUILD = nil
9
+
10
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'mongoid/accountify'
3
+ require 'mongoid/accountify/railtie' if defined? Rails
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :mongoid_accountify do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "mongoid_accountify"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mathias Schneider"]
12
+ s.date = "2012-09-05"
13
+ s.email = "hiasinho@me.com"
14
+ s.extra_rdoc_files = [
15
+ "README.md"
16
+ ]
17
+ s.files = [
18
+ "Gemfile",
19
+ "Gemfile.lock",
20
+ "MIT-LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "lib/mongoid/accountify.rb",
24
+ "lib/mongoid/accountify/account.rb",
25
+ "lib/mongoid/accountify/config.rb",
26
+ "lib/mongoid/accountify/railtie.rb",
27
+ "lib/mongoid/accountify/version.rb",
28
+ "lib/mongoid_accountify.rb",
29
+ "lib/tasks/mongoid_accountify_tasks.rake",
30
+ "mongoid_accountify.gemspec"
31
+ ]
32
+ s.homepage = "https://github.com/hiasinho/mongoid_accountify"
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = "1.8.24"
36
+ s.summary = "Account related models within mongoid"
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<mongoid>, ["~> 3.0.4"])
43
+ s.add_development_dependency(%q<redcarpet>, ["~> 2.1.0"])
44
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
45
+ else
46
+ s.add_dependency(%q<mongoid>, ["~> 3.0.4"])
47
+ s.add_dependency(%q<redcarpet>, ["~> 2.1.0"])
48
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<mongoid>, ["~> 3.0.4"])
52
+ s.add_dependency(%q<redcarpet>, ["~> 2.1.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
54
+ end
55
+ end
56
+
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_accountify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mathias Schneider
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongoid
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: redcarpet
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.1.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.1.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: jeweler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.8.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.3
62
+ description:
63
+ email: hiasinho@me.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files:
67
+ - README.md
68
+ files:
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - MIT-LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - lib/mongoid/accountify.rb
75
+ - lib/mongoid/accountify/account.rb
76
+ - lib/mongoid/accountify/config.rb
77
+ - lib/mongoid/accountify/railtie.rb
78
+ - lib/mongoid/accountify/version.rb
79
+ - lib/mongoid_accountify.rb
80
+ - lib/tasks/mongoid_accountify_tasks.rake
81
+ - mongoid_accountify.gemspec
82
+ homepage: https://github.com/hiasinho/mongoid_accountify
83
+ licenses:
84
+ - MIT
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ segments:
96
+ - 0
97
+ hash: 1114773536745024269
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.24
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Account related models within mongoid
110
+ test_files: []