Guest User

Untitled

a guest
Jan 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. ## filter.rb
  2. class Filter < ActiveRecord::Base
  3. has_many :visitors, :as => :visitable
  4. has_many :conditions, :as => :conditionable, :dependent => :destroy
  5. has_many :assigned_profiles, :as => :assignable, :dependent => :destroy
  6. has_many :site_profiles, :through => :assigned_profiles
  7.  
  8. accepts_nested_attributes_for :conditions, :allow_destroy => true #, :reject_if => proc { |obj| obj.blank? }
  9. accepts_nested_attributes_for :assigned_profiles, :reject_if => lambda { |p| p[:shares].blank? }, :allow_destroy => true
  10.  
  11. validates_uniqueness_of :name
  12.  
  13. acts_as_list
  14.  
  15. default_scope :order => 'position'
  16.  
  17. def total_shares
  18. self.assigned_profiles.where(:active => true).sum('shares')
  19. end
  20. end
  21.  
  22. ## profile_test.rb
  23. class ProfileTest < ActiveRecord::Base
  24. has_many :visitors, :as => :visitable
  25. has_many :conditions, :as => :conditionable, :dependent => :destroy
  26. has_many :assigned_profiles, :as => :assignable, :dependent => :destroy
  27. has_many :site_profiles, :through => :assigned_profiles
  28. has_many :test_runs
  29. belongs_to :current_test_run, :class_name => 'TestRun'
  30.  
  31. accepts_nested_attributes_for :conditions, :allow_destroy => true #, :reject_if => proc { |obj| obj.blank? }
  32. accepts_nested_attributes_for :assigned_profiles, :reject_if => lambda { |p| p[:shares].blank? }, :allow_destroy => true
  33.  
  34. validates_uniqueness_of :name
  35.  
  36. acts_as_list
  37.  
  38. default_scope :order => 'position'
  39.  
  40. def total_shares
  41. self.assigned_profiles.where(:active => true).sum('shares')
  42. end
  43. end
  44.  
  45. ## condition.rb
  46. class Condition < ActiveRecord::Base
  47. belongs_to :conditionable, :polymorphic => true
  48. belongs_to :condition_entryable, :polymorphic => true, :dependent => :destroy
  49.  
  50. default_scope :order => 'condition_entryable_type, matches desc'
  51. end
  52.  
  53. ## condition_country.rb
  54. class ConditionCountry < ActiveRecord::Base
  55. has_one :condition_entry, :as => :condition_entryable, :class_name => 'Condition'
  56. accepts_nested_attributes_for :condition_entry, :allow_destroy => true #, :reject_if => proc { |obj| obj.blank? }
  57.  
  58.  
  59. def type
  60. 'Country'
  61. end
  62. end
  63.  
  64. ## condition_day.rb
  65. class ConditionDay < ActiveRecord::Base
  66. has_one :condition_entry, :as => :condition_entryable, :class_name => 'Condition'
  67. accepts_nested_attributes_for :condition_entry, :allow_destroy => true #, :reject_if => proc { |obj| obj.blank? }
  68.  
  69. def type
  70. 'Day'
  71. end
  72. end
  73.  
  74. ## condition_time.rb
  75. class ConditionTime < ActiveRecord::Base
  76. has_one :condition_entry, :as => :condition_entryable, :class_name => 'Condition'
  77. accepts_nested_attributes_for :condition_entry, :allow_destroy => true #, :reject_if => proc { |obj| obj.blank? }
  78.  
  79. def type
  80. 'Time'
  81. end
  82. end
  83. ## assigned_profile.rb
  84. class AssignedProfile < ActiveRecord::Base
  85. belongs_to :site_profile
  86. belongs_to :assignable, :polymorphic => true
  87.  
  88. validates_presence_of :shares
  89. validates_numericality_of :shares, :only_integer => true, :greater_than => 0
  90.  
  91. def percentage_share_for_object(object)
  92. if self.active
  93. self.shares / object.total_shares * 100
  94. else
  95. 0
  96. end
  97. end
  98. end
  99.  
  100. ## visitor.rb
  101. class Visitor < ActiveRecord::Base
  102.  
  103. has_many :page_views
  104. has_many :certificates
  105. belongs_to :site_profile
  106. belongs_to :visitable, :polymorphic => true
  107.  
  108. end
Add Comment
Please, Sign In to add comment