Sha256: f46c2347fbf9fc3e4e31758ac214e28d429b0d23fd1908ea0a3e442d924f7551

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

# Feature model - Tracks the various application features in the db.
class MoleFeature < ActiveRecord::Base
  has_many :mole_logs    
        
  class << self     
    # famous constants...  
    def all()         "ALL"        ; end
    def exception()   "Exception"  ; end
    def performance() "Performance"; end  
    
    # find performance feature
    def find_performance_feature( app_name )
      find_feature( performance, app_name )
    end
                                 
    # find exception feature
    def find_exception_feature( app_name )         
      find_feature( exception, app_name )
    end
    
    def find_all_feature( app_name )
      find_feature( all, app_name )
    end
             
    # Finds all the features available for a given application
    def find_features( app_name )       
      # Creates the all feature if necessary    
      find_all_feature( app_name )
      MoleFeature.find( :all, 
                        :conditions => ["app_name = ?", app_name], 
                        :select     => "id, name, context", 
                        :order      => "name asc" )      
    end
      
    # locates an existing feature or create a new one
    def find_feature( name, app_name, ctx_name=nil )
      if name.nil? or name.empty? 
        ::Mole.logger.error( "--- MOLE ERROR - Invalid feature. Empty or nil" ) 
        return nil
      end                                
      find_by_name_and_context_and_app_name( name, ctx_name, app_name ) ||     
      create(:name => name,:context => ctx_name, :app_name => app_name )
    end   
  end
end               

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mole-0.0.1 lib/mole/models/mole_feature.rb