mami 0.0.6 → 0.0.7

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: ad1b7c129a47931987f32f3716331d4739f98600
4
- data.tar.gz: 1b99e17bd213e030e2d53647c2375de80ad83ec3
3
+ metadata.gz: 9d16356c8a7e060a8b3f57d450d7c1968842e7ca
4
+ data.tar.gz: 377e80787308f06f8e7306f33e5f89a86768cc66
5
5
  SHA512:
6
- metadata.gz: b50287197a3151ccdde666d3c5336843343c05e0d2212fdbd3c110f730d22f9bfc0e1d3e439f48d0eb917e56eecba79b568246e7904e20e783a2b441e6d575ec
7
- data.tar.gz: 54b89994b8b9ec8b02e9a4b03caa5e857586895c6bd5a2c643cb609d56315fdcdd85c8dcdd1d22ec3693da2e05a9d67eca0bd7d5786306315aba209ddf6b26f5
6
+ metadata.gz: af68d72a4dd4dceeff63d8cbef24f0641861bfa3a7a434f4e5b94b225b0fbd3dc7ee01b2f779cef86c0952a52d10b14d1d7cfe935946a0d09855bdb414397353
7
+ data.tar.gz: 4a61f37ba82fad65975d347d67676ef15c90a13993b8d43c26ed032091fb697d618f5b1d2e7d6f436c80adcd019a5e162f396dbda5767fec1a98536146f33412
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ branches:
6
+ only:
7
+ - master
data/README.md CHANGED
@@ -1,24 +1,18 @@
1
1
  # Mami
2
2
 
3
- TODO: Write a gem description
3
+ Show timestamped file name.
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'mami'
5
+ [![Build Status](https://api.travis-ci.org/sanemat/mami.png?branch=master)](https://travis-ci.org/sanemat/mami)
10
6
 
11
- And then execute:
12
-
13
- $ bundle
7
+ ## Installation
14
8
 
15
- Or install it yourself as:
9
+ Install it yourself as:
16
10
 
17
11
  $ gem install mami
18
12
 
19
13
  ## Usage
20
14
 
21
- TODO: Write usage instructions here
15
+ $ mami
22
16
 
23
17
  ## Contributing
24
18
 
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new('spec') do |spec|
4
+ spec.rspec_opts = %w(--color --format documentation)
5
+ end
6
+ task default: :spec
data/lib/mami/cli.rb CHANGED
@@ -3,6 +3,7 @@ require 'thor'
3
3
 
4
4
  module Mami
5
5
  class CLI < Thor
6
+ check_unknown_options!
6
7
  default_task :print
7
8
 
8
9
  desc "version", "Prints the mami's version information"
@@ -14,10 +15,11 @@ module Mami
14
15
  desc "print", "Prints timestamped text file path"
15
16
  method_option :extension, default: 'txt', aliases: '--ext', desc: 'Set extension, if nil, then no extension'
16
17
  method_option :directory, default: nil, aliases: '-d', desc: 'Set directory. if nil, then use MAMI_DIR'
17
- def print
18
+ def print(opt = {})
19
+ time = opt[:time] || Time.now
18
20
  path = options[:directory] || ENV['MAMI_DIR']
19
- return puts "no-mami" unless path
20
- basename = %x[date "+%Y-%m-%d-%H-%M-%S"].chomp
21
+ abort("mami requires MAMI_DIR or directory option") unless path
22
+ basename = time.strftime('%Y-%m-%d-%H-%M-%S')
21
23
  extension = options[:extension].nil? ? nil : '.' + options[:extension]
22
24
  filename = [basename, extension].compact.join
23
25
  puts File.join(path, filename)
data/lib/mami/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mami
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/mami.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "rspec"
24
25
 
25
26
  spec.add_dependency 'thor'
26
27
  end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'bundle executable' do
4
+ it 'returns non-zero exit status when passed unrecognized options' do
5
+ mami '--invalid_argument'
6
+ expect(err).to include('Unknown switches')
7
+ end
8
+ end
@@ -0,0 +1,46 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'mami'
6
+
7
+ # Require the correct version of popen for the current platform
8
+ if RbConfig::CONFIG['host_os'] =~ /mingw|mswin/
9
+ begin
10
+ require 'win32/open3'
11
+ rescue LoadError
12
+ abort "Run `gem install win32-open3` to be able to run specs"
13
+ end
14
+ else
15
+ require 'open3'
16
+ end
17
+
18
+ Dir["#{File.expand_path('../support', __FILE__)}/*.rb"].each do |file|
19
+ require file unless file =~ /fakeweb\/.*\.rb/
20
+ end
21
+
22
+ $debug = false
23
+ $show_err = true
24
+
25
+ RSpec.configure do |config|
26
+ config.include Spec::Path
27
+ config.include Spec::Helpers
28
+
29
+ original_wd = Dir.pwd
30
+
31
+ config.expect_with :rspec do |c|
32
+ c.syntax = :expect
33
+ end
34
+
35
+ config.before :each do
36
+ reset!
37
+ in_app_root
38
+ end
39
+
40
+ config.after :each do
41
+ puts @out if example.exception
42
+
43
+ Dir.chdir(original_wd)
44
+ # Reset ENV
45
+ end
46
+ end
@@ -0,0 +1,68 @@
1
+ # Copy from bundler/spec/support/helpers.rb
2
+ module Spec
3
+ module Helpers
4
+ def reset!
5
+ @in_p, @out_p, @err_p = nil, nil, nil
6
+ end
7
+
8
+ attr_reader :out, :err, :exitstatus
9
+
10
+ def in_app_root(&blk)
11
+ Dir.chdir(app, &blk)
12
+ end
13
+
14
+ def lib
15
+ File.expand_path('../../../lib', __FILE__)
16
+ end
17
+
18
+ def mami(cmd, options = {})
19
+ mami_bin = File.expand_path('../../../bin/mami', __FILE__)
20
+ options.merge!(my_command_bin: mami_bin)
21
+ my_command(cmd, options)
22
+ end
23
+
24
+ def my_command(cmd, options = {})
25
+ expect_err = options.delete(:expect_err)
26
+ exitstatus = options.delete(:exitstatus)
27
+ my_command_bin = options.delete(:my_command_bin)
28
+ options["no-color"] = true unless options.key?("no-color") || %w(exec conf).include?(cmd.to_s[0..3])
29
+
30
+ requires = options.delete(:requires) || []
31
+ requires_str = requires.map{|r| "-r#{r}"}.join(" ")
32
+
33
+ env = (options.delete(:env) || {}).map{|k,v| "#{k}='#{v}' "}.join
34
+ args = options.map do |k,v|
35
+ v == true ? " --#{k}" : " --#{k} #{v}" if v
36
+ end.join
37
+
38
+ cmd = "#{env}#{Gem.ruby} -I#{lib} #{requires_str} #{my_command_bin} #{cmd}#{args}"
39
+
40
+ if exitstatus
41
+ sys_status(cmd)
42
+ else
43
+ sys_exec(cmd, expect_err){|i| yield i if block_given? }
44
+ end
45
+ end
46
+
47
+ def sys_exec(cmd, expect_err = false)
48
+ Open3.popen3(cmd.to_s) do |stdin, stdout, stderr|
49
+ @in_p, @out_p, @err_p = stdin, stdout, stderr
50
+
51
+ yield @in_p if block_given?
52
+ @in_p.close
53
+
54
+ @out = @out_p.read_available_bytes.strip
55
+ @err = @err_p.read_available_bytes.strip
56
+ end
57
+
58
+ puts @err unless expect_err || @err.empty? || !$show_err
59
+ @out
60
+ end
61
+
62
+ def sys_status(cmd)
63
+ @err = nil
64
+ @out = %x{#{cmd}}.strip
65
+ @exitstatus = $?.exitstatus
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,19 @@
1
+ require 'pathname'
2
+
3
+ module Spec
4
+ module Path
5
+ def root
6
+ @root ||= Pathname.new(File.expand_path("../../..", __FILE__))
7
+ end
8
+
9
+ def tmp(*path)
10
+ root.join("tmp", *path)
11
+ end
12
+
13
+ def app(*path)
14
+ root = tmp.join("spec_app")
15
+ FileUtils.mkdir_p(root)
16
+ root.join(*path)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ class IO
2
+ def read_available_bytes(chunk_size = 16384, select_timeout = 0.02)
3
+ buffer = []
4
+
5
+ return "" if closed? || eof?
6
+ # IO.select cannot be used here due to the fact that it
7
+ # just does not work on windows
8
+ while true
9
+ begin
10
+ IO.select([self], nil, nil, select_timeout)
11
+ break if eof? # stop raising :-(
12
+ buffer << self.readpartial(chunk_size)
13
+ rescue(EOFError)
14
+ break
15
+ end
16
+ end
17
+
18
+ return buffer.join
19
+ end
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mami
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - sanemat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-04 00:00:00.000000000 Z
11
+ date: 2013-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: thor
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +89,7 @@ extensions: []
75
89
  extra_rdoc_files: []
76
90
  files:
77
91
  - .gitignore
92
+ - .travis.yml
78
93
  - Gemfile
79
94
  - LICENSE.txt
80
95
  - README.md
@@ -84,6 +99,11 @@ files:
84
99
  - lib/mami/cli.rb
85
100
  - lib/mami/version.rb
86
101
  - mami.gemspec
102
+ - spec/cli_spec.rb
103
+ - spec/spec_helper.rb
104
+ - spec/support/helpers.rb
105
+ - spec/support/path.rb
106
+ - spec/support/ruby_ext.rb
87
107
  homepage: https://github.com/sanemat/mami
88
108
  licenses:
89
109
  - MIT
@@ -108,4 +128,9 @@ rubygems_version: 2.0.0
108
128
  signing_key:
109
129
  specification_version: 4
110
130
  summary: Utility for date
111
- test_files: []
131
+ test_files:
132
+ - spec/cli_spec.rb
133
+ - spec/spec_helper.rb
134
+ - spec/support/helpers.rb
135
+ - spec/support/path.rb
136
+ - spec/support/ruby_ext.rb