ish_models 0.0.33.135 → 0.0.33.136

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
  SHA256:
3
- metadata.gz: 6c5a6043e8144f6fae57963f58a0880eb171044ae3bbc62d36ae013c0db3be04
4
- data.tar.gz: e3414aeaba21e5273054e14d8bf037ec798418c1a97a894e5861d8811ef2d224
3
+ metadata.gz: 172ea3b5881a62b2d1c4ef8bed4360782c6f9676eaa39c1be7e9febab7e8937b
4
+ data.tar.gz: ba242d1b5cc551a2257a0c2183413f1a9cebd5448cc570629761cb69e9e99863
5
5
  SHA512:
6
- metadata.gz: b2154545c111a45447bfa2bd1421e65afe4b68b17368fedf0de098e4cace9ea03cc9db25e3c0e7cd9f8b380a270fe7ce75b0544d8fa66d233ca4800e19046ee2
7
- data.tar.gz: 99a571b6c35ed885e7b204dc922f5289451d0d4dc3d01ce1dd6f03a970dddf9b1c297d815353853c85c319c0ca60f0c22bff36ca37d3ef60a20476a926c6c16a
6
+ metadata.gz: c849a3a2b774e4290e10e28b83561f11d85eb0ed316acc2118ad8ff6188d2d7c902b7bab1e0e192f4010a6ab9f1bafafec3ecaaecf47029084c9fcce43da2c34
7
+ data.tar.gz: 5c8641248d523733c55643e8fe3ee95c4aa75cd4b7257684b60d4d48735e1a68187015abd7dbbda3558964f6c97c090a12fba4de3deab8081e952501bcec3e1d
data/lib/city.rb CHANGED
@@ -36,7 +36,7 @@ class City
36
36
  has_one :profile_photo, :class_name => 'Photo', :inverse_of => :profile_city
37
37
  has_one :guide, :class_name => '::IshModels::UserProfile', :inverse_of => :guide_city
38
38
 
39
- embeds_many :features
39
+ has_many :features
40
40
 
41
41
  field :calendar_frame, :type => String
42
42
  field :is_active, type: Boolean, default: true
data/lib/feature.rb CHANGED
@@ -1,31 +1,25 @@
1
1
 
2
- class Feature
3
-
2
+ class Feature
4
3
  include Mongoid::Document
5
4
  include Mongoid::Timestamps
6
5
 
7
- field :name, :type => String
8
- field :subhead, :type => String
6
+ field :name
7
+ field :subhead
9
8
 
10
- field :image_path, :type => String
11
- field :link_path, :type => String
12
- field :partial_name, :type => String
13
- field :inner_html, :type => String
14
- field :weight, :type => Integer, :default => 10
15
-
16
- belongs_to :photo, :optional => true
17
- belongs_to :report, :optional => true
18
- belongs_to :gallery, :optional => true
19
- belongs_to :video, :optional => true
20
- # has_one :photo
21
- # has_one :report
22
- # has_one :gallery
23
- # has_one :video
9
+ field :image_path
10
+ field :link_path
11
+ field :partial_name
12
+ field :inner_html
13
+ field :weight, type: Integer, default: 10
24
14
 
25
- embedded_in :venue
26
- embedded_in :site
27
- embedded_in :city
28
- embedded_in :tag
15
+ belongs_to :city, optional: true
16
+ belongs_to :gallery, optional: true
17
+ belongs_to :photo, optional: true
18
+ belongs_to :report, optional: true
19
+ belongs_to :site, optional: true
20
+ belongs_to :tag, optional: true
21
+ belongs_to :video, optional: true
22
+ belongs_to :venue, optional: true
29
23
 
30
24
  def self.all
31
25
  self.order_by( :created_at => :desc )
@@ -34,5 +28,5 @@ class Feature
34
28
  def self.n_features
35
29
  4
36
30
  end
37
-
31
+
38
32
  end
data/lib/gameui/map.rb CHANGED
@@ -4,7 +4,7 @@ class ::Gameui::Map
4
4
  include Mongoid::Timestamps
5
5
 
6
6
  has_many :markers, :class_name => '::Gameui::Marker', inverse_of: :map
7
- has_many :newsitems, inverse_of: :map
7
+ has_many :newsitems, inverse_of: :map, order: :created_at.desc
8
8
 
9
9
  field :slug
10
10
  validates :slug, uniqueness: true, presence: true
@@ -24,6 +24,12 @@ class ::Gameui::Map
24
24
  field :name
25
25
  field :description
26
26
 
27
+ ## Possible keys: description, map, markers, newsitems,
28
+ field :labels, type: Object, default: {}
29
+ ## Possible keys:
30
+ ## config.description.collapsible
31
+ field :config, type: Object, default: {}
32
+
27
33
  # @deprecated, dont use!
28
34
  field :img_path
29
35
 
data/lib/ish/utils.rb ADDED
@@ -0,0 +1,25 @@
1
+
2
+ module Ish::Utils
3
+
4
+ private
5
+
6
+ def set_slug
7
+ return if slug
8
+ new_slug = name.downcase.gsub(/[^a-z0-9\s]/i, '').gsub(' ', '-')
9
+ if self.class.where( slug: new_slug ).first
10
+ loop do
11
+ if new_slug[new_slug.length-1].to_i != 0
12
+ # inrement last digit
13
+ last_digit = new_slug[new_slug.length-1].to_i
14
+ new_slug = "#{new_slug[0...new_slug.length-1]}#{last_digit+1}"
15
+ else
16
+ # add '-1' to the end
17
+ new_slug = "#{new_slug}-1"
18
+ end
19
+ break if !self.class.where( slug: new_slug ).first
20
+ end
21
+ end
22
+ self.slug = new_slug
23
+ end
24
+
25
+ end
data/lib/ish_models.rb CHANGED
@@ -34,23 +34,24 @@ require 'gameui/map_bookmark.rb'
34
34
  require 'gameui/marker.rb'
35
35
  require 'gameui/premium_purchase.rb'
36
36
 
37
+ # require 'ish/alphavantage_stockwatcher.rb'
37
38
  require 'ish/ameritrade'
39
+ require 'ish/campaign.rb'
38
40
  require 'ish/covered_call'
39
41
  require 'ish/crawler.rb'
40
42
  require 'ish/gallery_name.rb'
41
43
  require 'ish/image_asset.rb'
42
44
  require 'ish/input_error.rb'
45
+ require 'ish/invoice.rb'
43
46
  require 'ish/iron_condor.rb'
44
47
  require 'ish/iron_condor_watcher.rb'
48
+ require 'ish/issue.rb'
49
+ require 'ish/lead.rb'
45
50
  require 'ish/payment.rb'
46
51
  require 'ish/stock_action.rb'
47
52
  require 'ish/stock_option.rb'
48
53
  require 'ish/stock_watch.rb'
49
- # require 'ish/alphavantage_stockwatcher.rb'
50
- require 'ish/invoice.rb'
51
- require 'ish/lead.rb'
52
- require 'ish/campaign.rb'
53
- require 'ish/issue.rb'
54
+ require 'ish/utils.rb'
54
55
  require 'ish/yahoo_stockwatcher.rb'
55
56
 
56
57
  # obsolete, use `ish` namespace now
data/lib/newsitem.rb CHANGED
@@ -20,6 +20,10 @@ class Newsitem
20
20
 
21
21
  field :name
22
22
  field :descr
23
+ def description
24
+ descr
25
+ end
26
+
23
27
  field :image_path
24
28
  field :link_path
25
29
  field :username
data/lib/report.rb CHANGED
@@ -1,20 +1,24 @@
1
1
  class Report
2
2
  include ::Mongoid::Document
3
3
  include ::Mongoid::Timestamps
4
+ include Ish::Utils
4
5
 
5
6
  field :name, :type => String
6
7
  validates :name, :presence => true
7
8
  # index({ :name => 1 }, { :unique => true })
8
9
  index({ :name => 1, :is_trash => 1 })
9
10
 
10
- field :name_seo, :type => String
11
- validates :name_seo, :uniqueness => true, :presence => true
12
- index({ :name_seo => 1 }, { :unique => true })
11
+ field :slug
12
+ validates :slug, :uniqueness => true, :presence => true
13
+ index({ :slug => 1 }, { :unique => true })
13
14
 
14
- field :descr, :type => String
15
+ ## Can be one of: default (nil), longscroll
16
+ field :item_type, type: String
17
+
18
+ field :descr, :type => String
15
19
 
16
20
  field :is_trash, :type => Boolean, :default => false
17
- index :is_trash => 1, :is_public => 1
21
+ index :is_trash => 1, :is_public => 1
18
22
 
19
23
  field :is_public, :type => Boolean, :default => true
20
24
  index({ :is_public => 1 })
@@ -27,13 +31,13 @@ class Report
27
31
 
28
32
  field :is_done, :type => Boolean, :default => true
29
33
  index({ :is_done => 1 })
30
-
34
+
31
35
  field :x, :type => Float
32
36
  field :y, :type => Float
33
37
 
34
38
  field :lang, :type => String, :default => 'en'
35
39
  index({ :lang => 1 })
36
-
40
+
37
41
  belongs_to :user_profile, :optional => true, :class_name => 'IshModels::UserProfile'
38
42
 
39
43
  # validates :user, :presence => true, :allow_nil => false
@@ -43,14 +47,14 @@ class Report
43
47
 
44
48
  field :issue
45
49
  field :subhead
46
-
50
+
47
51
  belongs_to :city, :optional => true
48
52
  belongs_to :site, :optional => true
49
53
  belongs_to :cities_user, :optional => true
50
54
 
51
55
  has_and_belongs_to_many :tags
52
56
  has_and_belongs_to_many :venues
53
-
57
+
54
58
  has_one :photo
55
59
 
56
60
  field :n_upvotes, :default => 0
@@ -59,15 +63,15 @@ class Report
59
63
  default_scope ->{
60
64
  where({ is_public: true, is_trash: false }).order_by({ created_at: :desc })
61
65
  }
62
-
66
+
63
67
  has_many :newsitems
64
68
 
65
69
  def self.list conditions = { :is_trash => false }
66
70
  out = self.where( conditions ).order_by( :name => :asc ).limit( 100 )
67
71
  [['', nil]] + out.map { |item| [ item.name, item.id ] }
68
72
  end
69
-
70
- PER_PAGE = 20
73
+
74
+ PER_PAGE = 20
71
75
  def self.paginates_per
72
76
  self::PER_PAGE
73
77
  end
@@ -75,33 +79,30 @@ class Report
75
79
  def venue
76
80
  return self.venues[0] || nil
77
81
  end
78
-
82
+
79
83
  def self.all
80
84
  self.where( :is_public => true, :is_trash => false ).order_by( :created_at => :desc )
81
85
  end
82
-
86
+
83
87
  def self.not_tagged
84
88
  Report.where( :tag_ids => nil, :city => nil )
85
89
  end
86
-
90
+
87
91
  def self.for_homepage args
88
92
  begin
89
93
  tag_ids = args[:main_tag].children_tags.map { |tag| tag._id } + [ args[:main_tag]._id ]
90
94
  return Report.where( :tag_ids.in => tag_ids ).page args[:page]
91
95
  rescue
92
- return Report.page args[:page]
96
+ return Report.page args[:page]
93
97
  end
94
98
  end
95
99
 
96
- before_validation :set_name_seo, :on => :create
97
- def set_name_seo
98
- self.name_seo ||= self.name.gsub(' ', '-').gsub('.', '')
99
- end
100
+ before_validation :set_slug, :on => :create
100
101
 
101
102
  set_callback :update, :after do |doc|
102
103
  Site.update_all updated_at: Time.now
103
104
  end
104
-
105
+
105
106
  set_callback :create, :after do |doc|
106
107
  if doc.is_public
107
108
 
@@ -115,7 +116,7 @@ class Report
115
116
  v.newsitems << n
116
117
  v.save
117
118
  end
118
- end
119
+ end
119
120
 
120
121
  unless doc.city.blank?
121
122
  city = City.find doc.city.id
@@ -131,7 +132,7 @@ class Report
131
132
  end
132
133
  end
133
134
  end
134
-
135
+
135
136
  def self.clear
136
137
  if Rails.env.test?
137
138
  self.unscoped.each { |r| r.remove }
@@ -149,5 +150,5 @@ class Report
149
150
  end
150
151
  def premium?; is_premium; end
151
152
  has_many :premium_purchases, class_name: '::Gameui::PremiumPurchase', as: :item
152
-
153
+
153
154
  end
data/lib/site.rb CHANGED
@@ -30,7 +30,7 @@ class Site
30
30
  field :is_primary, :type => Boolean, :default => false
31
31
  field :is_private, :type => Boolean, :default => false
32
32
  field :private_user_emails, :type => Array, :default => []
33
-
33
+
34
34
  field :homepage_layout, :type => String, :default => 'show'
35
35
  field :layout, :type => String, :default => 'application'
36
36
 
@@ -40,9 +40,8 @@ class Site
40
40
  has_many :videos
41
41
  has_many :newsitems, :order => :created_at.desc
42
42
  has_many :issues, :class_name => 'Ish::Issue'
43
+ has_many :features, :order => :created_at.desc
43
44
 
44
- embeds_many :features, :order => :created_at.desc
45
-
46
45
  default_scope ->{ where({ :is_trash => false }).order_by({ :domain => :asc, :lang => :asc }) }
47
46
 
48
47
  set_callback :create, :before do |doc|
@@ -61,7 +60,7 @@ class Site
61
60
  end
62
61
 
63
62
  LANGUAGES = [ 'en', 'ru', 'pt' ]
64
-
63
+
65
64
  # manager uses it.
66
65
  def self.list
67
66
  out = self.all.order_by( :domain => :asc, :lang => :asc )
@@ -79,7 +78,7 @@ class Site
79
78
  def n_private_reports
80
79
  self.reports.unscoped.where( :is_public => false, :is_trash => false ).length
81
80
  end
82
-
81
+
83
82
  def its_locales
84
83
  Site.where( :domain => self.domain ).map { |s| s.lang.to_sym }
85
84
  end
data/lib/tag.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  class Tag
2
2
  include Mongoid::Document
3
3
  include Mongoid::Timestamps
4
+ include Ish::Utils
4
5
 
5
6
  field :name, :type => String
6
7
  # validates :name, :uniqueness => true, :allow_nil => false
7
8
 
8
- field :name_seo, :as => :tagname
9
- validates :name_seo, :uniqueness => true, :allow_nil => false
9
+ field :slug
10
+ validates :slug, :uniqueness => true, presence: true, allow_nil: false
10
11
 
11
12
  field :descr, :type => String, :default => ''
12
13
 
@@ -19,8 +20,7 @@ class Tag
19
20
  has_many :children_tags, :class_name => 'Tag', :inverse_of => :parent_tag
20
21
  belongs_to :parent_tag, :class_name => 'Tag', :inverse_of => :children_tags, :optional => true
21
22
 
22
- embeds_many :features
23
- # embeds_many :newsitems
23
+ has_many :features
24
24
  has_many :newsitems
25
25
 
26
26
  belongs_to :site, :optional => true
@@ -36,11 +36,7 @@ class Tag
36
36
  where({ :is_public => true, :is_trash => false }).order_by({ :name => :asc })
37
37
  }
38
38
 
39
- before_create do |d|
40
- if d.name_seo.blank?
41
- d.name_seo = d.name.gsub(' ', '-')
42
- end
43
- end
39
+ before_validation :set_slug
44
40
 
45
41
  def self.clear
46
42
  if Rails.env.test?
@@ -72,9 +68,9 @@ class Tag
72
68
  4
73
69
  end
74
70
 
75
- # @deprecated I don't even know why I have this. Should be simplified into non-being.
76
71
  def self.n_features
77
72
  4
78
73
  end
74
+ field :n_features, type: Integer, default: 4
79
75
 
80
76
  end
data/lib/venue.rb CHANGED
@@ -1,14 +1,16 @@
1
1
  class Venue
2
2
  include ::Mongoid::Document
3
3
  include ::Mongoid::Timestamps
4
+ include Ish::Utils
4
5
 
5
6
  field :address
6
7
 
7
8
  field :name, :type => String
8
9
  validates :name, :uniqueness => true, :allow_nil => false
9
10
 
10
- field :name_seo, :type => String
11
- validates :name_seo, :uniqueness => true, :allow_nil => false
11
+ field :slug
12
+ validates :slug, :uniqueness => true, :allow_nil => false
13
+ before_validation :set_slug
12
14
 
13
15
  field :subhead
14
16
  field :descr
@@ -41,9 +43,8 @@ class Venue
41
43
  has_many :reports
42
44
  has_many :galleries
43
45
  has_many :photos
44
-
45
- embeds_many :newsitems
46
- embeds_many :features
46
+ has_many :newsitems
47
+ has_many :features
47
48
 
48
49
  PER_PAGE = 6
49
50
 
@@ -52,9 +53,7 @@ class Venue
52
53
  [['', nil]] + out.map { |item| [ item.name, item.id ] }
53
54
  end
54
55
 
55
- set_callback :create, :before do |doc|
56
- doc.name_seo = doc.name.gsub(' ', '-')
57
- end
56
+
58
57
 
59
58
  set_callback :save, :before do |doc|
60
59
  if doc.city
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33.135
4
+ version: 0.0.33.136
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
@@ -137,6 +137,7 @@ files:
137
137
  - lib/ish/stock_action.rb
138
138
  - lib/ish/stock_option.rb
139
139
  - lib/ish/stock_watch.rb
140
+ - lib/ish/utils.rb
140
141
  - lib/ish/yahoo_stockwatcher.rb
141
142
  - lib/ish_models.rb
142
143
  - lib/ish_models/cache_key.rb