Class: MoleFeature

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/mole/models/mole_feature.rb

Overview

Feature model - Tracks the various application features in the db.

Class Method Summary collapse

Class Method Details

.allObject

famous constants…



7
# File 'lib/mole/models/mole_feature.rb', line 7

def all()         "ALL"        ; end

.exceptionObject



8
# File 'lib/mole/models/mole_feature.rb', line 8

def exception()   "Exception"  ; end

.find_all_feature(app_name) ⇒ Object

Find the all feature ( wildcard feature for given app )



22
23
24
# File 'lib/mole/models/mole_feature.rb', line 22

def find_all_feature( app_name )
  find_or_create_feature( all, app_name )
end

.find_exception_feature(app_name) ⇒ Object

find exception feature



17
18
19
# File 'lib/mole/models/mole_feature.rb', line 17

def find_exception_feature( app_name )         
  find_or_create_feature( exception, app_name )
end

.find_features(app_name) ⇒ Object

Finds all the features available for a given application



35
36
37
38
39
40
41
42
# File 'lib/mole/models/mole_feature.rb', line 35

def find_features( app_name )       
  # Creates the all feature if necessary    
  find_all_feature( app_name )
  find( :all, 
        :conditions => ["app_name = ?", app_name], 
        :select     => "id, name, context", 
        :order      => "name asc" )      
end

.find_moled_application_namesObject

Find all the MOled applications



27
28
29
30
31
32
# File 'lib/mole/models/mole_feature.rb', line 27

def find_moled_application_names
  res = find( :all, 
              :select => "distinct( app_name )", 
              :order  => "name asc" )            
  res.map(&:app_name)             
end

.find_or_create_feature(name, app_name, ctx_name = nil) ⇒ Object

locates an existing feature or create a new one if it does not exist.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mole/models/mole_feature.rb', line 45

def find_or_create_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                          
  if ctx_name      
    res = find_by_name_and_context_and_app_name( name, ctx_name, app_name )
  else
    res = find_by_name_and_app_name( name, app_name )
  end
  res || create(:name => name,:context => ctx_name, :app_name => app_name )
end

.find_performance_feature(app_name) ⇒ Object

find performance feature



12
13
14
# File 'lib/mole/models/mole_feature.rb', line 12

def find_performance_feature( app_name )
  find_or_create_feature( performance, app_name )
end

.performanceObject



9
# File 'lib/mole/models/mole_feature.rb', line 9

def performance() "Performance"; end