Class: Activr::Generators::ActivityGenerator
- Inherits:
- 
      Rails::Generators::NamedBase
      
        - Object
- Rails::Generators::NamedBase
- Activr::Generators::ActivityGenerator
 
- Defined in:
- lib/generators/activr/activity_generator.rb
Overview
Generates an Activity subclass in your Rails application
Constant Summary collapse
- DEFAULT_ENTITY_FIELD =
          Default entity humanization method 
- :name
Instance Method Summary collapse
- 
  
    
      #create_activity_file  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Create the activity class file. 
- 
  
    
      #entities_infos  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Compute entities infos. 
- 
  
    
      #humanization  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    Generates a default humanization template. 
Instance Method Details
#create_activity_file ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create the activity class file
| 22 23 24 | # File 'lib/generators/activr/activity_generator.rb', line 22 def create_activity_file template "activity.rb", "#{Activr.config.app_path}/activities/#{file_name}_activity.rb" end | 
#entities_infos ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compute entities infos
| 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | # File 'lib/generators/activr/activity_generator.rb', line 29 def entities_infos entities.map do |str| ary = str.split(':') name = ary[0].underscore klass, set_klass = if ary[1] [ ary[1].camelize, true ] else [ ary[0].camelize, false ] end human_meth = _resolve_entity_field(klass) result = { :name => name, :humanize => human_meth, } result[:class] = klass if set_klass result end end | 
#humanization ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates a default humanization template
| 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # File 'lib/generators/activr/activity_generator.rb', line 57 def humanization result = "" actor = entities_infos.find{ |entity| entity[:name] == 'actor' } if actor result += "{{actor}} " end result += name.underscore.gsub('_', ' ') entities_infos.each do |entity| if entity[:name] != 'actor' result += " {{{#{entity[:name]}}}}" end end result end |