accountable 0.0.2
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/.document +5 -0
- data/.gitignore +22 -0
- data/History.txt +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +105 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/accountable.gemspec +70 -0
- data/lib/accountable.rb +27 -0
- data/lib/accountable/accountee.rb +21 -0
- data/lib/accountable/accountor.rb +29 -0
- data/lib/accountable/accountor/states.rb +7 -0
- data/lib/accountable/accountor/states/aasm_traits.rb +28 -0
- data/lib/accountable/accountor/states/state_machine_instance_methods.rb +13 -0
- data/lib/accountable/accountor/states/state_machine_traits.rb +29 -0
- data/lib/accountable/accountors_asset.rb +20 -0
- data/lib/accountable/active_record_extensions.rb +66 -0
- data/lib/accountable/controller_actions.rb +19 -0
- data/lib/accountable/controller_helpers.rb +8 -0
- data/lib/accountable/current_methods.rb +15 -0
- data/lib/accountable/matchers.rb +10 -0
- data/lib/accountable/matchers/acts_as_accountor_matcher.rb +16 -0
- data/lib/accountable/view_helpers.rb +8 -0
- data/spec/accountable_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +102 -0
data/.document
ADDED
data/.gitignore
ADDED
data/History.txt
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jason Harrelson (midas)
|
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.rdoc
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
= accountable
|
2
|
+
|
3
|
+
http://github.com/midas/accountable
|
4
|
+
|
5
|
+
|
6
|
+
== DESCRIPTION
|
7
|
+
|
8
|
+
An abstraction of the account / user pattern. The account owns all of the system assets and users are delegated
|
9
|
+
permissions to them.
|
10
|
+
|
11
|
+
|
12
|
+
== FEATURES
|
13
|
+
|
14
|
+
* Adds required associations.
|
15
|
+
* Adds passive, active and suspended states for managing accounts (requires AASM or State Machine gem)
|
16
|
+
* Adds associations for assets.
|
17
|
+
|
18
|
+
|
19
|
+
== COMPATABILITY:
|
20
|
+
|
21
|
+
* Ruby 1.9
|
22
|
+
* Ruby 1.8
|
23
|
+
* Rails 3
|
24
|
+
* Rails 2
|
25
|
+
|
26
|
+
== INSTALL
|
27
|
+
|
28
|
+
gem sources -a http://gemcutter.org
|
29
|
+
gem install guilded
|
30
|
+
|
31
|
+
|
32
|
+
== INSTALL FOR RAILS
|
33
|
+
|
34
|
+
Configure the Gem for use:
|
35
|
+
|
36
|
+
gem 'accountable' # Rails 3
|
37
|
+
config.gem 'accountable' # Rails 2
|
38
|
+
|
39
|
+
Install the Gem:
|
40
|
+
|
41
|
+
bundle install # Rails 3
|
42
|
+
rake gems:install # Rails 2
|
43
|
+
|
44
|
+
|
45
|
+
== USAGE
|
46
|
+
|
47
|
+
=== SIMPLEST CASE
|
48
|
+
|
49
|
+
class Account < ActiveRecord::Base
|
50
|
+
acts_as_accountor
|
51
|
+
end
|
52
|
+
|
53
|
+
class User < ActiveRecord::Base
|
54
|
+
acts_as_accountee
|
55
|
+
end
|
56
|
+
|
57
|
+
class Thing
|
58
|
+
acts_as_accountors_asset
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
=== COMPLEX CASE
|
63
|
+
|
64
|
+
class Group < ActiveRecord::Base
|
65
|
+
acts_as_accountor :of => :members, :with_state => :state_machine, :assets => %w(things)
|
66
|
+
end
|
67
|
+
|
68
|
+
class Member < ActiveRecord::Base
|
69
|
+
acts_as_accountee :of => :group
|
70
|
+
end
|
71
|
+
|
72
|
+
class Thing
|
73
|
+
acts_as_accountors_asset
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
== OPTIONS
|
78
|
+
|
79
|
+
=== acts_as_accountor
|
80
|
+
|
81
|
+
:of::
|
82
|
+
|
83
|
+
|
84
|
+
== LICENSE
|
85
|
+
|
86
|
+
Copyright (c) 2009 Jason Harrelson (midas)
|
87
|
+
|
88
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
89
|
+
a copy of this software and associated documentation files (the
|
90
|
+
"Software"), to deal in the Software without restriction, including
|
91
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
92
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
93
|
+
permit persons to whom the Software is furnished to do so, subject to
|
94
|
+
the following conditions:
|
95
|
+
|
96
|
+
The above copyright notice and this permission notice shall be
|
97
|
+
included in all copies or substantial portions of the Software.
|
98
|
+
|
99
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
100
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
101
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
102
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
103
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
104
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
105
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "accountable"
|
8
|
+
gem.summary = %Q{An abstraction of the account / user pattern.}
|
9
|
+
gem.description = %Q{An abstraction of the account / user pattern. The account owns all of the system assets and users are delegated permissions to them.}
|
10
|
+
gem.email = "jason@lookforwardenterprises.com"
|
11
|
+
gem.homepage = "http://github.com/midas/accountable"
|
12
|
+
gem.authors = ["Jason Harrelson"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "accountable #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/accountable.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{accountable}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jason Harrelson"]
|
12
|
+
s.date = %q{2010-05-10}
|
13
|
+
s.description = %q{An abstraction of the account / user pattern. The account owns all of the system assets and users are delegated permissions to them.}
|
14
|
+
s.email = %q{jason@lookforwardenterprises.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"History.txt",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"accountable.gemspec",
|
28
|
+
"lib/accountable.rb",
|
29
|
+
"lib/accountable/accountee.rb",
|
30
|
+
"lib/accountable/accountor.rb",
|
31
|
+
"lib/accountable/accountor/states.rb",
|
32
|
+
"lib/accountable/accountor/states/aasm_traits.rb",
|
33
|
+
"lib/accountable/accountor/states/state_machine_instance_methods.rb",
|
34
|
+
"lib/accountable/accountor/states/state_machine_traits.rb",
|
35
|
+
"lib/accountable/accountors_asset.rb",
|
36
|
+
"lib/accountable/active_record_extensions.rb",
|
37
|
+
"lib/accountable/controller_actions.rb",
|
38
|
+
"lib/accountable/controller_helpers.rb",
|
39
|
+
"lib/accountable/current_methods.rb",
|
40
|
+
"lib/accountable/matchers.rb",
|
41
|
+
"lib/accountable/matchers/acts_as_accountor_matcher.rb",
|
42
|
+
"lib/accountable/view_helpers.rb",
|
43
|
+
"spec/accountable_spec.rb",
|
44
|
+
"spec/spec.opts",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
s.homepage = %q{http://github.com/midas/accountable}
|
48
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
49
|
+
s.require_paths = ["lib"]
|
50
|
+
s.rubygems_version = %q{1.3.6}
|
51
|
+
s.summary = %q{An abstraction of the account / user pattern.}
|
52
|
+
s.test_files = [
|
53
|
+
"spec/accountable_spec.rb",
|
54
|
+
"spec/spec_helper.rb"
|
55
|
+
]
|
56
|
+
|
57
|
+
if s.respond_to? :specification_version then
|
58
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
59
|
+
s.specification_version = 3
|
60
|
+
|
61
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
62
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
data/lib/accountable.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'accountable/active_record_extensions'
|
5
|
+
|
6
|
+
module Accountable
|
7
|
+
VERSION = File.exist?(File.expand_path( '../VERSION', __FILE__ )) ?
|
8
|
+
File.readlines( File.expand_path( '../VERSION', __FILE__ ) ).first :
|
9
|
+
""
|
10
|
+
|
11
|
+
autoload :Accountee, 'accountable/accountee'
|
12
|
+
autoload :Accountor, 'accountable/accountor'
|
13
|
+
autoload :AccountorsAsset, 'accountable/accountors_asset'
|
14
|
+
autoload :ControllerActions, 'accountable/controller_actions'
|
15
|
+
autoload :ControllerHelpers, 'accountable/controller_helpers'
|
16
|
+
autoload :CurrentMethods, 'accountable/current_methods'
|
17
|
+
autoload :ViewHelpers, 'accountable/view_helpers'
|
18
|
+
end
|
19
|
+
|
20
|
+
ActiveRecord::Base.send( :include, Accountable::ActiveRecordExtensions ) if defined? ActiveRecord::Base
|
21
|
+
if defined?( ActionView::Base )
|
22
|
+
ActionView::Base.send( :include, Accountable::ViewHelpers ) unless ActionView::Base.include? Accountable::ViewHelpers
|
23
|
+
end
|
24
|
+
if defined?( ActionController::Base )
|
25
|
+
ActionController::Base.send( :include, Accountable::ControllerHelpers ) unless ActionController::Base.include? Accountable::ControllerHelpers
|
26
|
+
ActionController::Base.send( :include, Accountable::ControllerActions ) unless ActionController::Base.include? Accountable::ControllerActions
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Accountable
|
2
|
+
module Accountee
|
3
|
+
def self.included( base )
|
4
|
+
unless included_modules.include? InstanceMethods
|
5
|
+
base.extend ClassMethods
|
6
|
+
base.extend CurrentMethods
|
7
|
+
base.class_eval { include InstanceMethods }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def accountee_options
|
13
|
+
@accountee_options ||= { :of => :account }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module InstanceMethods
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Accountable
|
2
|
+
module Accountor
|
3
|
+
autoload :States, 'accountable/accountor/states'
|
4
|
+
|
5
|
+
def self.included( base )
|
6
|
+
unless included_modules.include? InstanceMethods
|
7
|
+
base.extend ClassMethods
|
8
|
+
base.extend CurrentMethods
|
9
|
+
base.class_eval { include InstanceMethods }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def accountor_options
|
15
|
+
@accountor_options ||= {
|
16
|
+
:of => :users,
|
17
|
+
:name => :name,
|
18
|
+
:with_state => false,
|
19
|
+
:dependent => :nullify,
|
20
|
+
:assets => []
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module InstanceMethods
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
module Accountable::Accountor
|
2
|
+
module States
|
3
|
+
autoload :AasmTraits, 'accountable/accountor/states/aasm_traits'
|
4
|
+
autoload :StateMachineInstanceMethods, 'accountable/accountor/states/state_machine_instance_methods'
|
5
|
+
autoload :StateMachineTraits, 'accountable/accountor/states/state_machine_traits'
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Accountable::Accountor::States
|
2
|
+
module AasmTraits
|
3
|
+
|
4
|
+
def self.included( base )
|
5
|
+
base.class_eval do
|
6
|
+
include AASM
|
7
|
+
include StateMachineInstanceMethods
|
8
|
+
|
9
|
+
aasm_column :status
|
10
|
+
aasm_initial_state :passive
|
11
|
+
aasm_state :passive
|
12
|
+
aasm_state :active, :enter => :do_activate
|
13
|
+
aasm_state :suspended, :enter => :do_suspend
|
14
|
+
|
15
|
+
aasm_event :activate do
|
16
|
+
transitions :from => :passive, :to => :active
|
17
|
+
end
|
18
|
+
aasm_event :suspend do
|
19
|
+
transitions :from => [:passive, :active], :to => :suspended
|
20
|
+
end
|
21
|
+
aasm_event :unsuspend do
|
22
|
+
transitions :from => :suspended, :to => :active
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Accountable::Accountor::States
|
2
|
+
module StateMachineInstanceMethods
|
3
|
+
protected
|
4
|
+
|
5
|
+
def do_activate
|
6
|
+
self.activated_at = Time.now.utc if self.respond_to? :activated_at
|
7
|
+
end
|
8
|
+
|
9
|
+
def do_suspend
|
10
|
+
self.suspended_at = Time.now.utc if self.respond_to? :suspended_at
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Accountable::Accountor::States
|
2
|
+
module StateMachineTraits
|
3
|
+
|
4
|
+
def self.included( base )
|
5
|
+
base.class_eval do
|
6
|
+
include StateMachineInstanceMethods
|
7
|
+
|
8
|
+
state_machine :status, :initial => :passive do
|
9
|
+
state :passive, :active, :suspended
|
10
|
+
|
11
|
+
event :activate do
|
12
|
+
transition [:passive] => :active
|
13
|
+
end
|
14
|
+
after_transition :on => :active, :do => :do_activate
|
15
|
+
|
16
|
+
event :suspend do
|
17
|
+
transition [:passive, :active] => :suspended
|
18
|
+
end
|
19
|
+
after_transition :on => :active, :do => :do_suspend
|
20
|
+
|
21
|
+
event :unsuspend do
|
22
|
+
transition [:suspended] => :active
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Accountable
|
2
|
+
module AccountorsAsset
|
3
|
+
def self.included( base )
|
4
|
+
unless included_modules.include? InstanceMethods
|
5
|
+
base.extend ClassMethods
|
6
|
+
base.class_eval { include InstanceMethods }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def accountors_asset_options
|
12
|
+
@accountors_asset_options ||= { :of => :account }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Accountable
|
2
|
+
module ActiveRecordExtensions
|
3
|
+
|
4
|
+
def self.included( base )
|
5
|
+
base.extend( ActsMethods ) unless base.included_modules.include? ActsMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ActsMethods
|
9
|
+
# Placed in the model desired to be the accountor (usually Account).
|
10
|
+
#
|
11
|
+
def acts_as_accountor( *args )
|
12
|
+
unless included_modules.include? Accountable::Accountor
|
13
|
+
include Accountable::Accountor
|
14
|
+
options = args.extract_options!
|
15
|
+
self.accountor_options.merge!( options.reject { |k,v| v.blank? } )
|
16
|
+
|
17
|
+
self.class_eval do
|
18
|
+
has_many self.accountor_options[:of], :dependent => accountor_options[:dependent]
|
19
|
+
unless accountor_options[:name] == false
|
20
|
+
validates_presence_of accountor_options[:name].to_sym
|
21
|
+
validates_length_of accountor_options[:name].to_sym, :maximum => 150,
|
22
|
+
:allow_nil => true, :allow_blank => true
|
23
|
+
attr_accessible accountor_options[:name].to_sym
|
24
|
+
end
|
25
|
+
assets = self.accountor_options[:assets].is_a?( Array ) ?
|
26
|
+
self.accountor_options[:assets] :
|
27
|
+
[self.accountor_options[:assets]]
|
28
|
+
assets.each { |asset| has_many asset.to_sym, :dependent => accountor_options[:dependent] }
|
29
|
+
include Accountor::States::StateMachineInstanceMethods unless accountor_options[:with_state] == false
|
30
|
+
include Accountor::States::AasmTraits if accountor_options[:with_state] == :aasm
|
31
|
+
include Accountor::States::StateMachineTraits if accountor_options[:with_state] == :state_machine
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Placed in the model desired to be the accountee (usually User).
|
37
|
+
#
|
38
|
+
def acts_as_accountee( *args )
|
39
|
+
unless included_modules.include? Accountable::Accountee
|
40
|
+
include Accountable::Accountee
|
41
|
+
options = args.extract_options!
|
42
|
+
self.accountee_options.merge!( options.reject { |k,v| v.blank? } )
|
43
|
+
|
44
|
+
self.class_eval do
|
45
|
+
belongs_to self.accountee_options[:of].to_sym
|
46
|
+
validates_presence_of self.accountee_options[:of].to_sym
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Placed in the model(s) desired to be owned by the accountor.
|
52
|
+
#
|
53
|
+
def acts_as_accountors_asset( *args )
|
54
|
+
unless included_modules.include? Accountable::AccountorsAsset
|
55
|
+
include Accountable::AccountorsAsset
|
56
|
+
|
57
|
+
self.class_eval do
|
58
|
+
belongs_to self.accountors_asset_options[:of]
|
59
|
+
validates_presence_of self.accountors_asset_options[:of]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Accountable
|
2
|
+
module ControllerActions
|
3
|
+
def self.included( base )
|
4
|
+
base.instance_eval do
|
5
|
+
before_filter :set_currents
|
6
|
+
end
|
7
|
+
base.send( :include, InstanceMethods )
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
protected
|
12
|
+
|
13
|
+
def set_currents
|
14
|
+
User.current = current_user
|
15
|
+
Account.current = current_account
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Accountable
|
2
|
+
module CurrentMethods
|
3
|
+
def current
|
4
|
+
Thread.current[self.class.name.tableize.singularize.to_sym]
|
5
|
+
end
|
6
|
+
|
7
|
+
def current=( something )
|
8
|
+
unless something.nil? || something.is_a?( self )
|
9
|
+
raise( ArgumentError,
|
10
|
+
"Exception occurred while trying to set #{self.name}.current. Expected an object of type '#{self.name}', got an object of type ''#{something.class.name}'")
|
11
|
+
end
|
12
|
+
Thread.current[self.class.name.tableize.singularize.to_sym] = something
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Accountable::Matchers
|
2
|
+
# class ActsAsAccountorMatcher < Remarkable::ActiveRecord::Base
|
3
|
+
# arguments :instance
|
4
|
+
# assertion :is_applied?
|
5
|
+
#
|
6
|
+
# protected
|
7
|
+
#
|
8
|
+
# def is_applied?
|
9
|
+
#
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# def act_as_accountor( *args )
|
14
|
+
# ActsAsAccountorMatcher.new( *args ).spec( self )
|
15
|
+
# end
|
16
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: accountable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jason Harrelson
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-10 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
31
|
+
version: 1.2.9
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: An abstraction of the account / user pattern. The account owns all of the system assets and users are delegated permissions to them.
|
35
|
+
email: jason@lookforwardenterprises.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- LICENSE
|
42
|
+
- README.rdoc
|
43
|
+
files:
|
44
|
+
- .document
|
45
|
+
- .gitignore
|
46
|
+
- History.txt
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- accountable.gemspec
|
52
|
+
- lib/accountable.rb
|
53
|
+
- lib/accountable/accountee.rb
|
54
|
+
- lib/accountable/accountor.rb
|
55
|
+
- lib/accountable/accountor/states.rb
|
56
|
+
- lib/accountable/accountor/states/aasm_traits.rb
|
57
|
+
- lib/accountable/accountor/states/state_machine_instance_methods.rb
|
58
|
+
- lib/accountable/accountor/states/state_machine_traits.rb
|
59
|
+
- lib/accountable/accountors_asset.rb
|
60
|
+
- lib/accountable/active_record_extensions.rb
|
61
|
+
- lib/accountable/controller_actions.rb
|
62
|
+
- lib/accountable/controller_helpers.rb
|
63
|
+
- lib/accountable/current_methods.rb
|
64
|
+
- lib/accountable/matchers.rb
|
65
|
+
- lib/accountable/matchers/acts_as_accountor_matcher.rb
|
66
|
+
- lib/accountable/view_helpers.rb
|
67
|
+
- spec/accountable_spec.rb
|
68
|
+
- spec/spec.opts
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: http://github.com/midas/accountable
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options:
|
76
|
+
- --charset=UTF-8
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.3.6
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: An abstraction of the account / user pattern.
|
100
|
+
test_files:
|
101
|
+
- spec/accountable_spec.rb
|
102
|
+
- spec/spec_helper.rb
|