Class: TerminalProfile
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- TerminalProfile
- Includes:
- Redis::Objects::RMap
- Defined in:
- app/models/terminal_profile.rb
Class Method Summary collapse
Instance Method Summary collapse
- #actual_timestamp ⇒ Object
- #actualize_links! ⇒ Object
- #invalidate_cached_providers! ⇒ Object
- #promotions_dump ⇒ Object
- #provider_groups_dump ⇒ Object
- #providers_dump ⇒ Object
Class Method Details
.as_hash(fields) ⇒ Object
24 25 26 27 28 |
# File 'app/models/terminal_profile.rb', line 24 def self.as_hash(fields) connection.select_all(select(fields).arel).each do |attrs| yield(attrs) if block_given? end end |
.invalidate_all_cached_providers! ⇒ Object
40 41 42 |
# File 'app/models/terminal_profile.rb', line 40 def self.invalidate_all_cached_providers! TerminalProfile.all.each(&:invalidate_cached_providers!) end |
Instance Method Details
#actual_timestamp ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'app/models/terminal_profile.rb', line 51 def = self..value if .nil? # Redis is not populated yet self..value = = DateTime.now end end |
#actualize_links! ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/models/terminal_profile.rb', line 30 def actualize_links! ProviderGroup.where(ProviderGroup.arel_table[:id].not_in TerminalProfileProviderGroup.arel_table.project(:provider_group_id)).each do |pg| terminal_profile_provider_groups << TerminalProfileProviderGroup.new(:provider_group_id => pg.id, :terminal_profile_id => id) end Provider.where(Provider.arel_table[:id].not_in TerminalProfileProvider.arel_table.project(:provider_id)).each do |p| terminal_profile_providers << TerminalProfileProvider.new(:provider_id => p.id, :terminal_profile_id => id) end end |
#invalidate_cached_providers! ⇒ Object
44 45 46 47 48 49 |
# File 'app/models/terminal_profile.rb', line 44 def invalidate_cached_providers! self.cached_providers_lock.lock do self.cached_providers.value = nil self..value = DateTime.now end end |
#promotions_dump ⇒ Object
90 91 92 |
# File 'app/models/terminal_profile.rb', line 90 def promotions_dump self.terminal_profile_promotions.map &:provider_id end |
#provider_groups_dump ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/terminal_profile.rb', line 94 def provider_groups_dump overload = Hash[self.terminal_profile_provider_groups.map{|x| [x.provider_group_id, x]}] ProviderGroup.all.map do |x| icon = overload[x.id].icon rescue nil if icon.blank? icon = x.icon.try(:url) else icon = icon.url end { :id => x.id, :title => x.title, :icon => icon, :priority => overload[x.id].try(:priority), :parent_id => x.provider_group_id } end end |
#providers_dump ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/terminal_profile.rb', line 61 def providers_dump providers = Provider.includes(:provider_fields) return [] if providers.blank? overload = Hash[self.terminal_profile_providers.map{|x| [x.provider_id, x]}] providers.map do |x| icon = overload[x.id].icon rescue nil if icon.blank? icon = x.icon.try(:url) else icon = icon.url end { :id => x.id, :title => x.title, :keyword => x.keyword, :icon => icon, :priority => overload[x.id].try(:priority), :fields => x.fields_dump, :group_id => x.provider_group_id, :requires_print => x.requires_print } end end |