tophold_engine 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/models/article.rb +18 -0
- data/app/models/article_record.rb +13 -0
- data/app/models/comment.rb +15 -0
- data/app/models/tag.rb +16 -0
- data/app/models/topic.rb +14 -0
- data/app/models/user.rb +6 -0
- data/app/models/user_document.rb +12 -0
- data/config/initializers/basic_configatron_settings.rb +19 -0
- data/config/initializers/mongoid_extends_patch.rb +29 -0
- data/config/initializers/resque_redis_host_settings.rb +6 -0
- data/lib/serve_gridfs_image.rb +25 -0
- data/lib/tophold_engine/engine.rb +23 -0
- data/lib/tophold_engine/version.rb +3 -0
- data/lib/tophold_engine.rb +12 -0
- data/tophold_engine.gemspec +30 -0
- metadata +152 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3-p362@tophold_engine
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 readline
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# TopholdEngine
|
2
|
+
|
3
|
+
The core of tophold biz.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tophold_engine'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tophold_engine
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
class Article
|
3
|
+
|
4
|
+
include Mongoid::Document
|
5
|
+
|
6
|
+
field :title, type: String
|
7
|
+
|
8
|
+
field :content, type: String
|
9
|
+
|
10
|
+
attr_protected: _id
|
11
|
+
|
12
|
+
embeds_many :tags, as: taggable
|
13
|
+
|
14
|
+
embeds_many :comments, as: commentable
|
15
|
+
|
16
|
+
has_many :article_scores, dependent: delete
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
class Comment
|
3
|
+
|
4
|
+
include Mongoid::Document
|
5
|
+
|
6
|
+
embedded_in :article, polymorphic: true
|
7
|
+
|
8
|
+
embedded_in :sub_topic, polymorphic: true
|
9
|
+
|
10
|
+
embeds_many :replies, class_name: "Comment", inverseof: :parent
|
11
|
+
|
12
|
+
embedded_in :parent, class_name: "Comment", inverse_of: :replies
|
13
|
+
|
14
|
+
end
|
15
|
+
|
data/app/models/tag.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
class Tag
|
3
|
+
|
4
|
+
include Mongoid::Document
|
5
|
+
|
6
|
+
field :title, type: String
|
7
|
+
|
8
|
+
recursively_embeds_many index: true, background: true
|
9
|
+
|
10
|
+
embedded_in :article, ploymorphic: true
|
11
|
+
|
12
|
+
embedded_in :topic, ploymorphic: true
|
13
|
+
|
14
|
+
embedded_in :sub_topic, ploymorphic: true
|
15
|
+
|
16
|
+
end
|
data/app/models/topic.rb
ADDED
data/app/models/user.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'configatron'
|
3
|
+
|
4
|
+
@@TOPHOLD_GLOBAL_CONFIG = {
|
5
|
+
|
6
|
+
redis: {
|
7
|
+
development: {
|
8
|
+
host: "localhost",
|
9
|
+
port: "6379",
|
10
|
+
},
|
11
|
+
production: {
|
12
|
+
host: "uranus",
|
13
|
+
port: "6379",
|
14
|
+
},
|
15
|
+
},
|
16
|
+
|
17
|
+
}
|
18
|
+
|
19
|
+
configatron.configure_from_hash @@TOPHOLD_GLOBAL_CONFIG
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
Mongoid.add_language("zh-CN")
|
4
|
+
|
5
|
+
module Mongoid
|
6
|
+
|
7
|
+
class Criteria
|
8
|
+
|
9
|
+
def in_batches size=nil
|
10
|
+
limit = size || 500
|
11
|
+
skip = 0
|
12
|
+
objects = self.limit(limit).skip(skip * limit)
|
13
|
+
while objects.any?
|
14
|
+
yield objects
|
15
|
+
break if objects.size < limit
|
16
|
+
skip+=1
|
17
|
+
objects = self.limit(limit).skip(skip*limit)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
if defined?(PhusionPassenger)
|
26
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
27
|
+
Mongoid.master.connection.connect if forked
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
class ServeGridfsImage
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
if env["PATH_INFO"] =~ /^\/grid\/(.+)$/
|
9
|
+
process_request(env, $1)
|
10
|
+
else
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def process_request(env, key)
|
17
|
+
begin
|
18
|
+
Mongo::GridFileSystem.new(Mongoid.database).open(key, 'r') do |file|
|
19
|
+
[200, { 'Content-Type' => file.content_type }, [file.read]]
|
20
|
+
end
|
21
|
+
rescue
|
22
|
+
[404, { 'Content-Type' => 'text/plain' }, ['File not found.']]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'serve_gridfs_image'
|
2
|
+
|
3
|
+
module TopholdEngine
|
4
|
+
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
|
7
|
+
initializer "tophold_rack.load_app_instance_data" do |app|
|
8
|
+
TopholdRack.setup do |config|
|
9
|
+
config.app_root = app.root
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# initializer "tophold_engine.add_middleware" do |app|
|
14
|
+
# app.middleware.use ServeGridfsImage
|
15
|
+
# end
|
16
|
+
|
17
|
+
rake_tasks do
|
18
|
+
require 'resque/tasks'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tophold_engine/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "tophold_engine"
|
8
|
+
gem.version = TopholdEngine::VERSION
|
9
|
+
gem.authors = ["shreadline"]
|
10
|
+
gem.email = ["tim.rubist@gmail.com"]
|
11
|
+
gem.description = %q{tophold models engine}
|
12
|
+
gem.summary = %q{tophold models center}
|
13
|
+
gem.homepage = "http://github.com/tteng/tophold_engine"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency "rails", ">= 3.2.12"
|
21
|
+
|
22
|
+
gem.add_dependency "mysql2", ">= 0.3.11"
|
23
|
+
|
24
|
+
gem.add_dependency "configatron", ">= 2.10.0"
|
25
|
+
|
26
|
+
gem.add_dependency "mongoid"
|
27
|
+
|
28
|
+
gem.add_dependency "resque"
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tophold_engine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- shreadline
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.12
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.12
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mysql2
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.3.11
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.3.11
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: configatron
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.10.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.10.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mongoid
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: resque
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: tophold models engine
|
95
|
+
email:
|
96
|
+
- tim.rubist@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rvmrc
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- app/models/article.rb
|
108
|
+
- app/models/article_record.rb
|
109
|
+
- app/models/comment.rb
|
110
|
+
- app/models/tag.rb
|
111
|
+
- app/models/topic.rb
|
112
|
+
- app/models/user.rb
|
113
|
+
- app/models/user_document.rb
|
114
|
+
- config/initializers/basic_configatron_settings.rb
|
115
|
+
- config/initializers/mongoid_extends_patch.rb
|
116
|
+
- config/initializers/resque_redis_host_settings.rb
|
117
|
+
- lib/serve_gridfs_image.rb
|
118
|
+
- lib/tophold_engine.rb
|
119
|
+
- lib/tophold_engine/engine.rb
|
120
|
+
- lib/tophold_engine/version.rb
|
121
|
+
- tophold_engine.gemspec
|
122
|
+
homepage: http://github.com/tteng/tophold_engine
|
123
|
+
licenses: []
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
hash: 3539811113605173694
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
hash: 3539811113605173694
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 1.8.24
|
149
|
+
signing_key:
|
150
|
+
specification_version: 3
|
151
|
+
summary: tophold models center
|
152
|
+
test_files: []
|