Sha256: d9fe6b1a911abf053bc5cd868a0e2fa1edbb4de38239ad8dea500d330463af8f

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

module ActsAsIcontact
  # The list of criteria attached to every Segment.  Because of this intrinsic association, the usual #find methods don't
  # work; this collection _must_ be obtained using the individual segment's #criteria method.  
  # Unlike other subresources, SegmentCriteria can be created, modified, and saved.
  class SegmentCriteria < Subresource
    
    alias_method :segment, :parent
    
    # fieldName, operator, and values are required
    def self.required_on_create
      super + %w(fieldName operator values)
    end

    # Looks like 'criteria' is just a bit too strange for ActiveSupport to know singulars and plurals...
    def self.resource_name  # :nodoc:
      "criterion"
    end
    
    def self.collection_name  # :nodoc:
      "criteria"
    end
    
    # Uses criterionId as its ID.
    def id
      properties["criterionId"]
    end
    
    
    # operator must be one: eq, lt, lte, gt, gte, bet, notcontains, contains
    def validate_on_save(fields)
      operators = %w(eq lt lte gt gte bet notcontains contains)
      raise ActsAsIcontact::ValidationError, "operator must be one of: " + operators.join(', ') unless operators.include?(fields["operator"])
    end
 
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
SFEley-acts_as_icontact-0.4.2 lib/acts_as_icontact/resources/segment_criteria.rb
SFEley-acts_as_icontact-0.4.3 lib/acts_as_icontact/resources/segment_criteria.rb
acts_as_icontact-0.4.3 lib/acts_as_icontact/resources/segment_criteria.rb
acts_as_icontact-0.4.2 lib/acts_as_icontact/resources/segment_criteria.rb