Class: Puer::Generators::Search

Inherits:
Jam
  • Object
show all
Includes:
CLIColorize, Actions, Thor::Actions
Defined in:
lib/puer/generators/search.rb

Constant Summary collapse

RENDER_OPTIONS =
{ :fields => [:category,:command,:description] }

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Actions

#apply_component_for, #ask, #check_app_existence, #destination_root, #execute_component_setup, #fetch_app_name, #fetch_component_choice, included, #invalid_fields, #resolve_valid_choice, #retrieve_component_config, #store_component_choice, #store_component_config, #valid_choice?, #valid_constant?, #which

Methods inherited from Jam

attr_rw, #create_jam, init_generator, parseTemplate

Class Method Details



21
# File 'lib/puer/generators/search.rb', line 21

def self.banner; "puer search [option]"; end

.source_rootObject

Define the source root



20
# File 'lib/puer/generators/search.rb', line 20

def self.source_root; File.expand_path(File.dirname(__FILE__)); end

Instance Method Details

#create_searchObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/puer/generators/search.rb', line 36

def create_search
  valid_constant?(options[:search] || name)
  @gist_name = (options[:app] || name).gsub(/W/, "_").downcase
  @gist_class_name = (options[:app] || name).gsub(/W/, "_").capitalize
  @developer = "eiffel"
  @created_on = Date.today.to_s
  self.destination_root = options[:root]
  puts colorize( "Puer Version: #{Puer::Version::STRING}", { :foreground => :red, :background => :white, :config => :underline } )
  puts
  require 'yaml'
  # begin
  #   page_source = Net::HTTP.get(URI.parse("http://eiffelqiu.github.com/puer/gist.yml"))
  # rescue SocketError => e
  # end   
  # begin 
  #   g = YAML::load(page_source)  
  # rescue ArgumentError => e
  #   g = YAML.load_file(File.expand_path(File.dirname(__FILE__) + '/gist.yml'))
  # end
  gistfile = File.expand_path("~") + '/.puer/gist.yml'
  Gist::update_gist unless File.exist?(gistfile)          
  begin 
    g = YAML.load_file(gistfile) 
  rescue ArgumentError => e
    g = YAML.load_file(File.expand_path(File.dirname(__FILE__) + '/gist.yml'))
  end        
  gitopt = []  
  puts "notice: a new version '#{g['info']}' released" if g['info'] and g['info'].strip != "#{Puer::Version::STRING}"
  puts
  puts colorize("Available Options contains [#{@gist_name}]")
  puts        
  g.each_pair {|key,value|
    # puts colorize("Gist Category [#{key.gsub('_',' ')}]")    
    gname = key.gsub('_',' ') 
    unless key.downcase.strip == 'info'       
      g[key].each { |k|  
          k.each_pair { |k1,v1|
            gist_name = k1.downcase
            gist_desc = k[k1][2]['description'].downcase
            if gist_name.include?(@gist_name) or gist_desc.include?(@gist_name)
              # gitopt << {:category => "#{key.gsub('_',' ')}", :command => "puer gist #{k1}",   :description => "#{k[k1][2]['description']}" }
              if gname == 'lib'
                gitopt << {:category => "#{key.gsub('_',' ')}", :command => "puer lib #{k1}",   :description => "#{k[k1][2]['description']}" }
              else
                gitopt << {:category => "#{key.gsub('_',' ')}", :command => "puer gist #{k1}",   :description => "#{k[k1][2]['description']}" }
              end              
            end
          }
      }
    end
  } 
  View.render(gitopt, RENDER_OPTIONS)          
  puts     
end

#in_app_root?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/puer/generators/search.rb', line 31

def in_app_root?
  # File.exist?('Classes')
  Dir.glob("tiapp.xml").count >= 1
end