models 0.0.22.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +1 -0
- data/app/models/activity.rb +23 -0
- data/app/models/category.rb +32 -0
- data/app/models/category_type.rb +17 -0
- data/app/models/keyword.rb +11 -0
- data/app/models/location.rb +11 -0
- data/app/models/model.rb +19 -0
- data/app/models/model_type.rb +7 -0
- data/app/models/photo.rb +18 -0
- data/app/models/price.rb +13 -0
- data/app/models/product.rb +63 -0
- data/app/models/settings.rb +33 -0
- data/app/models/spec_rec.rb +8 -0
- data/app/models/store.rb +43 -0
- data/app/models/token.rb +18 -0
- data/app/models/user.rb +16 -0
- data/app/models/widget.rb +25 -0
- data/lib/models.rb +13 -0
- data/lib/models/version.rb +3 -0
- data/models.gemspec +21 -0
- metadata +101 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Le Duc Duy
|
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,23 @@
|
|
1
|
+
# Models
|
2
|
+
|
3
|
+
Gem riêng để sài với search app với admin app và frontend app
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'models', git: "git@github.com:duyleekun/models.git"
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Nếu muốn sửa nhanh thì vào cái gem đó trong rubymine sửa như bình thường
|
18
|
+
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
Clone về, sửa, đẩy version trong file version.rb rồi push
|
23
|
+
Rồi qua app chính bundle update là xong
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Activity
|
2
|
+
include Mongoid::Document
|
3
|
+
embedded_in :actionable, polymorphic: true
|
4
|
+
|
5
|
+
field :recommend, type: Hash
|
6
|
+
field :view, type: Hash
|
7
|
+
field :visit, type: Hash
|
8
|
+
|
9
|
+
field :_id, type: String, default: nil
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def activities_of_user(user_id)
|
14
|
+
result = {}
|
15
|
+
self.attributes.each {|k,v|
|
16
|
+
result[k] = {
|
17
|
+
'id' => (v.include?(user_id.to_s) ? v[user_id.to_s] || true : false),
|
18
|
+
'count' => v.try(:length)
|
19
|
+
}
|
20
|
+
}
|
21
|
+
result
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Category
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
|
5
|
+
default_scope ne(status: "DELETED").limit(20)
|
6
|
+
scope :filter_store, ->(store_id) {where(store_id: store_id)}
|
7
|
+
|
8
|
+
embeds_one :settings, class_name: "Settings"
|
9
|
+
|
10
|
+
|
11
|
+
#FROM iMuaSam
|
12
|
+
##FIELD
|
13
|
+
field :status, type: String
|
14
|
+
field :count, type: Integer
|
15
|
+
field :lid, type: Integer
|
16
|
+
field :position, type: Float
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
##RELATIONS
|
21
|
+
belongs_to :store
|
22
|
+
has_many :products
|
23
|
+
embeds_one :cover, as: :photoable, class_name: 'Photo', store_as: 'cover'
|
24
|
+
|
25
|
+
|
26
|
+
#FROM GRAPH API
|
27
|
+
##FIELDS
|
28
|
+
field :fb_id, type: String
|
29
|
+
field :name, type: String
|
30
|
+
field :description, type: String
|
31
|
+
field :columns, type: Integer
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CategoryType
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Localized::Accessor
|
4
|
+
|
5
|
+
default_scope exists(:status => 1).asc(:id)
|
6
|
+
|
7
|
+
field :_id, type: Integer
|
8
|
+
field :name, type: Hash, localize: true
|
9
|
+
field :level, type: Integer
|
10
|
+
field :status, type: String
|
11
|
+
field :site, type: Array
|
12
|
+
|
13
|
+
embeds_many :spec_recs
|
14
|
+
belongs_to :category_type
|
15
|
+
has_many :category_types
|
16
|
+
has_and_belongs_to_many :parents, class_name: 'CategoryType', inverse_of: :parents, foreign_key: 'parents'
|
17
|
+
end
|
data/app/models/model.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class Model
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
field :_id, type: Integer
|
5
|
+
field :name, type: String
|
6
|
+
field :model_id, type: String
|
7
|
+
field :type, type: String
|
8
|
+
field :brand, type: String
|
9
|
+
embeds_one :cover, as: :photoable, class_name: 'Photo', store_as: 'cover'
|
10
|
+
field :spec_values, type: Hash
|
11
|
+
|
12
|
+
def self.find_all_by_id ids, _ = {}
|
13
|
+
Model.where(:id.in => ids)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get (key)
|
17
|
+
self.spec_values.try(:[], key)
|
18
|
+
end
|
19
|
+
end
|
data/app/models/photo.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Size
|
2
|
+
include Mongoid::Document
|
3
|
+
embedded_in :photo
|
4
|
+
|
5
|
+
field :_id, type: String, default: nil
|
6
|
+
|
7
|
+
field :w, type: Integer
|
8
|
+
field :h, type: Integer
|
9
|
+
end
|
10
|
+
|
11
|
+
class Photo
|
12
|
+
include Mongoid::Document
|
13
|
+
embedded_in :photoable, polymorphic: true
|
14
|
+
field :source, type: String
|
15
|
+
field :_id, type: String, default: nil
|
16
|
+
field :offset, type: Integer
|
17
|
+
embeds_one :size
|
18
|
+
end
|
data/app/models/price.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class Price
|
2
|
+
include Mongoid::Document
|
3
|
+
embedded_in :pricable, polymorphic: true
|
4
|
+
|
5
|
+
field :_id, type: String, default: nil
|
6
|
+
field :currency, type: String
|
7
|
+
field :amount, type: Float
|
8
|
+
|
9
|
+
def to_s(missing_string)
|
10
|
+
return "#{currency} #{(amount - amount.floor) >0 ? amount : amount.floor}" if currency && amount
|
11
|
+
return missing_string
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class Choice
|
2
|
+
include Mongoid::Document
|
3
|
+
attr_accessible :adjusted_price, :stock, :values
|
4
|
+
|
5
|
+
embedded_in :option
|
6
|
+
|
7
|
+
field :_id, type: String, default: nil
|
8
|
+
field :adjusted_price, type: Float
|
9
|
+
field :values, type: Array
|
10
|
+
field :in_stock, type: Boolean
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
class Option
|
15
|
+
include Mongoid::Document
|
16
|
+
embedded_in :product
|
17
|
+
|
18
|
+
field :_id, type: String, default: nil
|
19
|
+
embeds_many :choices
|
20
|
+
field :template, type: Array
|
21
|
+
field :name, type: String
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
class Product
|
27
|
+
include Mongoid::Document
|
28
|
+
include Mongoid::Timestamps
|
29
|
+
|
30
|
+
default_scope ne(status: "DELETED").limit(20)
|
31
|
+
scope :filter_store, ->(store_id) {where(store_id: store_id)}
|
32
|
+
|
33
|
+
belongs_to :category, index: true
|
34
|
+
belongs_to :store, index: true
|
35
|
+
embedded_in :widget
|
36
|
+
|
37
|
+
embeds_one :cover, as: :photoable, class_name: 'Photo', store_as: 'cover'
|
38
|
+
embeds_many :photos
|
39
|
+
embeds_one :activity
|
40
|
+
embeds_one :option
|
41
|
+
embeds_one :price, as: :pricable
|
42
|
+
embeds_one :retail_price, as: :pricable, class_name: 'Price', store_as: 'retail_price'
|
43
|
+
|
44
|
+
embeds_one :settings, class_name: "Settings"
|
45
|
+
|
46
|
+
field :fb_id, type: String
|
47
|
+
field :lid, type: Integer
|
48
|
+
field :category_lid , type: Integer
|
49
|
+
|
50
|
+
|
51
|
+
field :status, type: String
|
52
|
+
field :name, type: String
|
53
|
+
field :description, type: String
|
54
|
+
field :content, type: String #<html>
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
field :in_stock, type: Boolean
|
59
|
+
field :position, type: Float
|
60
|
+
|
61
|
+
field :sku, type: String
|
62
|
+
field :keywords, type: Array
|
63
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class PaymentMethod
|
2
|
+
include Mongoid::Document
|
3
|
+
embedded_in :settings
|
4
|
+
|
5
|
+
field :_id, type: String, default: nil
|
6
|
+
field :account, :type => String
|
7
|
+
field :bank, :type => String
|
8
|
+
field :enabled, :type => String
|
9
|
+
field :method, :type => Symbol
|
10
|
+
end
|
11
|
+
|
12
|
+
class ShippingMethod
|
13
|
+
include Mongoid::Document
|
14
|
+
embedded_in :settings
|
15
|
+
|
16
|
+
embeds_one :location
|
17
|
+
field :_id, type: String, default: nil
|
18
|
+
field :enabled, :type => Boolean
|
19
|
+
field :method, :type => Symbol
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
class Settings
|
24
|
+
include Mongoid::Document
|
25
|
+
embedded_in :settingable, polymorphic: true
|
26
|
+
|
27
|
+
field :_id, type: String
|
28
|
+
field :auto_set_featured, type: Boolean
|
29
|
+
field :own, type: Boolean
|
30
|
+
embeds_many :shipping_methods
|
31
|
+
embeds_many :payment_methods
|
32
|
+
|
33
|
+
end
|
data/app/models/store.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
class Store
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
default_scope ne(status: "DELETED")
|
5
|
+
|
6
|
+
#attr_accessible :name, :picture, :website, :description, :about, :phone, :settings, :cover, :location
|
7
|
+
|
8
|
+
#FROM iMuaSam
|
9
|
+
#RELATIONS
|
10
|
+
has_many :categories
|
11
|
+
has_many :widgets
|
12
|
+
embeds_one :settings, class_name: "Settings"
|
13
|
+
embeds_one :location
|
14
|
+
embeds_one :activity
|
15
|
+
|
16
|
+
|
17
|
+
##FIELD
|
18
|
+
field :status, type: String
|
19
|
+
field :currency, type: String
|
20
|
+
field :language, type: String
|
21
|
+
field :store_category, type: String
|
22
|
+
field :fb_link, type: String
|
23
|
+
field :username, type: String
|
24
|
+
field :like_count, type: Integer
|
25
|
+
field :terms_and_policies, type:String
|
26
|
+
field :email, type:String
|
27
|
+
field :count, type: Integer
|
28
|
+
field :handling_time, type:String
|
29
|
+
|
30
|
+
#FROM GRAPH API
|
31
|
+
##RELATIONS
|
32
|
+
embeds_one :token, as: :fb_token
|
33
|
+
embeds_one :cover, as: :photoable, class_name: 'Photo', store_as: 'cover'
|
34
|
+
##FIELDS
|
35
|
+
field :fb_id, type: String
|
36
|
+
field :name, type: String
|
37
|
+
|
38
|
+
field :website, type: String
|
39
|
+
field :description, type: String
|
40
|
+
field :about, type: String
|
41
|
+
field :phone, type: String
|
42
|
+
|
43
|
+
end
|
data/app/models/token.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Token
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
embedded_in :fb_token, polymorphic: true
|
5
|
+
|
6
|
+
field :_id, type: String, default: nil
|
7
|
+
field :access_token, type: String
|
8
|
+
field :can_modify, type: Boolean
|
9
|
+
field :expires, type: DateTime
|
10
|
+
field :scope, type: Array
|
11
|
+
|
12
|
+
def update_attributes_from_fb(access_token,expires_from_epoch = nil)
|
13
|
+
self.access_token = access_token
|
14
|
+
self.expires = Time.at(expires_from_epoch.to_i).to_datetime if expires_from_epoch
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/app/models/user.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class User
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
default_scope ne(status: "DELETED")
|
5
|
+
|
6
|
+
#From iMuaSam
|
7
|
+
##Field
|
8
|
+
field :status, type: String
|
9
|
+
|
10
|
+
#FROM GRAPH API
|
11
|
+
##RELATIONS
|
12
|
+
embeds_one :token, as: :fb_token
|
13
|
+
##FIELDS
|
14
|
+
field :fb_id, type: String
|
15
|
+
field :pages_ids, type: Array
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Widget
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
|
5
|
+
default_scope ne(status: "DELETED")
|
6
|
+
scope :filter_store, ->(store_id) {where(store_id: store_id)}
|
7
|
+
belongs_to :store
|
8
|
+
|
9
|
+
field :name, type: String #Title of widget
|
10
|
+
field :type, type: String #Types: Not finalized yet
|
11
|
+
field :status, type: String
|
12
|
+
|
13
|
+
field :settings #Type specific setting
|
14
|
+
field :position, type: Float #Position
|
15
|
+
|
16
|
+
field :api, type: String #NEWEST,RECENT_UPDATE,MOST_VIEWED,MOST_RECOMMENDED,FIXED
|
17
|
+
field :source # Object, e.g Store ID
|
18
|
+
field :source_type # ENUM: Store, Category, Categories, Product, Products, User, URL, URLS
|
19
|
+
|
20
|
+
field :key_type, type: String #Store,Category,Product
|
21
|
+
field :limit, type: Integer #Limit used in query
|
22
|
+
field :keys, type: Array #List of ids
|
23
|
+
field :values, type: Hash #Hash of overrides
|
24
|
+
|
25
|
+
end
|
data/lib/models.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "models/version"
|
2
|
+
require "mongoid"
|
3
|
+
require "mongoid-localized-accessor"
|
4
|
+
|
5
|
+
Dir[File.expand_path("../../app/models/*.rb",__FILE__)].each {|file|
|
6
|
+
puts file
|
7
|
+
require file
|
8
|
+
}
|
9
|
+
|
10
|
+
Dir[File.expand_path("../../app/models/model/*.rb",__FILE__)].each {|file|
|
11
|
+
puts file
|
12
|
+
require file
|
13
|
+
}
|
data/models.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'models/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "models"
|
8
|
+
gem.version = Models::VERSION
|
9
|
+
gem.authors = ["Le Duc Duy"]
|
10
|
+
gem.email = ["me@duy.kr"]
|
11
|
+
gem.description = "Models for ims"
|
12
|
+
gem.summary = "Models for ims"
|
13
|
+
gem.homepage = ""
|
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
|
+
gem.add_dependency 'mongoid'
|
20
|
+
gem.add_dependency 'mongoid-localized-accessor'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: models
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.22.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Le Duc Duy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mongoid
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
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: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mongoid-localized-accessor
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
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'
|
46
|
+
description: Models for ims
|
47
|
+
email:
|
48
|
+
- me@duy.kr
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- app/models/activity.rb
|
59
|
+
- app/models/category.rb
|
60
|
+
- app/models/category_type.rb
|
61
|
+
- app/models/keyword.rb
|
62
|
+
- app/models/location.rb
|
63
|
+
- app/models/model.rb
|
64
|
+
- app/models/model_type.rb
|
65
|
+
- app/models/photo.rb
|
66
|
+
- app/models/price.rb
|
67
|
+
- app/models/product.rb
|
68
|
+
- app/models/settings.rb
|
69
|
+
- app/models/spec_rec.rb
|
70
|
+
- app/models/store.rb
|
71
|
+
- app/models/token.rb
|
72
|
+
- app/models/user.rb
|
73
|
+
- app/models/widget.rb
|
74
|
+
- lib/models.rb
|
75
|
+
- lib/models/version.rb
|
76
|
+
- models.gemspec
|
77
|
+
homepage: ''
|
78
|
+
licenses: []
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.24
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Models for ims
|
101
|
+
test_files: []
|