seiya 0.0.7 → 0.0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b46494f0bfaec4f0a78fd9cf6cc9ac06c306b9f7
4
- data.tar.gz: 4fbc8f4febaddf6f20f7f04ac4ae7dd43d86c20e
3
+ metadata.gz: 9964852e3ba6851acdab2537d026e800d0b6c24f
4
+ data.tar.gz: da4abe61167d4688170eb5ba35994d39457d80c5
5
5
  SHA512:
6
- metadata.gz: 43afa2ca3d3c85cf28b8ac0985f37cd56b2c0001a1d69ba108dd4b7679410ebbbeb8cf2d62a543c19d2f29aa38ec0ef9248ac18cf2942d703fc143b09b447dee
7
- data.tar.gz: 797a0a441cf7d7b129e5958d09fc20902ed75040b320a5b555cd2cf174ef5b58c62c2540b2ca8f65b31409e73bae3a54987b029191a88d2762674f13717e95a1
6
+ metadata.gz: 123eed1fdbe3d0c4f7280f8b565a93c43f57cddd40be0404245bc512edb4eb24997e7e19c47884296dba674c8116a87ee68fb6af84eccddc665708b7494b2bfb
7
+ data.tar.gz: 2bc95f18d099db390bc3ee8c45f4a5e09ec9571a659c7a596c327c531d04cf32e23f8c6203a4fbb675e86fc14c2b6188a2a9cefdf8580f554ac1c20f20a48f5d
@@ -18,19 +18,22 @@ Run a task
18
18
  Options
19
19
  =======
20
20
  --help, -h show this help message and exit
21
- -a NAME=VALUE set task argument (may be repeated)'
21
+ -a NAME=VALUE set task argument (may be repeated)
22
+ --list, -l show task list in this project'
22
23
  end
23
24
 
24
- def run(*args)
25
- require 'tasks'
25
+ def print_task_list
26
+ task_list = Seiya.tasks.map do |k, v|
27
+ '%-14s%-30s' % [k, v]
28
+ end.join("\n")
29
+ puts "Task list
30
+ =========
26
31
 
27
- task_name = args.shift
28
- if task_name.nil?
29
- puts 'Need a task_name'
30
- exit!
31
- end
32
- task_class = Seiya.get_task_class task_name
32
+ #{task_list}
33
+ "
34
+ end
33
35
 
36
+ def run(*args)
34
37
  options = {}
35
38
  OptionParser.new do |opts|
36
39
  opts.banner = 'Usage: seiya [options]'
@@ -39,8 +42,25 @@ Options
39
42
  options[:args] = [] unless options[:args]
40
43
  options[:args] << a
41
44
  end
45
+
46
+ opts.on '-l', '--list', 'list tasks' do |l|
47
+ options[:list] = l
48
+ end
42
49
  end.parse!
43
50
 
51
+ if options[:list]
52
+ print_task_list
53
+ exit 0
54
+ end
55
+
56
+ task_name = args.shift
57
+ if task_name.nil?
58
+ puts 'Need a task_name'
59
+ exit!
60
+ end
61
+ task_class = Seiya.get_task_class task_name
62
+
63
+
44
64
  _args = options[:args] ? options[:args] : []
45
65
 
46
66
  task = task_class.new *_args
data/lib/seiya/task.rb CHANGED
@@ -21,6 +21,10 @@ module Seiya
21
21
  @start_urls = []
22
22
  end
23
23
 
24
+ def self.summary
25
+ 'I am a seiya task'
26
+ end
27
+
24
28
  def run
25
29
  return unless @start_urls.is_a? Array
26
30
  requests = @start_urls.map do |url|
data/lib/seiya/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Seiya
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.7.1'
3
3
  end
data/lib/seiya.rb CHANGED
@@ -34,6 +34,18 @@ module Seiya
34
34
  end
35
35
  end
36
36
 
37
+ def get_klasses(const_path, super_clazz = Object)
38
+ require_str, const_str = const_path.split '|'
39
+ _module = get_const require_str, const_str
40
+
41
+ _module.constants.select do |c|
42
+ const = _module.const_get(c)
43
+ const.is_a? Class and const < super_clazz
44
+ end.map do |c|
45
+ _module.const_get c
46
+ end
47
+ end
48
+
37
49
  def extend_load_path(path)
38
50
  Dir.foreach path do |f|
39
51
  unless %w(. ..).include? f
@@ -80,18 +92,27 @@ module Seiya
80
92
  # ignored
81
93
  end
82
94
 
83
- @commands = commands.map do |dir|
84
- require_str, const_str = dir.split '|'
85
- _module = get_const require_str, const_str
86
- clazz_symbols = _module.constants.select do |c|
87
- const = _module.const_get(c)
88
- const.is_a? Class and const < Command
89
- end
90
- clazz_symbols.map do |c|
91
- clazz = _module.const_get c
92
- [clazz.name.underscore.split('/').last.to_sym, clazz.new]
95
+ @commands = commands.map do |const_path|
96
+ klasses = get_klasses(const_path, Command)
97
+ klasses.map do |klass|
98
+ [klass.name.underscore.split('/').last.to_sym, klass.new]
93
99
  end
94
100
  end.flatten(1).to_h
101
+
102
+ task_klasses = get_klasses('tasks|Tasks', Task)
103
+ @task_klasses = task_klasses.map do |klass|
104
+ [klass.name.underscore.split('/').last.to_sym, klass]
105
+ end.to_h
106
+ end
107
+
108
+ def tasks
109
+ if @task_klasses.nil?
110
+ setup
111
+ end
112
+
113
+ @task_klasses.map do |k, v|
114
+ [k, v.summary]
115
+ end.to_h
95
116
  end
96
117
 
97
118
  def run_command(command, *args)
@@ -129,14 +150,17 @@ Use "seiya <command> -h" to see more info about a command
129
150
  end
130
151
 
131
152
  def get_task_class(task_name)
132
- task_name = 'Tasks::' << task_name unless task_name.include? '::'
133
- begin
134
- Util::get_const task_name
135
- rescue NameError
136
- p $:
137
- puts "Cannot get task: #{task_name}"
153
+ if @task_klasses.nil?
154
+ setup
155
+ end
156
+
157
+ task_name = task_name.to_sym
158
+ unless @task_klasses.key? task_name
159
+ puts "Task #{task_name} does not exist!"
138
160
  exit!
139
161
  end
162
+
163
+ @task_klasses[task_name]
140
164
  end
141
165
 
142
166
  def gen_project_file(project_name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seiya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yetone