Module: AlpacaComplete::Utils

Defined in:
lib/AlpacaComplete/utils.rb

Class Method Summary collapse

Class Method Details

.get_bannerObject

}}}



48
49
50
51
52
53
54
# File 'lib/AlpacaComplete/utils.rb', line 48

def get_banner# {{{
  return <<-BANNAR.gsub(/^\s*/)
      Usage:
      alpacaComplete [OPTIONS]
      ---------------------------------------------------------------------
  BANNAR
end

.load_yaml(path) ⇒ Object

}}}



75
76
77
78
79
80
# File 'lib/AlpacaComplete/utils.rb', line 75

def load_yaml( path )# {{{
  return nil until File.exist?(path)

  require 'yaml'
  ::YAML::load_file( path )
end

.option_parser(args) ⇒ Object

{{{



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/AlpacaComplete/utils.rb', line 7

def option_parser( args )# {{{
  args << '-h' if args.empty?

  options = {}
  optparse = OptionParser.new do |opts|
    opts.banner  = get_banner

    opts.on('-h','--help','HELP') do
      puts opts
      exit
    end

    opts.on('-t CMD', '--type CMD', 'command type') do |l|
      options[:command] = l.to_sym
    end

    opts.on('-w VAL', '--word VAL', 'uncomplete word') do |l|
      options[:word] = l
    end

    opts.on('-f VAL', '--filepath VAL', 'rails path') do |l|
      options[:path] = l
    end

    opts.on('-v', '--version', 'Version') do
      puts ::AlpacaComplete::VERSION
      exit
    end
  end

  optparse.parse! args
  options[:files]  = args.to_a

  {
    command: options[:command],
    path: options[:path],
    word: options[:word],
    uncomplete: options[:locale]
  }
end

.run(cmd, path, uncomplete = "") ⇒ Object

}}}



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/AlpacaComplete/utils.rb', line 56

def run( cmd, path, uncomplete="" )# {{{
  case cmd
  when :locale
    # TODO :権限を委譲する
    locales = ::AlpacaComplete::LocaleComplete.complete( path, uncomplete )

    locales.each do |k, v|
      puts ":key =>#{k} :value =>#{v}"
    end

  when :assets_image
    assets = ::AlpacaComplete::AssetsComplete.complete( path, uncomplete, :image )
    assets.each { |file_path| puts file_path }

  # when :assets_stylesheets
  # when :assets_javascripts
  end
end