private_person 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +15 -0
  2. data/.document +5 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +21 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +18 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/lib/generators/private_person/install/install_generator.rb +31 -0
  10. data/lib/generators/private_person/install/templates/migrate/create_permissions_table.rb +18 -0
  11. data/lib/generators/private_person/utils.rb +16 -0
  12. data/lib/private_person/models/permissible.rb +16 -0
  13. data/lib/private_person/models/permission.rb +58 -0
  14. data/lib/private_person/models/permissor.rb +17 -0
  15. data/lib/private_person/models/permitted.rb +44 -0
  16. data/lib/private_person/version.rb +7 -0
  17. data/lib/private_person.rb +14 -0
  18. data/private_person.gemspec +127 -0
  19. data/script/rails +6 -0
  20. data/spec/dummy/.rspec +1 -0
  21. data/spec/dummy/Rakefile +7 -0
  22. data/spec/dummy/app/models/follow.rb +14 -0
  23. data/spec/dummy/app/models/page.rb +4 -0
  24. data/spec/dummy/app/models/user.rb +30 -0
  25. data/spec/dummy/config/application.rb +56 -0
  26. data/spec/dummy/config/boot.rb +10 -0
  27. data/spec/dummy/config/database.yml +25 -0
  28. data/spec/dummy/config/environment.rb +5 -0
  29. data/spec/dummy/config/environments/development.rb +27 -0
  30. data/spec/dummy/config/environments/production.rb +58 -0
  31. data/spec/dummy/config/environments/test.rb +25 -0
  32. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  33. data/spec/dummy/config/initializers/inflections.rb +15 -0
  34. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  35. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  36. data/spec/dummy/config/initializers/session_store.rb +8 -0
  37. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  38. data/spec/dummy/config/locales/devise.en.yml +59 -0
  39. data/spec/dummy/config/locales/en.yml +5 -0
  40. data/spec/dummy/config/routes.rb +59 -0
  41. data/spec/dummy/config.ru +4 -0
  42. data/spec/dummy/db/development.sqlite3 +0 -0
  43. data/spec/dummy/db/migrate/20130906211525_create_permissions_table.rb +18 -0
  44. data/spec/dummy/db/migrate/20130906213557_create_users_table.rb +13 -0
  45. data/spec/dummy/db/migrate/20130906213612_create_pages_table.rb +15 -0
  46. data/spec/dummy/db/migrate/20130907010108_acts_as_follower_migration.rb +17 -0
  47. data/spec/dummy/db/schema.rb +56 -0
  48. data/spec/dummy/db/test.sqlite3 +0 -0
  49. data/spec/dummy/script/rails +6 -0
  50. data/spec/factories/pages.rb +7 -0
  51. data/spec/factories/permissions.rb +7 -0
  52. data/spec/factories/users.rb +5 -0
  53. data/spec/models/page_spec.rb +6 -0
  54. data/spec/models/permission_spec.rb +88 -0
  55. data/spec/models/user_spec.rb +101 -0
  56. data/spec/private_person_spec.rb +7 -0
  57. data/spec/spec_helper.rb +36 -0
  58. data/spec/support/permissions_support.rb +24 -0
  59. data/spec/support/users_support.rb +21 -0
  60. metadata +259 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDk2ZjIyOTkxZWY4MjI5YzVjYWMxMjRlNGYwYzQyYjA4MGMyNjM0YQ==
5
+ data.tar.gz: !binary |-
6
+ ODc4N2VmY2I2ZTg1MDAyM2RjNjkyOTgyZmNjYzUxNGViNWI5ZjJjMg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NGI5NDAzMTE0MjY2MTEzMTFlM2JhNDZhNjJiNmY1OGE2N2QyNzViZjMxZDQz
10
+ MGI2OGJiZWU4ZjYwOTE5NzE2ODdiMzNlMzU4NTNiYjZmYjc0NjAzNmUyMzA5
11
+ NjRmYTM5NGZmMjMxYmQzMzIwOGNlNmMwMjllMzg3ZDY5YjgxNmI=
12
+ data.tar.gz: !binary |-
13
+ OTMxNDAzZjNmNGRlNjY1ODQxMTQxNmIwNTAyNDhkNzViZTQ5NmU2YmMzMDkw
14
+ NTUyZGZhZTk1YWY5YzUyNzdjYzJiYWI1NzdkOWU3N2RmZGFhNTg4N2NmOWE3
15
+ MzYyMmJhMmVlYWM1Nzc3YzQ5MDhjOWFjZDc2YWFkZWZhY2MxMWE=
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source 'http://rubygems.org'
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem 'activesupport', '>= 2.3.5'
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development, :test do
9
+ gem 'rdoc'
10
+ gem 'bundler'
11
+ gem 'jeweler'
12
+ gem 'sqlite3'
13
+ gem 'rspec'
14
+ gem 'rspec-rails'
15
+ gem 'shoulda-matchers'
16
+ gem 'factory_girl_rails'
17
+ gem 'database_cleaner'
18
+ gem 'acts_as_follower'
19
+ end
20
+
21
+ gem 'rails'
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Sour Cherry Web
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,18 @@
1
+ = PrivatePerson
2
+
3
+ Private person is an active record extension gem that allows a model to be given privacy settings over arbitrary models and polymorphic relations, putting users' accounts in control of their own privacy policies.
4
+
5
+ == Contributing to Person
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Sour Cherry Web. See LICENSE.txt for further details.
18
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "private_person"
18
+ gem.homepage = "http://github.com/nerakdon/private_person"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Private person puts your users in control of their own privacy policies.}
21
+ gem.description = %Q{Private person is an active record extension gem that allows a model to be given privacy settings over arbitrary models and polymorphic relations, putting users' accounts in control of their own privacy policies.}
22
+ gem.email = "webmaster@sourcherryweb.com"
23
+ gem.authors = ["Karen Lundgren"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = false
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "private_person #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,31 @@
1
+ module PrivatePerson
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("../templates", __FILE__)
4
+ require File.expand_path('../../utils', __FILE__)
5
+ include Generators::Utils
6
+ include Rails::Generators::Migration
7
+
8
+ def hello
9
+ output "With PrivatePerson, you can put your users in control of their own privacy policies.", :magenta
10
+ end
11
+
12
+ def add_migrations
13
+ unless ActiveRecord::Base.connection.table_exists? 'permissions'
14
+ migration_template 'migrate/create_permissions_table.rb', 'db/migrate/create_permissions_table.rb' rescue output $!.message
15
+ end
16
+ end
17
+
18
+ def self.next_migration_number(dirname)
19
+ if ActiveRecord::Base.timestamped_migrations
20
+ unless @prev_migration_nr
21
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
22
+ else
23
+ @prev_migration_nr += 1
24
+ end
25
+ @prev_migration_nr.to_s
26
+ else
27
+ "%.3d" % (current_migration_number(dirname) + 1)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ class CreatePermissionsTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :permissions do |t|
4
+ t.string :permissor_type
5
+ t.integer :permissor_id
6
+ t.string :permissible_type
7
+ t.integer :permissible_id
8
+ t.string :relationship_type, :default => 'none'
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :permissions, [:permissor_type, :permissor_id]
13
+ add_index :permissions, [:permissible_type, :permissible_id]
14
+ end
15
+ def self.down
16
+ drop_table :permissions
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module PrivatePerson
2
+ module Generators
3
+ module Utils
4
+ def output(output, color = :green)
5
+ say(" - #{output}", color)
6
+ end
7
+
8
+ def ask_for(wording, default_value = nil, override_if_present_value = nil)
9
+ override_if_present_value.present? ?
10
+ display("Using [#{override_if_present_value}] for question '#{wording}'") && override_if_present_value :
11
+ ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ module PrivatePerson
2
+ module Permissible
3
+ def acts_as_permissible(params = {})
4
+ if params[:by].nil?
5
+ raise 'Called acts_as_permissible, but without a :by parameter.'
6
+ end
7
+ class_attribute :by
8
+ self.by = params[:by]
9
+
10
+ class_eval do
11
+ has_many :permissions, :as => :permissible
12
+ has_many :permissors, :through => :permissions, :as => :permissor
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,58 @@
1
+ class Permission < ActiveRecord::Base
2
+ belongs_to :permissor, :polymorphic => true
3
+ belongs_to :permissible, :polymorphic => true
4
+
5
+ attr_accessible :permissible, :permissible_type, :permissible_id, :relationship_type
6
+ validates_presence_of :permissor, :permissible_type, :relationship_type
7
+
8
+ def self.find_all_by_permissor(permissor)
9
+ where("permissor_type = ? AND permissor_id = ?", permissor.class.name, permissor.id)
10
+ end
11
+
12
+ def self.find_all_by_permissible(permissible)
13
+ where("permissible_type = ? AND permissible_id = ?", permissible.class.name, permissible.id)
14
+ end
15
+
16
+ def self.find_all_by_wildcard(permissible_type)
17
+ where(:permissible_type => permissible_type, :permissible_id => nil)
18
+ end
19
+
20
+ def self.find_all_by_relationship_type(relationship_type)
21
+ if relationship_type == 'public'
22
+ return where("relationship_type = 'public'")
23
+ end
24
+ if(self.permissible_types.include? relationship_type)
25
+ return where("relationship_type = ? OR relationship_type = 'public'", relationship_type)
26
+ end
27
+ return where(0)
28
+ end
29
+
30
+ def self.blocked
31
+ where('NOT(relationship_type IN (?))', self.permissible_types)
32
+ end
33
+
34
+ def self.legitimate
35
+ where('relationship_type IN (?)', self.permissible_types)
36
+ end
37
+
38
+ def self.permissible_types
39
+ permissible_types = ['public']
40
+ for record in self.group('permissor_type').group('permissor_id')
41
+ permissor = record.permissor_type.constantize.find(record.permissor_id)
42
+ unless permissor.nil?
43
+ for method in permissor.class.of
44
+ permissible_types << method.to_s
45
+ end
46
+ end
47
+ end
48
+ permissible_types.compact
49
+ end
50
+
51
+ def existing_types
52
+ existing_types = ['public']
53
+ for method in permissor.class.of
54
+ existing_types << method.to_s
55
+ end
56
+ existing_types
57
+ end
58
+ end
@@ -0,0 +1,17 @@
1
+ module PrivatePerson
2
+ module Permissor
3
+ def acts_as_permissor(params = {})
4
+ if params[:of].nil?
5
+ raise 'Called acts_as_permissor, but without an :of parameter.'
6
+ end
7
+ class_attribute :of
8
+ self.of = params[:of]
9
+ class_name = params[:class_name] || params[:of].to_s.classify
10
+ class_name.constantize.acts_as_permitted
11
+ class_eval do
12
+ has_many :permissions, :as => :permissor
13
+ has_many :permissibles, :through => :permissions, :as => :permissible
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ module PrivatePerson
2
+ module Permitted
3
+ def acts_as_permitted
4
+ class_eval do
5
+ def is_permitted?(permissor, permissible)
6
+ if Permission.find_all_by_permissible(permissible).blocked.exists?
7
+ return false
8
+ end
9
+ wildcards = permissions_by(permissor).find_all_by_wildcard(permissible.class.name).legitimate
10
+ if wildcards.exists?
11
+ return true
12
+ end
13
+ permissions = permissions_by(permissor).find_all_by_permissible(permissible).legitimate
14
+ if permissions.exists?
15
+ return true
16
+ end
17
+ return false
18
+ end
19
+
20
+ def permissions_by(permissor)
21
+ Permission.find_all_by_permissor(permissor).find_all_by_relationship_type(relationship_to(permissor))
22
+ end
23
+
24
+ def relationship_to(permissor)
25
+ # First check for an efficient method
26
+ for relationship_method in permissor.class.of
27
+ is_method = ('is_' + relationship_method.to_s.singularize + '_of?').to_sym
28
+ if respond_to?(is_method) and self.send(is_method, permissor)
29
+ return relationship_method.to_s
30
+ end
31
+ end
32
+ # Then check for a slow method
33
+ for relationship_method in permissor.class.of
34
+ relationship_members = permissor.send(relationship_method.to_sym)
35
+ if relationship_members.exists?(:id => self.id)
36
+ return relationship_method.to_s
37
+ end
38
+ end
39
+ return nil
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ module PrivatePerson
2
+ VERSION = File.read(File.expand_path('../../../VERSION', __FILE__))
3
+
4
+ def self.version_string
5
+ "PrivatePerson version #{PrivatePerson::VERSION}"
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ module PrivatePerson
2
+ require 'rails'
3
+ require 'private_person/version'
4
+ require 'private_person/models/permissor'
5
+ require 'private_person/models/permission'
6
+ require 'private_person/models/permissible'
7
+ require 'private_person/models/permitted'
8
+ end
9
+
10
+ if defined?(ActiveRecord::Base)
11
+ ActiveRecord::Base.extend PrivatePerson::Permitted
12
+ ActiveRecord::Base.extend PrivatePerson::Permissor
13
+ ActiveRecord::Base.extend PrivatePerson::Permissible
14
+ end
@@ -0,0 +1,127 @@
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 = "private_person"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Karen Lundgren"]
12
+ s.date = "2013-09-07"
13
+ s.description = "Private person is an active record extension gem that allows a model to be given privacy settings over arbitrary models and polymorphic relations, putting users' accounts in control of their own privacy policies."
14
+ s.email = "webmaster@sourcherryweb.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/generators/private_person/install/install_generator.rb",
28
+ "lib/generators/private_person/install/templates/migrate/create_permissions_table.rb",
29
+ "lib/generators/private_person/utils.rb",
30
+ "lib/private_person.rb",
31
+ "lib/private_person/models/permissible.rb",
32
+ "lib/private_person/models/permission.rb",
33
+ "lib/private_person/models/permissor.rb",
34
+ "lib/private_person/models/permitted.rb",
35
+ "lib/private_person/version.rb",
36
+ "private_person.gemspec",
37
+ "script/rails",
38
+ "spec/dummy/.rspec",
39
+ "spec/dummy/Rakefile",
40
+ "spec/dummy/app/models/follow.rb",
41
+ "spec/dummy/app/models/page.rb",
42
+ "spec/dummy/app/models/user.rb",
43
+ "spec/dummy/config.ru",
44
+ "spec/dummy/config/application.rb",
45
+ "spec/dummy/config/boot.rb",
46
+ "spec/dummy/config/database.yml",
47
+ "spec/dummy/config/environment.rb",
48
+ "spec/dummy/config/environments/development.rb",
49
+ "spec/dummy/config/environments/production.rb",
50
+ "spec/dummy/config/environments/test.rb",
51
+ "spec/dummy/config/initializers/backtrace_silencers.rb",
52
+ "spec/dummy/config/initializers/inflections.rb",
53
+ "spec/dummy/config/initializers/mime_types.rb",
54
+ "spec/dummy/config/initializers/secret_token.rb",
55
+ "spec/dummy/config/initializers/session_store.rb",
56
+ "spec/dummy/config/initializers/wrap_parameters.rb",
57
+ "spec/dummy/config/locales/devise.en.yml",
58
+ "spec/dummy/config/locales/en.yml",
59
+ "spec/dummy/config/routes.rb",
60
+ "spec/dummy/db/development.sqlite3",
61
+ "spec/dummy/db/migrate/20130906211525_create_permissions_table.rb",
62
+ "spec/dummy/db/migrate/20130906213557_create_users_table.rb",
63
+ "spec/dummy/db/migrate/20130906213612_create_pages_table.rb",
64
+ "spec/dummy/db/migrate/20130907010108_acts_as_follower_migration.rb",
65
+ "spec/dummy/db/schema.rb",
66
+ "spec/dummy/db/test.sqlite3",
67
+ "spec/dummy/script/rails",
68
+ "spec/factories/pages.rb",
69
+ "spec/factories/permissions.rb",
70
+ "spec/factories/users.rb",
71
+ "spec/models/page_spec.rb",
72
+ "spec/models/permission_spec.rb",
73
+ "spec/models/user_spec.rb",
74
+ "spec/private_person_spec.rb",
75
+ "spec/spec_helper.rb",
76
+ "spec/support/permissions_support.rb",
77
+ "spec/support/users_support.rb"
78
+ ]
79
+ s.homepage = "http://github.com/nerakdon/private_person"
80
+ s.licenses = ["MIT"]
81
+ s.require_paths = ["lib"]
82
+ s.rubygems_version = "2.0.7"
83
+ s.summary = "Private person puts your users in control of their own privacy policies."
84
+
85
+ if s.respond_to? :specification_version then
86
+ s.specification_version = 4
87
+
88
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
89
+ s.add_runtime_dependency(%q<rails>, [">= 0"])
90
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
91
+ s.add_development_dependency(%q<bundler>, [">= 0"])
92
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
93
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
94
+ s.add_development_dependency(%q<rspec>, [">= 0"])
95
+ s.add_development_dependency(%q<rspec-rails>, [">= 0"])
96
+ s.add_development_dependency(%q<shoulda-matchers>, [">= 0"])
97
+ s.add_development_dependency(%q<factory_girl_rails>, [">= 0"])
98
+ s.add_development_dependency(%q<database_cleaner>, [">= 0"])
99
+ s.add_development_dependency(%q<acts_as_follower>, [">= 0"])
100
+ else
101
+ s.add_dependency(%q<rails>, [">= 0"])
102
+ s.add_dependency(%q<rdoc>, [">= 0"])
103
+ s.add_dependency(%q<bundler>, [">= 0"])
104
+ s.add_dependency(%q<jeweler>, [">= 0"])
105
+ s.add_dependency(%q<sqlite3>, [">= 0"])
106
+ s.add_dependency(%q<rspec>, [">= 0"])
107
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
108
+ s.add_dependency(%q<shoulda-matchers>, [">= 0"])
109
+ s.add_dependency(%q<factory_girl_rails>, [">= 0"])
110
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
111
+ s.add_dependency(%q<acts_as_follower>, [">= 0"])
112
+ end
113
+ else
114
+ s.add_dependency(%q<rails>, [">= 0"])
115
+ s.add_dependency(%q<rdoc>, [">= 0"])
116
+ s.add_dependency(%q<bundler>, [">= 0"])
117
+ s.add_dependency(%q<jeweler>, [">= 0"])
118
+ s.add_dependency(%q<sqlite3>, [">= 0"])
119
+ s.add_dependency(%q<rspec>, [">= 0"])
120
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
121
+ s.add_dependency(%q<shoulda-matchers>, [">= 0"])
122
+ s.add_dependency(%q<factory_girl_rails>, [">= 0"])
123
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
124
+ s.add_dependency(%q<acts_as_follower>, [">= 0"])
125
+ end
126
+ end
127
+
data/script/rails ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby1.8
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../spec/dummy/config/application', __FILE__)
5
+ require File.expand_path('../../spec/dummy/config/boot', __FILE__)
6
+ require 'rails/commands'
data/spec/dummy/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,14 @@
1
+ class Follow < ActiveRecord::Base
2
+
3
+ extend ActsAsFollower::FollowerLib
4
+ extend ActsAsFollower::FollowScopes
5
+
6
+ # NOTE: Follows belong to the "followable" interface, and also to followers
7
+ belongs_to :followable, :polymorphic => true
8
+ belongs_to :follower, :polymorphic => true
9
+
10
+ def block!
11
+ self.update_attribute(:blocked, true)
12
+ end
13
+
14
+ end
@@ -0,0 +1,4 @@
1
+ class Page < ActiveRecord::Base
2
+ acts_as_permissible :by => :user
3
+ belongs_to :user
4
+ end
@@ -0,0 +1,30 @@
1
+ class User < ActiveRecord::Base
2
+ acts_as_follower
3
+ acts_as_followable
4
+
5
+ acts_as_permissor :of => [:following_users, :user_followers, :following_of_followings, :follower_of_followers], :class_name => 'User'
6
+
7
+ def following_of_followings
8
+ ids = []
9
+ for user in following_users
10
+ ids |= user.following_users
11
+ end
12
+ User.where(:id => ids)
13
+ end
14
+
15
+ def follower_of_followers
16
+ ids = []
17
+ for user in user_followers
18
+ ids |= user.user_followers
19
+ end
20
+ User.where(:id => ids)
21
+ end
22
+
23
+ def is_following_user_of?(item)
24
+ self.followed_by?(item)
25
+ end
26
+
27
+ def is_user_follower_of?(item)
28
+ item.followed_by?(self)
29
+ end
30
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ # require "rails/test_unit/railtie"
6
+
7
+ Bundler.require
8
+ require "private_person"
9
+ require 'acts_as_follower'
10
+
11
+ module Dummy
12
+ class Application < Rails::Application
13
+ # Settings in config/environments/* take precedence over those specified here.
14
+ # Application configuration should go into files in config/initializers
15
+ # -- all .rb files in that directory are automatically loaded.
16
+
17
+ # Custom directories with classes and modules you want to be autoloadable.
18
+ # config.autoload_paths += %W(#{config.root}/extras)
19
+
20
+ # Only load the plugins named here, in the order given (default is alphabetical).
21
+ # :all can be used as a placeholder for all plugins not explicitly named.
22
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
23
+
24
+ # Activate observers that should always be running.
25
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
26
+
27
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
28
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
29
+ # config.time_zone = 'Central Time (US & Canada)'
30
+
31
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
32
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
33
+ # config.i18n.default_locale = :de
34
+
35
+ # Configure the default encoding used in templates for Ruby 1.9.
36
+ config.encoding = "utf-8"
37
+
38
+ # Configure sensitive parameters which will be filtered from the log file.
39
+ config.filter_parameters += [:password]
40
+
41
+ # Enable escaping HTML in JSON.
42
+ config.active_support.escape_html_entities_in_json = true
43
+
44
+ # Use SQL instead of Active Record's schema dumper when creating the database.
45
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
46
+ # like if you have constraints or database-specific column types
47
+ # config.active_record.schema_format = :sql
48
+
49
+ # Enforce whitelist mode for mass assignment.
50
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
51
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
52
+ # parameters by using an attr_accessible or attr_protected declaration.
53
+ config.active_record.whitelist_attributes = true
54
+ end
55
+ end
56
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)