Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## filter.rb
- class Filter < ActiveRecord::Base
- has_many :visitors, :as => :visitable
- has_many :conditions, :as => :conditionable, :dependent => :destroy
- has_many :assigned_profiles, :as => :assignable, :dependent => :destroy
- has_many :site_profiles, :through => :assigned_profiles
- accepts_nested_attributes_for :conditions, :allow_destroy => true #, :reject_if => proc { |obj| obj.blank? }
- accepts_nested_attributes_for :assigned_profiles, :reject_if => lambda { |p| p[:shares].blank? }, :allow_destroy => true
- validates_uniqueness_of :name
- acts_as_list
- default_scope :order => 'position'
- def total_shares
- self.assigned_profiles.where(:active => true).sum('shares')
- end
- end
- ## profile_test.rb
- class ProfileTest < ActiveRecord::Base
- has_many :visitors, :as => :visitable
- has_many :conditions, :as => :conditionable, :dependent => :destroy
- has_many :assigned_profiles, :as => :assignable, :dependent => :destroy
- has_many :site_profiles, :through => :assigned_profiles
- has_many :test_runs
- belongs_to :current_test_run, :class_name => 'TestRun'
- accepts_nested_attributes_for :conditions, :allow_destroy => true #, :reject_if => proc { |obj| obj.blank? }
- accepts_nested_attributes_for :assigned_profiles, :reject_if => lambda { |p| p[:shares].blank? }, :allow_destroy => true
- validates_uniqueness_of :name
- acts_as_list
- default_scope :order => 'position'
- def total_shares
- self.assigned_profiles.where(:active => true).sum('shares')
- end
- end
- ## condition.rb
- class Condition < ActiveRecord::Base
- belongs_to :conditionable, :polymorphic => true
- belongs_to :condition_entryable, :polymorphic => true, :dependent => :destroy
- default_scope :order => 'condition_entryable_type, matches desc'
- end
- ## condition_country.rb
- class ConditionCountry < ActiveRecord::Base
- has_one :condition_entry, :as => :condition_entryable, :class_name => 'Condition'
- accepts_nested_attributes_for :condition_entry, :allow_destroy => true #, :reject_if => proc { |obj| obj.blank? }
- def type
- 'Country'
- end
- end
- ## condition_day.rb
- class ConditionDay < ActiveRecord::Base
- has_one :condition_entry, :as => :condition_entryable, :class_name => 'Condition'
- accepts_nested_attributes_for :condition_entry, :allow_destroy => true #, :reject_if => proc { |obj| obj.blank? }
- def type
- 'Day'
- end
- end
- ## condition_time.rb
- class ConditionTime < ActiveRecord::Base
- has_one :condition_entry, :as => :condition_entryable, :class_name => 'Condition'
- accepts_nested_attributes_for :condition_entry, :allow_destroy => true #, :reject_if => proc { |obj| obj.blank? }
- def type
- 'Time'
- end
- end
- ## assigned_profile.rb
- class AssignedProfile < ActiveRecord::Base
- belongs_to :site_profile
- belongs_to :assignable, :polymorphic => true
- validates_presence_of :shares
- validates_numericality_of :shares, :only_integer => true, :greater_than => 0
- def percentage_share_for_object(object)
- if self.active
- self.shares / object.total_shares * 100
- else
- 0
- end
- end
- end
- ## visitor.rb
- class Visitor < ActiveRecord::Base
- has_many :page_views
- has_many :certificates
- belongs_to :site_profile
- belongs_to :visitable, :polymorphic => true
- end
Add Comment
Please, Sign In to add comment