miu 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/miu CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- encoding: utf-8 -*-
3
+ require 'bundler'
4
+ Bundler.require
5
+
3
6
  require 'miu/cli'
4
7
  Miu::CLI.start
data/lib/miu/cli.rb CHANGED
@@ -6,6 +6,16 @@ module Miu
6
6
  include ::Thor::Actions
7
7
  add_runtime_options!
8
8
 
9
+ class << self
10
+ def source_root
11
+ File.expand_path('../../templates', __FILE__)
12
+ end
13
+
14
+ def destination_root
15
+ Miu.root
16
+ end
17
+ end
18
+
9
19
  map ['--version', '-v'] => :version
10
20
 
11
21
  desc 'version', 'Show version'
@@ -24,32 +34,10 @@ module Miu
24
34
 
25
35
  desc 'init', 'Generates a miu configuration files'
26
36
  def init
27
- empty_directory 'config'
37
+ copy_file 'Gemfile'
38
+ directory 'config'
28
39
  empty_directory 'log'
29
40
  empty_directory 'tmp/pids'
30
-
31
- create_file 'config/miu.god', <<-CONF
32
- # vim: ft=ruby
33
- require 'miu'
34
-
35
- God.port = 30300
36
- God.pid_file_directory = Miu.root.join('tmp/pids')
37
-
38
- God.watch do |w|
39
- w.dir = Miu.root
40
- w.log = Miu.root.join('log/fluentd.log')
41
- w.name = 'fluentd'
42
- w.start = 'bundle exec fluentd -c config/fluent.conf'
43
- w.keepalive
44
- end
45
- CONF
46
- create_file 'config/fluent.conf', <<-CONF
47
- # built-in TCP input
48
- # $ echo <json> | fluent-cat <tag>
49
- <source>
50
- type forward
51
- </source>
52
- CONF
53
41
  end
54
42
  end
55
43
  end
data/lib/miu/plugin.rb CHANGED
@@ -4,12 +4,52 @@ module Miu
4
4
  module Plugin
5
5
  def self.included(base)
6
6
  base.extend ClassMethods
7
+ base.called_from = begin
8
+ call_stack = caller.map { |p| p.sub(/:\d+.*/, '') }
9
+ File.dirname(call_stack.detect { |p| p !~ %r(miu[\w.-]*/lib/miu/plugins) })
10
+ end
7
11
  end
8
12
 
9
13
  module ClassMethods
14
+ attr_accessor :called_from
15
+
10
16
  def register(*args, &block)
11
- args.insert 1, self.class
12
- Miu.register *args, &block
17
+ require 'miu/cli'
18
+ options = args.last.is_a?(::Hash) ? args.pop : {}
19
+ name = args.shift
20
+ plugin = args.shift || self
21
+ usage = options[:usage] || "#{name} [COMMAND]"
22
+ desc = options[:desc] || plugin.to_s
23
+
24
+ Miu.plugins[name] = plugin
25
+ Miu::CLI.register generate_subcommand(name, plugin, &block), name, usage, desc if block
26
+ end
27
+
28
+ private
29
+
30
+ def generate_subcommand(name, plugin, &block)
31
+ require 'thor'
32
+ Class.new ::Thor do
33
+ include ::Thor::Actions
34
+ add_runtime_options!
35
+
36
+ class << self
37
+ def source_root
38
+ Miu.find_root('Gemfile', plugin.called_from)
39
+ end
40
+
41
+ def destination_root
42
+ Miu.root
43
+ end
44
+
45
+ def banner(task, namespace = nil, subcommand = true)
46
+ super
47
+ end
48
+ end
49
+
50
+ namespace name
51
+ class_eval &block if block
52
+ end
13
53
  end
14
54
  end
15
55
  end
data/lib/miu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Miu
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/miu.rb CHANGED
@@ -1,48 +1,33 @@
1
1
  require 'miu/version'
2
2
 
3
3
  module Miu
4
- autoload :CLI, 'miu/cli'
5
-
6
4
  class << self
7
5
  def root
8
- require 'pathname'
9
- Pathname.new(File.expand_path('../../', __FILE__))
6
+ @root ||= find_root 'Gemfile'
10
7
  end
11
8
 
12
9
  def plugins
13
10
  @plugins ||= {}
14
11
  end
15
12
 
16
- def register(name, type, options = {}, &block)
13
+ def register(name, plugin, options = {}, &block)
17
14
  name = name.to_s
18
15
  usage = options[:usage] || "#{name} [COMMAND]"
19
- desc = options[:desc] || type.to_s
16
+ desc = options[:desc] || plugin.to_s
20
17
 
21
- plugins[name] = type
22
- Miu::CLI.register generate_subcommand(name, &block), name, usage, desc if block
18
+ plugins[name] = plugin
19
+ Miu::CLI.register generate_subcommand(name, plugin, &block), name, usage, desc if block
23
20
  end
24
21
 
25
- private
26
-
27
- def generate_subcommand(name, &block)
28
- require 'thor'
29
- Class.new ::Thor do
30
- include ::Thor::Actions
31
- add_runtime_options!
32
-
33
- class << self
34
- def source_root
35
- Miu.root.to_s
36
- end
37
-
38
- def banner(task, namespace = nil, subcommand = true)
39
- super
40
- end
41
- end
42
-
43
- namespace name
44
- class_eval &block if block
22
+ def find_root(flag, base = nil)
23
+ require 'pathname'
24
+ path = base || Dir.pwd
25
+ while path && File.directory?(path) && File.exist?("#{path}/#{flag}")
26
+ parent = File.dirname path
27
+ path = path != parent && path
45
28
  end
29
+ raise 'Could not find root path' unless path
30
+ Pathname.new File.realpath(path)
46
31
  end
47
32
  end
48
33
  end
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'miu'
@@ -0,0 +1,5 @@
1
+ # built-in TCP input
2
+ # $ echo <json> | fluent-cat <tag>
3
+ <source>
4
+ type forward
5
+ </source>
@@ -0,0 +1,13 @@
1
+ # vim: ft=ruby
2
+ require 'miu'
3
+
4
+ God.port = 30300
5
+ God.pid_file_directory = Miu.root.join('tmp/pids')
6
+
7
+ God.watch do |w|
8
+ w.dir = Miu.root
9
+ w.log = Miu.root.join('log/fluentd.log')
10
+ w.name = 'fluentd'
11
+ w.start = 'bundle exec fluentd -c config/fluent.conf'
12
+ w.keepalive
13
+ end
data/miu.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
+ gem.add_dependency 'bundler'
20
21
  gem.add_dependency 'thor'
21
22
  gem.add_dependency 'god'
22
23
  gem.add_dependency 'fluentd'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,6 +11,22 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: thor
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -111,6 +127,9 @@ files:
111
127
  - lib/miu/plugins.rb
112
128
  - lib/miu/plugins/null.rb
113
129
  - lib/miu/version.rb
130
+ - lib/templates/Gemfile
131
+ - lib/templates/config/fluent.conf
132
+ - lib/templates/config/miu.god
114
133
  - miu.gemspec
115
134
  homepage: ''
116
135
  licenses: []
@@ -126,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
145
  version: '0'
127
146
  segments:
128
147
  - 0
129
- hash: -1753892730624338277
148
+ hash: -519439640692874562
130
149
  required_rubygems_version: !ruby/object:Gem::Requirement
131
150
  none: false
132
151
  requirements:
@@ -135,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
154
  version: '0'
136
155
  segments:
137
156
  - 0
138
- hash: -1753892730624338277
157
+ hash: -519439640692874562
139
158
  requirements: []
140
159
  rubyforge_project:
141
160
  rubygems_version: 1.8.24