rails_account_location 1.0

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/.gitignore ADDED
@@ -0,0 +1 @@
1
+ account_location-*.gem
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ source :rubygems
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ # Copyright (c) 2005 David Heinemeier Hansson
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,57 @@
1
+ Account Location
2
+ ================
3
+
4
+ Account location is a set of protected methods that supports the account-key-as-subdomain
5
+ way of identifying the current scope. These methods allow you to easily produce URLs that
6
+ match this style and to get the current account key from the subdomain.
7
+
8
+ The methods are: `account_url`, `account_host`, and `account_domain`.
9
+
10
+ current_account can be used to get and set the currently active account.
11
+
12
+
13
+ Example:
14
+
15
+ class ApplicationController < ActionController::Base
16
+ include AccountLocation
17
+ before_filter :find_account
18
+
19
+ protected
20
+ def find_account
21
+ self.current_account = Account.find_by_username(account_subdomain)
22
+ end
23
+ end
24
+
25
+ class UsersController < ApplicationController
26
+ def index
27
+ @users = current_account.users.all
28
+ end
29
+ end
30
+
31
+ class AccountController < ApplicationController
32
+ def new
33
+ @new_account = Account.create(params[:new_account])
34
+ redirect_to :host => account_host(@new_account.username), :controller => "weblog"
35
+ end
36
+
37
+ def authenticate
38
+ session[account_domain] = :authenticated
39
+ redirect_to :controller => "weblog"
40
+ end
41
+
42
+ protected
43
+ def authenticated?
44
+ session[account_domain] == :authenticated
45
+ end
46
+ end
47
+
48
+ And in your view:
49
+
50
+ Your domain: <%= account_url %>
51
+
52
+ By default, all the methods will query for current_account.username as the account key, but you can
53
+ specialize that by overwriting default_account_subdomain. You can of course also pass it in
54
+ as the first argument to all the methods.
55
+
56
+
57
+ Copyright (c) 2005 David Heinemeier Hansson, released under the MIT license
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
4
+
5
+ version = "1.0"
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "rails_account_location"
9
+ s.version = version
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = ["David Heinemeier Hansson"]
12
+ s.email = "david@37signals.com"
13
+ s.homepage = "http://github.com/rails/account_location"
14
+ s.summary = "Module that supports account-key-as-subdomain pattern"
15
+ s.description = "Account location is a set of protected methods that supports the account-key-as-subdomain way of identifying the current scope."
16
+
17
+ s.rubygems_version = "1.3.7"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
21
+ s.extra_rdoc_files = [ "README.md" ]
22
+ s.rdoc_options = ["--charset=UTF-8"]
23
+ s.require_path = "lib"
24
+
25
+ s.add_runtime_dependency "rails"
26
+ end
@@ -0,0 +1,41 @@
1
+ module AccountLocation
2
+ def self.included(controller)
3
+ controller.helper_method(:account_domain, :account_subdomain, :account_host, :account_url,
4
+ :current_account)
5
+ end
6
+
7
+ protected
8
+
9
+ def current_account
10
+ @current_account
11
+ end
12
+
13
+ def current_account=(account)
14
+ @current_account = account
15
+ end
16
+
17
+ def default_account_subdomain
18
+ account = current_account || @account
19
+ account.username if account && account.respond_to?(:username)
20
+ end
21
+
22
+ def account_url(account_subdomain = default_account_subdomain, use_ssl = request.ssl?)
23
+ (use_ssl ? "https://" : "http://") + account_host(account_subdomain)
24
+ end
25
+
26
+ def account_host(account_subdomain = default_account_subdomain)
27
+ account_host = ""
28
+ account_host << account_subdomain + "."
29
+ account_host << account_domain
30
+ end
31
+
32
+ def account_domain
33
+ account_domain = ""
34
+ account_domain << request.subdomains[1..-1].join(".") + "." if request.subdomains.size > 1
35
+ account_domain << request.domain + request.port_string
36
+ end
37
+
38
+ def account_subdomain
39
+ request.subdomains.first
40
+ end
41
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+
3
+ class AccountLocationTest < Test::Unit::TestCase
4
+ def test_truth
5
+ assert true
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_account_location
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
10
+ platform: ruby
11
+ authors:
12
+ - David Heinemeier Hansson
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2013-01-29 00:00:00 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: rails
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Account location is a set of protected methods that supports the account-key-as-subdomain way of identifying the current scope.
34
+ email: david@37signals.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README.md
41
+ files:
42
+ - .gitignore
43
+ - Gemfile
44
+ - MIT-LICENSE
45
+ - README.md
46
+ - account_location.gemspec
47
+ - lib/account_location.rb
48
+ - test/account_location_test.rb
49
+ homepage: http://github.com/rails/account_location
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.15
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Module that supports account-key-as-subdomain pattern
82
+ test_files: []
83
+
84
+ has_rdoc: