site_framework 0.3.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/site_framework/domain.rb +24 -5
- data/app/models/site_framework/site.rb +13 -3
- data/lib/site_framework/engine.rb +2 -1
- data/lib/site_framework/middleware.rb +15 -1
- data/lib/site_framework/mongoid/concerns.rb +11 -0
- data/lib/site_framework/orm.rb +20 -0
- data/lib/site_framework/version.rb +1 -1
- data/lib/site_framework.rb +9 -2
- metadata +41 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ebfba86caf32f02c9c3ee0005ae888ab99a5693
|
4
|
+
data.tar.gz: 7592ca5ba338fb8c130988fee3ffecff6d17e7ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46be8593a818ab7b94910d3e7c30b56e7595af4da2ee9d41a760cdb69a01b653408ea47ca059451d9b28465eb408839ed51faad1e00ae37c60641b91427282a5
|
7
|
+
data.tar.gz: b3c247baf8b0cca3cbd08afda993e21fce2e55acffc0541822c1f36b2eabdbdf1dac5cf9dd0e52d103ab1de9c661d2da207996b32742b43c0773a6fb91e31703
|
@@ -2,14 +2,33 @@ module SiteFramework
|
|
2
2
|
# This model represent a **Domain**. Each domain
|
3
3
|
# belongs to a [Site] model and may or may not
|
4
4
|
# belongs to another **Domain**
|
5
|
-
class Domain < ActiveRecord::Base
|
5
|
+
class Domain < (defined?(ActiveRecord) ? ActiveRecord::Base : Object)
|
6
6
|
|
7
|
-
|
7
|
+
if defined? Mongoid
|
8
|
+
include Mongoid::Document
|
9
|
+
include Mongoid::Timestamps
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
field :name, :type => String
|
12
|
+
field :parent, :type => String
|
13
|
+
field :alias, :type => Boolean
|
14
|
+
|
15
|
+
embedded_in :site
|
16
|
+
|
17
|
+
index({ name: 1 }, { unique: true, background: true })
|
18
|
+
|
19
|
+
def parent
|
20
|
+
# TODO: return a domain with alias == false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
if defined? ActiveRecord
|
25
|
+
belongs_to :site
|
26
|
+
|
27
|
+
# Self relation
|
28
|
+
belongs_to :parent, :class_name => self.class
|
29
|
+
validates_associated :site
|
30
|
+
end
|
11
31
|
|
12
|
-
validates_associated :site
|
13
32
|
validates :name, :presence => true,
|
14
33
|
:format => { :with => /\A(?:[a-z0-9\-]+\.)+[a-z]{2,4}\z/i }
|
15
34
|
validates_uniqueness_of :name
|
@@ -3,8 +3,19 @@ module SiteFramework
|
|
3
3
|
# [SiteFramework::Middleware] will check for a site
|
4
4
|
# with current domain of request and attach the object
|
5
5
|
# to global **Rails** object
|
6
|
-
class Site < ActiveRecord::Base
|
7
|
-
|
6
|
+
class Site < (defined?(ActiveRecord) ? ActiveRecord::Base : Object)
|
7
|
+
|
8
|
+
if defined? Mongoid
|
9
|
+
include Mongoid::Document
|
10
|
+
include Mongoid::Timestamps
|
11
|
+
|
12
|
+
field :title, :type => String
|
13
|
+
field :description, :type => String
|
14
|
+
|
15
|
+
embeds_many :domains
|
16
|
+
end
|
17
|
+
|
18
|
+
has_many :domains if defined? ActiveRecord::Base
|
8
19
|
|
9
20
|
# This method returns a slug for site title
|
10
21
|
def slug
|
@@ -13,7 +24,6 @@ module SiteFramework
|
|
13
24
|
else
|
14
25
|
# TODO: generate a sha1 hash base on time
|
15
26
|
end
|
16
|
-
|
17
27
|
end
|
18
28
|
end
|
19
29
|
end
|
@@ -17,6 +17,18 @@ module SiteFramework
|
|
17
17
|
env['SERVER_NAME']
|
18
18
|
end
|
19
19
|
|
20
|
+
# Create `fetch_domain` method on `Rails.application`
|
21
|
+
# only if it didn't already define.
|
22
|
+
unless Rails.application.respond_to? :fetch_domain
|
23
|
+
Rails.application.send :define_singleton_method, 'fetch_domain' do
|
24
|
+
if defined? ActiveRecord
|
25
|
+
Domain.find_by(nam: Rails.application.domain_name)
|
26
|
+
elsif defined? Mongoid
|
27
|
+
Site.where('domains.name' => Rails.application.domain_name).domains.first
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
20
32
|
Rails.application.send :define_singleton_method, 'domain' do
|
21
33
|
domain = nil
|
22
34
|
if Rails.application.instance_variable_defined? '@domain'
|
@@ -27,7 +39,9 @@ module SiteFramework
|
|
27
39
|
end
|
28
40
|
|
29
41
|
if domain.nil?
|
30
|
-
|
42
|
+
# Fetch domain by calling **fetch_domain** method on
|
43
|
+
# **Rails.application**
|
44
|
+
domain_obj = fetch_domain
|
31
45
|
if respond_to? :logger
|
32
46
|
logger.debug '`domain` is nil'
|
33
47
|
logger.warn "Can't find domain object of `#{Rails.application.domain_name}`"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SiteFramework
|
2
|
+
module ORM
|
3
|
+
def self.current_orm
|
4
|
+
if defined? ActiveRecord
|
5
|
+
'active_record'
|
6
|
+
elsif defined? Mongoid
|
7
|
+
'mongoid'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.base_class
|
12
|
+
case current_orm
|
13
|
+
when 'active_record'
|
14
|
+
::ActiveRecord::Base
|
15
|
+
when 'mongoid'
|
16
|
+
Object
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/site_framework.rb
CHANGED
@@ -4,6 +4,13 @@ end
|
|
4
4
|
|
5
5
|
require "site_framework/engine"
|
6
6
|
require 'site_framework/railtie'
|
7
|
-
require 'site_framework/
|
8
|
-
|
7
|
+
require 'site_framework/orm'
|
8
|
+
case SiteFramework::ORM.current_orm
|
9
|
+
when 'active_record'
|
10
|
+
require 'site_framework/active_record/migration'
|
11
|
+
require 'site_framework/active_record/concerns'
|
12
|
+
when 'mongoid'
|
13
|
+
require 'site_framework/mongoid/concerns'
|
14
|
+
end
|
15
|
+
|
9
16
|
require 'site_framework/middleware'
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: site_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
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-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4
|
19
|
+
version: '4'
|
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
|
-
version: 4
|
26
|
+
version: '4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: orm_adapter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,6 +74,8 @@ files:
|
|
60
74
|
- lib/site_framework/active_record/migration.rb
|
61
75
|
- lib/site_framework/engine.rb
|
62
76
|
- lib/site_framework/middleware.rb
|
77
|
+
- lib/site_framework/mongoid/concerns.rb
|
78
|
+
- lib/site_framework/orm.rb
|
63
79
|
- lib/site_framework/railtie.rb
|
64
80
|
- lib/site_framework/version.rb
|
65
81
|
- lib/tasks/site_framework_tasks.rake
|
@@ -123,37 +139,37 @@ specification_version: 4
|
|
123
139
|
summary: A site framework for Ruby on Rails web framework inspired by Django site
|
124
140
|
fremework
|
125
141
|
test_files:
|
142
|
+
- spec/spec_helper.rb
|
126
143
|
- spec/models/site_framework/site_spec.rb
|
127
144
|
- spec/models/site_framework/domain_spec.rb
|
128
|
-
- spec/
|
129
|
-
- spec/dummy/
|
145
|
+
- spec/dummy/public/500.html
|
146
|
+
- spec/dummy/public/404.html
|
147
|
+
- spec/dummy/public/422.html
|
148
|
+
- spec/dummy/public/favicon.ico
|
149
|
+
- spec/dummy/config.ru
|
150
|
+
- spec/dummy/README.rdoc
|
130
151
|
- spec/dummy/app/views/layouts/application.html.erb
|
131
|
-
- spec/dummy/app/helpers/application_helper.rb
|
132
152
|
- spec/dummy/app/assets/javascripts/application.js
|
133
153
|
- spec/dummy/app/assets/stylesheets/application.css
|
154
|
+
- spec/dummy/app/controllers/application_controller.rb
|
155
|
+
- spec/dummy/app/helpers/application_helper.rb
|
156
|
+
- spec/dummy/Rakefile
|
157
|
+
- spec/dummy/bin/rake
|
134
158
|
- spec/dummy/bin/bundle
|
135
159
|
- 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
|
142
160
|
- spec/dummy/config/application.rb
|
143
|
-
- spec/dummy/config/environments/development.rb
|
144
161
|
- spec/dummy/config/environments/test.rb
|
162
|
+
- spec/dummy/config/environments/development.rb
|
145
163
|
- spec/dummy/config/environments/production.rb
|
146
|
-
- spec/dummy/config/
|
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
|
164
|
+
- spec/dummy/config/routes.rb
|
153
165
|
- spec/dummy/config/environment.rb
|
154
166
|
- spec/dummy/config/database.yml
|
155
167
|
- spec/dummy/config/locales/en.yml
|
156
|
-
- spec/dummy/config/routes.rb
|
157
168
|
- spec/dummy/config/boot.rb
|
158
|
-
- spec/dummy/
|
159
|
-
- spec/dummy/
|
169
|
+
- spec/dummy/config/initializers/session_store.rb
|
170
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
171
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
172
|
+
- spec/dummy/config/initializers/inflections.rb
|
173
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
174
|
+
- spec/dummy/config/initializers/mime_types.rb
|
175
|
+
- spec/dummy/config/initializers/secret_token.rb
|