Class: DistyllModelProfile
- Inherits:
-
Object
- Object
- DistyllModelProfile
- Defined in:
- lib/distyll.rb
Instance Attribute Summary collapse
-
#all_ids ⇒ Object
readonly
Returns the value of attribute all_ids.
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#last_ids ⇒ Object
readonly
Returns the value of attribute last_ids.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#new_ids ⇒ Object
readonly
Returns the value of attribute new_ids.
-
#record_count ⇒ Object
readonly
Returns the value of attribute record_count.
Instance Method Summary collapse
- #copy_records ⇒ Object
- #demote_new_ids ⇒ Object
- #get_id_count ⇒ Object
- #get_new_associated_ids(a) ⇒ Object
-
#initialize(m) ⇒ DistyllModelProfile
constructor
A new instance of DistyllModelProfile.
- #load_ids(ids) ⇒ Object
- #load_ids_by_timestamp(timestamp) ⇒ Object
Constructor Details
#initialize(m) ⇒ DistyllModelProfile
Returns a new instance of DistyllModelProfile.
63 64 65 66 67 68 69 70 |
# File 'lib/distyll.rb', line 63 def initialize(m) @model = m @record_count = m.count @all_ids = Array.new @last_ids = Array.new @new_ids = Array.new set_associations end |
Instance Attribute Details
#all_ids ⇒ Object (readonly)
Returns the value of attribute all_ids.
61 62 63 |
# File 'lib/distyll.rb', line 61 def all_ids @all_ids end |
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
61 62 63 |
# File 'lib/distyll.rb', line 61 def associations @associations end |
#last_ids ⇒ Object (readonly)
Returns the value of attribute last_ids.
61 62 63 |
# File 'lib/distyll.rb', line 61 def last_ids @last_ids end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
61 62 63 |
# File 'lib/distyll.rb', line 61 def model @model end |
#new_ids ⇒ Object (readonly)
Returns the value of attribute new_ids.
61 62 63 |
# File 'lib/distyll.rb', line 61 def new_ids @new_ids end |
#record_count ⇒ Object (readonly)
Returns the value of attribute record_count.
61 62 63 |
# File 'lib/distyll.rb', line 61 def record_count @record_count end |
Instance Method Details
#copy_records ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/distyll.rb', line 97 def copy_records return nil if all_ids.blank? records = model.where(id: all_ids).load model.establish_connection("distyll") records.each { |record| model.new(record.attributes).save!(validate: false) } model.establish_connection(Rails.env) records end |
#demote_new_ids ⇒ Object
72 73 74 75 |
# File 'lib/distyll.rb', line 72 def demote_new_ids @last_ids = @new_ids @new_ids = Array.new end |
#get_id_count ⇒ Object
88 89 90 91 |
# File 'lib/distyll.rb', line 88 def get_id_count @all_ids = @all_ids.uniq || [] @all_ids.count end |
#get_new_associated_ids(a) ⇒ Object
93 94 95 |
# File 'lib/distyll.rb', line 93 def get_new_associated_ids(a) model.where(id: last_ids).select(a.foreign_key).map { |r| r.send(a.foreign_key) } end |
#load_ids(ids) ⇒ Object
83 84 85 86 |
# File 'lib/distyll.rb', line 83 def load_ids(ids) @new_ids += ids @all_ids += ids end |
#load_ids_by_timestamp(timestamp) ⇒ Object
77 78 79 80 81 |
# File 'lib/distyll.rb', line 77 def () ids = model.where("created_at >= ?", ).select(:id).map &:id @new_ids += ids @all_ids += ids end |