mygegegems 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a29a68d608651a67f71b2c15d3e86dea4a800da8
4
+ data.tar.gz: 5722537d00340ffd9b8c2240b110d9223b5d798c
5
+ SHA512:
6
+ metadata.gz: f8511cc7302a58a950ca45144a4f72ae74c6ae943be8a0d81d72b815f10617fd6a1088d6b1e9947fb7a07e7ee7caec81f0a756c970c09b0a908aef85b89b4962
7
+ data.tar.gz: 6184c30efdce0d06a7adca8d528d350e5ea6b88f68e8e0eca4c78fcd5d3c105b2fb579f5ce745759848536e28af7f15b4d0fb983f4b05bd6723635534dd82e5d
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mygegegems.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 kyoendo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Mygegegems
2
+
3
+ Report download numbers of you gems.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mygegegems'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mygegegems
18
+
19
+ ## Usage
20
+
21
+ `mygegegems help` command helps you.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/mygegegems/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/bin/mygegegems ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mygegegems'
4
+
5
+ Mygegegems::CLI.start(ARGV)
data/lib/mygegegems.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "yaml"
2
+ require "gems"
3
+
4
+ require "mygegegems/version"
5
+ require "mygegegems/client"
6
+ require "mygegegems/stat"
7
+ require "mygegegems/cli"
8
+
9
+ module Mygegegems
10
+ DATA_PATH = File.expand_path('~/.mygegegems.yaml')
11
+
12
+ class << self
13
+ def update
14
+ Client.new.update
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,60 @@
1
+ require "thor"
2
+
3
+ module Mygegegems
4
+ class CLI < Thor
5
+ desc "update", "Get latest stat from rubygems.org and update local database"
6
+ def update
7
+ Mygegegems.update
8
+ puts "Your gems data updated!(#{DATA_PATH})"
9
+ rescue => e
10
+ warn "Fail update process. #{e}"
11
+ exit(1)
12
+ end
13
+
14
+ desc "stat", "Show stat of your gems"
15
+ option :target,
16
+ aliases:'-t',
17
+ default:'last',
18
+ desc:"Target to compare. any of 'last', 'last_month' or 'last_year'"
19
+ def stat
20
+ target = options[:target].intern
21
+ date, gems = Stat.latest
22
+ (_, t_date), diffs = Stat.diff(target)
23
+ total, diff_total, num_of_gems = Stat.total(target)
24
+ space1, space2 = [total, diff_total].map { |t| t.to_s.size }
25
+ header = header(date, t_date, target)
26
+
27
+ puts header
28
+ puts "-" * header.size
29
+ puts body(gems, diffs, space1, space2)
30
+ puts "-" * header.size
31
+ puts footer(total, diff_total, num_of_gems, space1, space2)
32
+ end
33
+
34
+ no_tasks do
35
+ def header(date1, date2, label)
36
+ "As of #{date1} (#{label}: \e[33m#{date2}\e[0m)"
37
+ end
38
+
39
+ def body(gems, diffs, space1, space2)
40
+ gems = gems.sort_by { |_, dl| -dl }
41
+ gems.map do |name, dl|
42
+ if diffs && (diff = diffs[name])
43
+ "%#{space1}d \e[33m+%#{space2}d \e[32m%s\e[0m" % [dl, diffs[name], name]
44
+ else
45
+ none = "-".center(space2)
46
+ "%#{space1}d \e[33m#{none} \e[32m%s\e[0m" % [dl, name]
47
+ end
48
+ end
49
+ end
50
+
51
+ def footer(total, diff_total, num_of_gems, space1, space2)
52
+ if diff_total
53
+ "%#{space1}d \e[33m+%#{space2}d \e[32m%s gems\e[0m" % [total, diff_total, num_of_gems]
54
+ else
55
+ "%#{space1}d %s gems" % [total, num_of_gems]
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,31 @@
1
+ module Mygegegems
2
+ class Client
3
+ def initialize(path=DATA_PATH)
4
+ @path = path
5
+ end
6
+
7
+ def update
8
+ data[Date.today] = get
9
+ save(data, @path)
10
+ end
11
+
12
+ private
13
+ def data
14
+ @data ||= load(@path)
15
+ end
16
+
17
+ def get
18
+ Gems.gems.inject({}) { |h, gem| h[gem['name']] = gem['downloads']; h }
19
+ end
20
+
21
+ def load(path)
22
+ YAML.load_file(path)
23
+ rescue Errno::ENOENT
24
+ {}
25
+ end
26
+
27
+ def save(obj, path)
28
+ File.open(path, 'w') { |f| YAML.dump(obj, f) }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,70 @@
1
+ module Mygegegems
2
+ class Stat
3
+ class << self
4
+ def latest
5
+ data.max_by { |date, _| date }
6
+ end
7
+
8
+ def last
9
+ data.sort_by { |date, _| date }[-2]
10
+ end
11
+ alias :last_day :last
12
+
13
+ def last_month
14
+ latest_date, _ = latest
15
+ data.select { |date, _| date.mon == latest_date.mon-1 }
16
+ .max_by { |date, _| date }
17
+ end
18
+ alias :last_mon :last_month
19
+
20
+ def last_year
21
+ latest_date, _ = latest
22
+ data.select { |date, _| date.year == latest_date.year-1 }
23
+ .max_by { |date, _| date }
24
+ end
25
+
26
+ def data
27
+ @data ||= load
28
+ end
29
+
30
+ def diff(target=:last, base=:latest)
31
+ raise ArgumentError unless respond_to?(target) && respond_to?(base)
32
+ res = []
33
+ date, gems = send(base)
34
+ t_date, t_gems = send(target)
35
+ return [] unless t_date
36
+ res << [date, t_date]
37
+ diff = gems.each_with_object({}) do |(name, dl), h|
38
+ t_dl = t_gems[name]
39
+ h[name] = t_dl ? (dl - t_dl) : nil
40
+ end
41
+ res << diff
42
+ res
43
+ end
44
+
45
+ def total(target=:last)
46
+ date, gems = latest
47
+ (date, t_date), diffs = diff(target)
48
+ total = gems.inject(0) { |sum, (_, dl)| sum + dl }
49
+ diff_total =
50
+ if diffs
51
+ diffs.inject(0) do |sum, (_, dl)|
52
+ dl = 0 if dl.nil?
53
+ sum + dl
54
+ end
55
+ else
56
+ nil
57
+ end
58
+ [total, diff_total, gems.size]
59
+ end
60
+
61
+ private
62
+ def load(path=DATA_PATH)
63
+ YAML.load_file(path)
64
+ rescue Errno::ENOENT
65
+ warn "File not found: #{path}"
66
+ exit(1)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module Mygegegems
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mygegegems/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mygegegems"
8
+ spec.version = Mygegegems::VERSION
9
+ spec.authors = ["kyoendo"]
10
+ spec.email = ["postagie@gmail.com"]
11
+ spec.summary = %q{Report download numbers of you gems.}
12
+ spec.homepage = "https://github.com/melborne/mygegegems"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'gems'
21
+ spec.add_dependency 'thor'
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "tildoc"
26
+ end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mygegegems::CLI do
4
+ before(:all) do
5
+ Mygegegems::DATA_PATH = File.join(source_root, 'mygegegems.yaml')
6
+ end
7
+
8
+ before do
9
+ $stdout, $stderr = StringIO.new, StringIO.new
10
+ end
11
+
12
+ after do
13
+ $stdout, $stderr = STDIN, STDERR
14
+ end
15
+
16
+ describe "#stat" do
17
+ it "returns statics of your gems" do
18
+ described_class.start(['stat'])
19
+ expect($stdout.string).to eq ~<<-EOS
20
+ As of 2014-07-11 (last: 2014-07-10)
21
+ -----------------------------------
22
+ 3345 + 0 let_it_fall
23
+ 2225 +100 togglate
24
+ 762 + 2 emot
25
+ 354 + 14 gh-diff
26
+ 299 + 18 matreska
27
+ 297 + 30 tildoc
28
+ -----------------------------------
29
+ 7282 +164 6 gems
30
+ EOS
31
+ end
32
+
33
+ context "with target option" do
34
+ it "returns statics of your gems" do
35
+ described_class.start(['stat', '--target', 'last_month'])
36
+ expect($stdout.string).to eq ~<<-EOS
37
+ As of 2014-07-11 (last_month: 2014-06-30)
38
+ -----------------------------------------
39
+ 3345 +123 let_it_fall
40
+ 2225 +225 togglate
41
+ 762 +162 emot
42
+ 354 - gh-diff
43
+ 299 + 21 matreska
44
+ 297 - tildoc
45
+ -----------------------------------------
46
+ 7282 +531 6 gems
47
+ EOS
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,20 @@
1
+ ---
2
+ 2014-07-11:
3
+ gh-diff: 354
4
+ tildoc: 297
5
+ emot: 762
6
+ let_it_fall: 3345
7
+ togglate: 2225
8
+ matreska: 299
9
+ 2014-07-10:
10
+ gh-diff: 340
11
+ tildoc: 267
12
+ emot: 760
13
+ let_it_fall: 3345
14
+ togglate: 2125
15
+ matreska: 281
16
+ 2014-06-30:
17
+ emot: 600
18
+ let_it_fall: 3222
19
+ togglate: 2000
20
+ matreska: 278
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mygegegems do
4
+ it 'has a version number' do
5
+ expect(Mygegegems::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'mygegegems'
3
+ require "tildoc"
4
+
5
+ module Helpers
6
+ def source_root
7
+ File.join(File.dirname(__FILE__), 'fixtures')
8
+ end
9
+ end
10
+
11
+ RSpec.configure do |c|
12
+ c.include Helpers
13
+ end
data/spec/stat_spec.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mygegegems::Stat do
4
+ before(:all) do
5
+ Mygegegems::DATA_PATH = File.join(source_root, 'mygegegems.yaml')
6
+ end
7
+
8
+ describe ".latest" do
9
+ it "returns latest data" do
10
+ date, gems = described_class.latest
11
+ expect(date.to_s).to eq '2014-07-11'
12
+ expect(gems['emot']).to eq 762
13
+ end
14
+ end
15
+
16
+ describe ".last" do
17
+ it "returns last data(one before latest)" do
18
+ date, gems = described_class.last
19
+ expect(date.to_s).to eq '2014-07-10'
20
+ expect(gems['emot']).to eq 760
21
+ end
22
+ end
23
+
24
+ describe ".last_month" do
25
+ it "returns last month's data" do
26
+ date, gems = described_class.last_month
27
+ expect(date.to_s).to eq '2014-06-30'
28
+ expect(gems['emot']).to eq 600
29
+ end
30
+ end
31
+
32
+ describe ".last_year" do
33
+ it "returns last year's data" do
34
+ date, gems = described_class.last_year
35
+ expect(date).to be_nil
36
+ end
37
+ end
38
+
39
+ describe ".diff" do
40
+ it "raises an error with a wrong argument" do
41
+ expect { described_class.diff(:newest) }.to raise_error(ArgumentError)
42
+ end
43
+
44
+ it "returns differences between last and latest" do
45
+ (date1, date2), gems = described_class.diff(:last)
46
+ expect(date1.to_s).to eq '2014-07-11'
47
+ expect(date2.to_s).to eq '2014-07-10'
48
+ expect(gems['emot']).to eq 2
49
+ expect(gems['tildoc']).to eq 30
50
+ end
51
+
52
+ it "returns differences between last month and latest" do
53
+ (date1, date2), gems = described_class.diff(:last_mon)
54
+ expect(date1.to_s).to eq '2014-07-11'
55
+ expect(date2.to_s).to eq '2014-06-30'
56
+ expect(gems['emot']).to eq 162
57
+ expect(gems['tildoc']).to be_nil
58
+ end
59
+ end
60
+
61
+ describe ".total" do
62
+ it "returns total stats" do
63
+ total, diff_total, gems = described_class.total(:last)
64
+ expect(total).to eq 7282
65
+ expect(diff_total).to eq 164
66
+ expect(gems).to eq 6
67
+ end
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mygegegems
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kyoendo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gems
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: tildoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - postagie@gmail.com
100
+ executables:
101
+ - mygegegems
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/mygegegems
113
+ - lib/mygegegems.rb
114
+ - lib/mygegegems/cli.rb
115
+ - lib/mygegegems/client.rb
116
+ - lib/mygegegems/stat.rb
117
+ - lib/mygegegems/version.rb
118
+ - mygegegems.gemspec
119
+ - spec/cli_spec.rb
120
+ - spec/fixtures/mygegegems.yaml
121
+ - spec/mygegegems_spec.rb
122
+ - spec/spec_helper.rb
123
+ - spec/stat_spec.rb
124
+ homepage: https://github.com/melborne/mygegegems
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.3.0
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Report download numbers of you gems.
148
+ test_files:
149
+ - spec/cli_spec.rb
150
+ - spec/fixtures/mygegegems.yaml
151
+ - spec/mygegegems_spec.rb
152
+ - spec/spec_helper.rb
153
+ - spec/stat_spec.rb