site_framework 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8e95a16b23e98de803f2c46040dc05e53575bee
4
- data.tar.gz: d79408b41041f185b019cee2be65b80c803de057
3
+ metadata.gz: 2fb51315df859b2956c28c75ec98c8ac6b4e107c
4
+ data.tar.gz: a5834402764a4a218fdbc1af1af6583c203358fd
5
5
  SHA512:
6
- metadata.gz: 90b9d6a9aba0421b2a450442608cb552f39522ac2d6894fac8e04b9bc031bbd094b01c4fa01bafa7ff7a51afe36be401151c31c1372543863dacca701889847f
7
- data.tar.gz: 8730e12142001896affe4905e166cf7cb196cd49f4074d976b0b58781213e24ea700faa7041040bd6323270d3bd79a6db47eb7db2a4a6ee9e19f7d2f5a493448
6
+ metadata.gz: 1258af53d24fa55df5e33b7a802950ef49e87f5aff9dfc1b5659536e3f723ea28e2a33dbcd88889647599bf844ade1f9eb2e6ea2ed69e92251f01abafdab2b74
7
+ data.tar.gz: 29b35c5c149570b7597b3e1c5a098c66c28873228d7d278fb4029895e3e204877b9b5da5a16ec21b98ec3b9168be11e6f2deae08efed680760a310b6386a5f10
@@ -1,9 +1,17 @@
1
1
  module SiteFramework
2
+ # This model represent a **Domain**. Each domain
3
+ # belongs to a [Site] model and may or may not
4
+ # belongs to another **Domain**
2
5
  class Domain < ActiveRecord::Base
6
+
3
7
  belongs_to :site
4
8
 
9
+ # Self relation
10
+ belongs_to :parent, :class_name => self.class
11
+
5
12
  validates_associated :site
6
13
  validates :name, :presence => true,
7
- :format => { :with => /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix }
14
+ :format => { :with => /\A(?:[a-z0-9\-]+\.)+[a-z]{2,4}\z/i }
15
+ validates_uniqueness_of :name
8
16
  end
9
17
  end
@@ -1,7 +1,12 @@
1
1
  module SiteFramework
2
+ # This model represent the **Site** entity.
3
+ # [SiteFramework::Middleware] will check for a site
4
+ # with current domain of request and attach the object
5
+ # to global **Rails** object
2
6
  class Site < ActiveRecord::Base
3
7
  has_many :domains
4
8
 
9
+ # This method returns a slug for site title
5
10
  def slug
6
11
  if title
7
12
  title
@@ -1,10 +1,14 @@
1
1
  class CreateSiteFrameworkDomains < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :site_framework_domains do |t|
4
- t.string :name
5
- t.integer :site_id
4
+ t.string :name
5
+ t.integer :site_id
6
+ t.integer :parent_id
7
+ t.boolean :alias
6
8
 
7
- t.timestamps
9
+ t.timestamps
8
10
  end
11
+
12
+ add_index :site_framework_domains, :name, :unique => true
9
13
  end
10
14
  end
@@ -1,6 +1,11 @@
1
1
  module SiteFramework
2
+ # Rack middleware class of `site_framework` which is responsible for loading
3
+ # [Domain] model instance and [Site] model instance and putting them on
4
+ # `Rails.application`.
2
5
  class Middleware
3
6
 
7
+ # Middleware initializer method which gets the `app` from previous
8
+ # middleware
4
9
  def initialize(app)
5
10
  @app = app
6
11
  end
@@ -8,10 +13,41 @@ module SiteFramework
8
13
  def call(env)
9
14
  # Create a method called domain which will return the current domain
10
15
  # name
11
- Rails.application.class.send :define_method, "domain" do
12
- env["SERVER_NAME"]
16
+ Rails.application.send :define_singleton_method, 'domain_name' do
17
+ env['SERVER_NAME']
13
18
  end
14
19
 
20
+ Rails.application.send :define_singleton_method, 'domain' do
21
+ domain = nil
22
+ if Rails.application.instance_variable_defined? '@domain'
23
+ domain = Rails.application.instance_variable_get '@domain'
24
+ if respond_to? :logger
25
+ logger.info "`domain` is defined, value #{domain}"
26
+ end
27
+ end
28
+
29
+ if domain.nil?
30
+ domain_obj = Domain.find_by(:name => Rails.application.domain_name)
31
+ if respond_to? :logger
32
+ logger.debug '`domain` is nil'
33
+ logger.warn "Can't find domain object of `#{Rails.application.domain_name}`"
34
+ end
35
+ Rails.application.instance_variable_set '@domain', domain_obj
36
+ domain = domain_obj
37
+ end
38
+
39
+ domain
40
+ end
41
+
42
+ Rails.application.send :define_singleton_method, 'site' do
43
+ site = nil
44
+ unless Rails.application.domain.nil?
45
+ site = Rails.application.domain.site
46
+ end
47
+ site
48
+ end
49
+
50
+ Rails.application
15
51
  @app.call(env)
16
52
  end
17
53
  end
@@ -1,3 +1,3 @@
1
1
  module SiteFramework
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,4 +1,4 @@
1
-
1
+ # Main module of `site_framework` gem
2
2
  module SiteFramework
3
3
  end
4
4
 
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sameer Rahmani
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-03 00:00:00.000000000 Z
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.0.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.0.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: A site framework for Ruby on Rails web framework inspired by Django site
@@ -47,56 +47,56 @@ executables: []
47
47
  extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
50
53
  - app/models/site_framework/domain.rb
51
54
  - app/models/site_framework/site.rb
52
55
  - config/routes.rb
53
- - db/migrate/20140303141448_create_site_framework_sites.rb
54
56
  - db/migrate/20140118200201_create_site_framework_domains.rb
55
- - lib/site_framework/active_record/migration.rb
57
+ - db/migrate/20140303141448_create_site_framework_sites.rb
58
+ - lib/site_framework.rb
56
59
  - lib/site_framework/active_record/concerns.rb
60
+ - lib/site_framework/active_record/migration.rb
61
+ - lib/site_framework/engine.rb
57
62
  - lib/site_framework/middleware.rb
58
- - lib/site_framework/version.rb
59
63
  - lib/site_framework/railtie.rb
60
- - lib/site_framework/engine.rb
64
+ - lib/site_framework/version.rb
61
65
  - lib/tasks/site_framework_tasks.rake
62
- - lib/site_framework.rb
63
- - LICENSE
64
- - Rakefile
65
- - README.md
66
- - spec/spec_helper.rb
67
- - spec/models/site_framework/site_spec.rb
68
- - spec/models/site_framework/domain_spec.rb
69
- - spec/dummy/public/500.html
70
- - spec/dummy/public/404.html
71
- - spec/dummy/public/422.html
72
- - spec/dummy/public/favicon.ico
73
- - spec/dummy/config.ru
74
66
  - spec/dummy/README.rdoc
75
- - spec/dummy/app/views/layouts/application.html.erb
67
+ - spec/dummy/Rakefile
76
68
  - spec/dummy/app/assets/javascripts/application.js
77
69
  - spec/dummy/app/assets/stylesheets/application.css
78
70
  - spec/dummy/app/controllers/application_controller.rb
79
71
  - spec/dummy/app/helpers/application_helper.rb
80
- - spec/dummy/Rakefile
81
- - spec/dummy/bin/rake
72
+ - spec/dummy/app/views/layouts/application.html.erb
82
73
  - spec/dummy/bin/bundle
83
74
  - spec/dummy/bin/rails
75
+ - spec/dummy/bin/rake
76
+ - spec/dummy/config.ru
84
77
  - spec/dummy/config/application.rb
85
- - spec/dummy/config/environments/test.rb
78
+ - spec/dummy/config/boot.rb
79
+ - spec/dummy/config/database.yml
80
+ - spec/dummy/config/environment.rb
86
81
  - spec/dummy/config/environments/development.rb
87
82
  - spec/dummy/config/environments/production.rb
88
- - spec/dummy/config/routes.rb
89
- - spec/dummy/config/environment.rb
90
- - spec/dummy/config/database.yml
91
- - spec/dummy/config/locales/en.yml
92
- - spec/dummy/config/boot.rb
93
- - spec/dummy/config/initializers/session_store.rb
83
+ - spec/dummy/config/environments/test.rb
94
84
  - spec/dummy/config/initializers/backtrace_silencers.rb
95
- - spec/dummy/config/initializers/wrap_parameters.rb
96
- - spec/dummy/config/initializers/inflections.rb
97
85
  - spec/dummy/config/initializers/filter_parameter_logging.rb
86
+ - spec/dummy/config/initializers/inflections.rb
98
87
  - spec/dummy/config/initializers/mime_types.rb
99
88
  - spec/dummy/config/initializers/secret_token.rb
89
+ - spec/dummy/config/initializers/session_store.rb
90
+ - spec/dummy/config/initializers/wrap_parameters.rb
91
+ - spec/dummy/config/locales/en.yml
92
+ - spec/dummy/config/routes.rb
93
+ - spec/dummy/public/404.html
94
+ - spec/dummy/public/422.html
95
+ - spec/dummy/public/500.html
96
+ - spec/dummy/public/favicon.ico
97
+ - spec/models/site_framework/domain_spec.rb
98
+ - spec/models/site_framework/site_spec.rb
99
+ - spec/spec_helper.rb
100
100
  homepage: https://github.com/Yellowen/site_framework
101
101
  licenses:
102
102
  - GPL-2
@@ -107,53 +107,53 @@ require_paths:
107
107
  - lib
108
108
  required_ruby_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - '>='
110
+ - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 2.0.3
120
+ rubygems_version: 2.2.0
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: A site framework for Ruby on Rails web framework inspired by Django site
124
124
  fremework
125
125
  test_files:
126
- - spec/spec_helper.rb
127
126
  - spec/models/site_framework/site_spec.rb
128
127
  - spec/models/site_framework/domain_spec.rb
129
- - spec/dummy/public/500.html
130
- - spec/dummy/public/404.html
131
- - spec/dummy/public/422.html
132
- - spec/dummy/public/favicon.ico
133
- - spec/dummy/config.ru
134
- - spec/dummy/README.rdoc
128
+ - spec/spec_helper.rb
129
+ - spec/dummy/app/controllers/application_controller.rb
135
130
  - spec/dummy/app/views/layouts/application.html.erb
131
+ - spec/dummy/app/helpers/application_helper.rb
136
132
  - spec/dummy/app/assets/javascripts/application.js
137
133
  - spec/dummy/app/assets/stylesheets/application.css
138
- - spec/dummy/app/controllers/application_controller.rb
139
- - spec/dummy/app/helpers/application_helper.rb
140
- - spec/dummy/Rakefile
141
- - spec/dummy/bin/rake
142
134
  - spec/dummy/bin/bundle
143
135
  - spec/dummy/bin/rails
136
+ - spec/dummy/bin/rake
137
+ - spec/dummy/public/404.html
138
+ - spec/dummy/public/422.html
139
+ - spec/dummy/public/500.html
140
+ - spec/dummy/public/favicon.ico
141
+ - spec/dummy/config.ru
144
142
  - spec/dummy/config/application.rb
145
- - spec/dummy/config/environments/test.rb
146
143
  - spec/dummy/config/environments/development.rb
144
+ - spec/dummy/config/environments/test.rb
147
145
  - spec/dummy/config/environments/production.rb
148
- - spec/dummy/config/routes.rb
146
+ - spec/dummy/config/initializers/backtrace_silencers.rb
147
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
148
+ - spec/dummy/config/initializers/secret_token.rb
149
+ - spec/dummy/config/initializers/session_store.rb
150
+ - spec/dummy/config/initializers/wrap_parameters.rb
151
+ - spec/dummy/config/initializers/mime_types.rb
152
+ - spec/dummy/config/initializers/inflections.rb
149
153
  - spec/dummy/config/environment.rb
150
154
  - spec/dummy/config/database.yml
151
155
  - spec/dummy/config/locales/en.yml
156
+ - spec/dummy/config/routes.rb
152
157
  - spec/dummy/config/boot.rb
153
- - spec/dummy/config/initializers/session_store.rb
154
- - spec/dummy/config/initializers/backtrace_silencers.rb
155
- - spec/dummy/config/initializers/wrap_parameters.rb
156
- - spec/dummy/config/initializers/inflections.rb
157
- - spec/dummy/config/initializers/filter_parameter_logging.rb
158
- - spec/dummy/config/initializers/mime_types.rb
159
- - spec/dummy/config/initializers/secret_token.rb
158
+ - spec/dummy/README.rdoc
159
+ - spec/dummy/Rakefile