Class: RailsNewsfeed::NewsfeedModel
- Inherits:
-
Object
- Object
- RailsNewsfeed::NewsfeedModel
- Defined in:
- lib/rails_newsfeed/newsfeed_model.rb
Constant Summary collapse
- SALT_KEY =
'fQEEumGosuS92VcVVMPm'.freeze
- SECRET_KEY =
'sL6PySf7Ijo8L0ZhU7R2'.freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#next_page_token ⇒ Object
readonly
Returns the value of attribute next_page_token.
Class Method Summary collapse
-
.delete(id, act_id = nil, related = false) ⇒ Object
deletes by id.
-
.feeds(id, page_size = 10, next_page_token = nil) ⇒ Object
gets feeds by id.
- .from_cass_act(id, res) ⇒ Object
-
.insert(id, activity, related = true, hide_old = true) ⇒ Object
inserts.
-
.schema ⇒ Object
gets schema DO NOT override this method unless you know what you are doing.
-
.table_name ⇒ Object
gets table name.
-
.type_of_id(type) ⇒ Object
sets type of id.
Instance Method Summary collapse
-
#after_feeds ⇒ Object
overrides this method to implement your own.
-
#delete(act_id = nil, related = true) ⇒ Object
deletes an activity or all activities from this feed.
-
#deregister(to, options = {}) ⇒ Object
deregisters to another.
-
#feeds(page_size = 10) ⇒ Object
gets feeds.
-
#initialize(options = {}) ⇒ NewsfeedModel
constructor
initializes.
-
#insert(activity, related = true, hide_old = true) ⇒ Object
inserts an activity into table.
-
#register(to, options = {}) ⇒ Object
registers to another.
-
#register?(to) ⇒ Boolean
checks related.
Constructor Details
#initialize(options = {}) ⇒ NewsfeedModel
initializes
49 50 51 52 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 49 def initialize( = {}) @id = .key?(:id) ? [:id] : nil @next_page_token = .key?(:next_page_token) ? [:next_page_token] : nil end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 9 def id @id end |
#next_page_token ⇒ Object (readonly)
Returns the value of attribute next_page_token.
10 11 12 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 10 def next_page_token @next_page_token end |
Class Method Details
.delete(id, act_id = nil, related = false) ⇒ Object
deletes by id
34 35 36 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 34 def self.delete(id, act_id = nil, = false) new(id: id).delete(act_id, ) end |
.feeds(id, page_size = 10, next_page_token = nil) ⇒ Object
gets feeds by id
39 40 41 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 39 def self.feeds(id, page_size = 10, next_page_token = nil) new(id: id, next_page_token: next_page_token).feeds(page_size) end |
.from_cass_act(id, res) ⇒ Object
43 44 45 46 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 43 def self.from_cass_act(id, res) { id: id, activity_id: res['id'].to_s, activity_content: res['content'], activity_object: res['object'], activity_time: res['time'].to_s } end |
.insert(id, activity, related = true, hide_old = true) ⇒ Object
inserts
29 30 31 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 29 def self.insert(id, activity, = true, hide_old = true) new(id: id).insert(activity, , hide_old) end |
.schema ⇒ Object
gets schema DO NOT override this method unless you know what you are doing
24 25 26 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 24 def self.schema { id: id_type, activity_id: :uuid, activity_content: :text, activity_object: :text, activity_time: :timestamp } end |
.table_name ⇒ Object
gets table name
18 19 20 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 18 def self.table_name name.demodulize.underscore end |
.type_of_id(type) ⇒ Object
sets type of id
13 14 15 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 13 def self.type_of_id(type) self.id_type = type end |
Instance Method Details
#after_feeds ⇒ Object
overrides this method to implement your own
109 110 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 109 def after_feeds end |
#delete(act_id = nil, related = true) ⇒ Object
deletes an activity or all activities from this feed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 77 def delete(act_id = nil, = true) tbl = self.class.table_name schema = self.class.schema if act_id return Activity.delete(act_id, true) if return Connection.delete(tbl, schema, id: @id, activity_id: act_id) end cqls = [] Connection.select(tbl, schema, '*', id: @id).each do |r| if Activity.delete(r['id'].to_s, true) else cqls.push(Connection.delete(tbl, schema, { id: @id, activity_id: r['id'].to_s }, true)) end end Connection.batch_cqls(cqls.uniq) true end |
#deregister(to, options = {}) ⇒ Object
deregisters to another
118 119 120 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 118 def deregister(to, = {}) Relation.delete(to, self, ) end |
#feeds(page_size = 10) ⇒ Object
gets feeds
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 97 def feeds(page_size = 10) @feeds = [] = { page_size: page_size.to_i } [:paging_state] = decoded_next_page_token if @next_page_token result = Connection.select(self.class.table_name, self.class.schema, '*', { id: @id }, ) result.each { |r| @feeds.push(Activity.create_from_cass(:feed, r)) } encoded_next_page_token(result) after_feeds @feeds end |
#insert(activity, related = true, hide_old = true) ⇒ Object
inserts an activity into table
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 55 def insert(activity, = true, hide_old = true) record = { id: @id, activity_id: activity.id, activity_content: activity.content, activity_object: activity.object, activity_time: activity.time } Connection.insert(self.class.table_name, self.class.schema, record) ins_arr = [] cqls = [] if Relation.(self).each do |ins| record[:id] = ins.id cqls.push(Connection.insert(ins.class.table_name, ins.class.schema, record, true)) ins_arr.push(ins) if hide_old end end if hide_old ins_arr.push(self) cqls |= cql_hide_old_feeds_of(activity, ins_arr) end Connection.batch_cqls(cqls) true end |
#register(to, options = {}) ⇒ Object
registers to another
113 114 115 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 113 def register(to, = {}) Relation.create(to, self, ) end |
#register?(to) ⇒ Boolean
checks related
123 124 125 |
# File 'lib/rails_newsfeed/newsfeed_model.rb', line 123 def register?(to) Relation.(to, self) end |