noir 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 321b15d42d793bbc446da53068990490c43d1d53
4
- data.tar.gz: 958e080bde8a7e4aba828cef99ad0587b774b869
3
+ metadata.gz: 87a92fb27d6501f841713ec7f5972152c1df2b02
4
+ data.tar.gz: 3b4585476354ecdee659faf9c14f00f8fc89ff71
5
5
  SHA512:
6
- metadata.gz: 047e554c78f92f237badf491e967d86c8a8af8edb89938f0cc9350dc1c39376f2e7d841dd6481fb648aee8107ba65f10b0c7ac6b823bbcd3e9c54e99d34477ee
7
- data.tar.gz: fc30d7f7a8890a13a01fafeca7ec82e1a8984b044224c83cb003ce86136008ac9ecec46833e8898c4540574186be68eb8bb54a23f153ce286fdac7747e5bde85
6
+ metadata.gz: 730faf4b77365e52fa48aac8cd44b5de86678ebac29cbadabc4ce158c66232d7c4caef1ba26cda40479b09b5a08033a6fd714775a1a87e49ab62d6e9d514009b
7
+ data.tar.gz: c4dd7f89a0f889d030737bfba74ccb43bc6f1ef11a74eeb7ec5bf792a951851af5b2e0bd8536ac06b829c5f4c59565adc4cc772a43c964b94a65d383746a9b83
data/lib/noir.rb CHANGED
@@ -7,7 +7,6 @@ require 'noir/command'
7
7
 
8
8
  module Noir
9
9
  def self.main
10
- Noir::Options.parse_options_from_argv!
11
10
  Noir::Executer.execute
12
11
  end
13
12
  end
@@ -27,7 +27,10 @@ module Noir::Base
27
27
 
28
28
  def sub_commands
29
29
  consts = constants - superclass.constants
30
- consts = consts.select{|c| const_get(c).ancestors.include?(Noir::Base::Command)}
30
+ consts = consts.select do |const|
31
+ const_get(const).class == Class &&
32
+ const_get(const).ancestors.include?(Noir::Base::Command)
33
+ end
31
34
  end
32
35
 
33
36
  def check_command_not_found command=nil, *args
@@ -11,6 +11,10 @@ module Noir::Base
11
11
  raise 'please override in extended class'
12
12
  end
13
13
 
14
+ def sub_commands
15
+ return []
16
+ end
17
+
14
18
  end
15
19
 
16
20
  end
@@ -5,10 +5,6 @@ class Noir::Command::Completion < Noir::Base::TerminalCommand
5
5
  class << self
6
6
 
7
7
  def execute *args
8
- if Noir::Options.exist? Noir::Options::Help
9
- description
10
- exit
11
- end
12
8
  puts suggestions(args)
13
9
  end
14
10
 
@@ -1,5 +1,5 @@
1
1
  class Noir::Command::Edit::WeeklyReport::Friday < Noir::Base::TerminalCommand
2
- @describe = 'edit weekly report separated by friday'
2
+ @description = 'edit weekly report separated by friday'
3
3
 
4
4
  class << self
5
5
  def execute *args
@@ -1,5 +1,5 @@
1
1
  class Noir::Command::Edit::WeeklyReport::Monday < Noir::Base::TerminalCommand
2
- @describe = 'edit weekly report separated by monday'
2
+ @description = 'edit weekly report separated by monday'
3
3
 
4
4
  class << self
5
5
  def execute *args
@@ -1,5 +1,5 @@
1
1
  class Noir::Command::Edit::WeeklyReport::Saturday < Noir::Base::TerminalCommand
2
- @describe = 'edit weekly report separated by saturday'
2
+ @description = 'edit weekly report separated by saturday'
3
3
 
4
4
  class << self
5
5
  def execute *args
@@ -1,5 +1,5 @@
1
1
  class Noir::Command::Edit::WeeklyReport::Sunday < Noir::Base::TerminalCommand
2
- @describe = 'edit weekly report separated by sunday'
2
+ @description = 'edit weekly report separated by sunday'
3
3
 
4
4
  class << self
5
5
  def execute *args
@@ -1,5 +1,5 @@
1
1
  class Noir::Command::Edit::WeeklyReport::Thursday < Noir::Base::TerminalCommand
2
- @describe = 'edit weekly report separated by thursday'
2
+ @description = 'edit weekly report separated by thursday'
3
3
 
4
4
  class << self
5
5
  def execute *args
@@ -1,5 +1,5 @@
1
1
  class Noir::Command::Edit::WeeklyReport::Tuesday < Noir::Base::TerminalCommand
2
- @describe = 'edit weekly report separated by tuesday'
2
+ @description = 'edit weekly report separated by tuesday'
3
3
 
4
4
  class << self
5
5
  def execute *args
@@ -1,5 +1,5 @@
1
1
  class Noir::Command::Edit::WeeklyReport::Wednesday < Noir::Base::TerminalCommand
2
- @describe = 'edit weekly report separated by wednesday'
2
+ @description = 'edit weekly report separated by wednesday'
3
3
 
4
4
  class << self
5
5
  def execute *args
@@ -1,5 +1,14 @@
1
1
  class Noir::Command::New < Noir::Base::Command
2
2
  @description = 'Create new files'
3
+
4
+ def self.createFile filename, text=''
5
+ File.open(filename, 'w') do |file|
6
+ file.write(text.sub(/^\n/, ''))
7
+ end
8
+ end
9
+
3
10
  end
4
11
 
5
12
  require 'noir/command/new/note'
13
+ require 'noir/command/new/gitignore'
14
+ require 'noir/command/new/makefile'
@@ -0,0 +1,13 @@
1
+ class Noir::Command::New::GitIgnore < Noir::Base::Command
2
+ @description = 'Create new .gitignore'
3
+
4
+ GitIgnoreName = '.gitignore'
5
+
6
+ def self.createGitIgnore text
7
+ Noir::Command::New.createFile(GitIgnoreName, text)
8
+ end
9
+
10
+ end
11
+
12
+ require 'noir/command/new/gitignore/vim'
13
+ require 'noir/command/new/gitignore/tex'
@@ -0,0 +1,19 @@
1
+ class Noir::Command::New::GitIgnore::Tex < Noir::Base::TerminalCommand
2
+ @description = 'Create new .gitignore for TeX'
3
+
4
+ GitIgnoreText = %q(
5
+ *.swp
6
+
7
+ *.log
8
+ *.aux
9
+ *.dvi
10
+ *.pdf
11
+ *.toc
12
+ )
13
+
14
+ def self.execute *args
15
+ Noir::Command::New::GitIgnore.createGitIgnore GitIgnoreText
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,13 @@
1
+ class Noir::Command::New::GitIgnore::Vim < Noir::Base::TerminalCommand
2
+ @description = 'Create new .gitignore for vim'
3
+
4
+ GitIgnoreText = %q(
5
+ *.swp
6
+ )
7
+
8
+ def self.execute *args
9
+ Noir::Command::New::GitIgnore.createGitIgnore GitIgnoreText
10
+ end
11
+
12
+ end
13
+
@@ -0,0 +1,11 @@
1
+ class Noir::Command::New::Makefile < Noir::Base::Command
2
+ @description = 'Create new Makefile'
3
+
4
+ MakefileName = 'Makefile'
5
+
6
+ def self.createMakefile text
7
+ Noir::Command::New.createFile(MakefileName, text)
8
+ end
9
+ end
10
+
11
+ require 'noir/command/new/makefile/tex'
@@ -0,0 +1,34 @@
1
+ class Noir::Command::New::Makefile::Tex < Noir::Base::TerminalCommand
2
+ @description = 'Create new Makefile for TeX'
3
+
4
+ MakefileText = %q(
5
+ # target name
6
+ TARGET=<tex_file_name_without_extension>
7
+
8
+ # dependencies
9
+ $(TARGET).pdf : $(TARGET).dvi
10
+ dvipdfmx $<
11
+
12
+ $(TARGET).dvi : $(wildcard **/*.tex) $(TARGET).tex
13
+ platex $(TARGET).tex
14
+ platex $(TARGET).tex
15
+ platex $(TARGET).tex
16
+
17
+ # commands
18
+ .PHONY : all open clean
19
+
20
+ all : $(TARGET).pdf
21
+
22
+ open : $(TARGET).pdf
23
+ open $(TARGET).pdf
24
+
25
+ clean:
26
+ rm -f *.dvi *.aux *.log *.pdf *.ps *.gz *.bbl *.blg *.toc *~ *.core
27
+ )
28
+
29
+ def self.execute *args
30
+ Noir::Command::New::Makefile.createMakefile MakefileText
31
+ end
32
+
33
+ end
34
+
@@ -1,5 +1,4 @@
1
1
  require 'date'
2
- require 'fileutils'
3
2
 
4
3
  class Noir::Command::New::Note < Noir::Base::TerminalCommand
5
4
  @description = 'create empty txt. filename format is <serial-no>_<date>.txt'
@@ -9,7 +8,8 @@ class Noir::Command::New::Note < Noir::Base::TerminalCommand
9
8
  def execute *args
10
9
  note_num = Dir.glob('[0-9]*_????????.txt').size + 1
11
10
  note_name = format("%02d", note_num) + '_' + Time.now.strftime('%Y%m%d') + '.txt'
12
- FileUtils.touch(note_name)
11
+ Noir::Command::New.createFile note_name
12
+ puts note_name
13
13
  end
14
14
 
15
15
  end
data/lib/noir/executer.rb CHANGED
@@ -6,19 +6,12 @@ module Noir
6
6
  def self.find_command command_arr, search_str
7
7
  command = eval(command_arr.join('::'))
8
8
 
9
- # finish find by terminal command
10
- return nil if command.superclass == Noir::Base::TerminalCommand
11
-
12
- commands = command.constants(true).map(&:to_s)
9
+ commands = command.sub_commands.map(&:to_s)
13
10
  matched_str = commands.find{|c| c.downcase == search_str.downcase}
14
11
  matched_str = find_abbr_command(commands, search_str) if matched_str.nil?
15
12
 
16
13
  return nil if matched_str.nil?
17
14
  matched_arr = command_arr + [matched_str]
18
- unless eval(matched_arr.join('::')).ancestors.include?(Noir::Base::Command)
19
- # matched. but matched class is not inherited commmand
20
- return nil
21
- end
22
15
 
23
16
  return matched_str
24
17
  end
@@ -60,6 +53,12 @@ module Noir
60
53
  # inherited methods
61
54
 
62
55
  def self.execute
56
+ Noir::Options.parse_options_from_argv!
57
+
58
+ if Noir::Options.exist? Noir::Options::Help
59
+ return command_from_argv.description
60
+ end
61
+
63
62
  command_from_argv.execute *args_from_argv
64
63
  end
65
64
 
data/lib/noir/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Noir
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/noir.gemspec CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.required_ruby_version = '>= 1.9.2'
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.5"
22
24
  spec.add_development_dependency "rake", "10.1.1"
23
25
  spec.add_development_dependency "rspec", "3.0.0.beta2"
@@ -0,0 +1,8 @@
1
+ require 'noir'
2
+ require 'spec_helper'
3
+
4
+ describe 'Noir::Command::New::GitIgnore::Tex' do
5
+ it 'is TerminalCommand' do
6
+ expect(Noir::Command::New::GitIgnore::Tex.superclass).to eq(Noir::Base::TerminalCommand)
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'noir'
2
+ require 'spec_helper'
3
+
4
+ describe 'Noir::Command::New::GitIgnore::Vim' do
5
+ it 'is TerminalCommand' do
6
+ expect(Noir::Command::New::GitIgnore::Vim.superclass).to eq(Noir::Base::TerminalCommand)
7
+ end
8
+ end
9
+
10
+
@@ -0,0 +1,9 @@
1
+ require 'noir'
2
+ require 'spec_helper'
3
+
4
+ describe 'Noir::Command::New::GitIgnore' do
5
+ it 'is Command' do
6
+ expect(Noir::Command::New::GitIgnore.superclass).to eq(Noir::Base::Command)
7
+ end
8
+ end
9
+
@@ -0,0 +1,9 @@
1
+ require 'noir'
2
+ require 'spec_helper'
3
+
4
+ describe 'Noir::Command::New::Makefile::Tex' do
5
+ it 'is TerminalCommand' do
6
+ expect(Noir::Command::New::Makefile::Tex.superclass).to eq(Noir::Base::TerminalCommand)
7
+ end
8
+ end
9
+
@@ -0,0 +1,10 @@
1
+ require 'noir'
2
+ require 'spec_helper'
3
+
4
+ describe 'Noir::Command::New::Makefile' do
5
+ it 'is Command' do
6
+ expect(Noir::Command::New::Makefile.superclass).to eq(Noir::Base::Command)
7
+ end
8
+ end
9
+
10
+
@@ -204,4 +204,30 @@ describe 'Noir::Executer' do
204
204
  end # in defined argv
205
205
 
206
206
  end # args_from_argv
207
+
208
+ describe 'execute' do
209
+ let(:mock_command) { double('Noir::Base::Command') }
210
+
211
+ before do
212
+ stub_const 'Noir::Executer', Noir::Executer
213
+ allow(Noir::Executer).to receive(:command_from_argv).and_return(mock_command)
214
+
215
+ allow(mock_command).to receive(:execute).and_return(:call_execute)
216
+ allow(mock_command).to receive(:description).and_return(:call_description)
217
+ end
218
+
219
+ it 'not has help flag. execute command.execute' do
220
+ expect(Noir::Executer.execute).to eq(:call_execute)
221
+ end
222
+
223
+ it 'has help option. execute command.describe' do
224
+ stub_const 'ARGV', ['-h']
225
+ expect(Noir::Executer.execute).to eq(:call_description)
226
+ end
227
+
228
+ it 'has log help option. execute command.describe' do
229
+ stub_const 'ARGV', ['--help']
230
+ expect(Noir::Executer.execute).to eq(:call_description)
231
+ end
232
+ end # execute
207
233
  end
@@ -54,6 +54,7 @@ describe 'Noir::Base::Command' do
54
54
  stub_const('Hoge::SubCommand' , Class.new(Noir::Base::Command))
55
55
  stub_const('Hoge::SubCommand::SubSubCommand' , Class.new(Noir::Base::Command))
56
56
  stub_const('Hoge::SubCommand::SubSubNonCommand' , Class.new)
57
+ stub_const('Hoge::SubCommand::NotCommand' , :not_command)
57
58
  stub_const('Hoge::SubCommandTwo' , Class.new(Noir::Base::Command))
58
59
  stub_const('Hoge::SubNonCommand' , Class.new)
59
60
 
@@ -112,6 +113,10 @@ describe 'Noir::Base::Command' do
112
113
  expect(@commands).not_to include(:SubCommand)
113
114
  end
114
115
 
116
+ it 'not include non class const' do
117
+ expect(@commands).not_to include(:not_command)
118
+ end
119
+
115
120
  end
116
121
  end
117
122
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - atton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-13 00:00:00.000000000 Z
11
+ date: 2014-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,6 +85,11 @@ files:
85
85
  - lib/noir/command/init.rb
86
86
  - lib/noir/command/init/zsh.rb
87
87
  - lib/noir/command/new.rb
88
+ - lib/noir/command/new/gitignore.rb
89
+ - lib/noir/command/new/gitignore/tex.rb
90
+ - lib/noir/command/new/gitignore/vim.rb
91
+ - lib/noir/command/new/makefile.rb
92
+ - lib/noir/command/new/makefile/tex.rb
88
93
  - lib/noir/command/new/note.rb
89
94
  - lib/noir/executer.rb
90
95
  - lib/noir/options.rb
@@ -103,6 +108,11 @@ files:
103
108
  - spec/noir/command/help_spec.rb
104
109
  - spec/noir/command/init/zsh_spec.rb
105
110
  - spec/noir/command/init_spec.rb
111
+ - spec/noir/command/new/gitignore/tex_spec.rb
112
+ - spec/noir/command/new/gitignore/vim_spec.rb
113
+ - spec/noir/command/new/gitignore_spec.rb
114
+ - spec/noir/command/new/makefile/tex_spec.rb
115
+ - spec/noir/command/new/makefile_spec.rb
106
116
  - spec/noir/command/new/note_spec.rb
107
117
  - spec/noir/command/new_spec.rb
108
118
  - spec/noir/command_spec.rb
@@ -125,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
135
  requirements:
126
136
  - - ">="
127
137
  - !ruby/object:Gem::Version
128
- version: '0'
138
+ version: 1.9.2
129
139
  required_rubygems_version: !ruby/object:Gem::Requirement
130
140
  requirements:
131
141
  - - ">="
@@ -151,6 +161,11 @@ test_files:
151
161
  - spec/noir/command/help_spec.rb
152
162
  - spec/noir/command/init/zsh_spec.rb
153
163
  - spec/noir/command/init_spec.rb
164
+ - spec/noir/command/new/gitignore/tex_spec.rb
165
+ - spec/noir/command/new/gitignore/vim_spec.rb
166
+ - spec/noir/command/new/gitignore_spec.rb
167
+ - spec/noir/command/new/makefile/tex_spec.rb
168
+ - spec/noir/command/new/makefile_spec.rb
154
169
  - spec/noir/command/new/note_spec.rb
155
170
  - spec/noir/command/new_spec.rb
156
171
  - spec/noir/command_spec.rb