inventory-cli 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 +4 -4
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +0 -2
- data/README.md +26 -5
- data/Rakefile +5 -0
- data/bin/inventory +1 -1
- data/bin/setup +8 -0
- data/bin/setup_database.rb +22 -0
- data/inventory.gemspec +4 -2
- data/lib/inventory.rb +0 -2
- data/lib/inventory/bag.rb +18 -14
- data/lib/inventory/cli.rb +12 -1
- data/lib/inventory/dbconnection.rb +14 -0
- data/lib/inventory/inventory.rb +25 -1
- data/lib/inventory/order.rb +105 -0
- data/lib/inventory/version.rb +1 -1
- metadata +41 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e319dea23b4bc60332cb940ba1dd31c40f9fcf17
|
4
|
+
data.tar.gz: 0e0ceaffccd1f51072965fb15b7411a7da403272
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4801bc75c135729548ab94a7a5346634d9e6ad3b3779ae8aabb15a9bc74cd76b31df82ed2a496d29bcae96d67ab0cbd954f34cb76ec9e188db590f5d899a132
|
7
|
+
data.tar.gz: babfa55ecb9c07082ff53e4b7d19ca4098adcd39f5ef076f3488f515dd508efc8e7bbc6089a4c1637f43d586fae3e5ef5960f537b8fb7d0cd093e4de5b30cf6b
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at skylerclayne@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# Inventory
|
2
|
+
|
3
|
+
[![Join the chat at https://gitter.im/skylerto/inventory](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/skylerto/inventory?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
|
+
|
2
5
|
[![Build
|
3
6
|
Status](https://travis-ci.org/skylerto/inventory.svg?branch=gemify)](https://travis-ci.org/skylerto/inventory)
|
4
7
|
[![Code
|
@@ -8,27 +11,44 @@ Status](https://coveralls.io/repos/skylerto/inventory/badge.svg?branch=master&se
|
|
8
11
|
[![Dependency
|
9
12
|
Status](https://gemnasium.com/skylerto/inventory.svg)](https://gemnasium.com/skylerto/inventory)
|
10
13
|
|
11
|
-
Manage inventory with this.
|
14
|
+
Manage inventory with this and mysql.
|
12
15
|
|
13
16
|
## Installation
|
14
17
|
|
15
18
|
Add this line to your application's Gemfile:
|
16
19
|
|
17
20
|
```ruby
|
18
|
-
gem 'inventory'
|
21
|
+
gem 'inventory-cli'
|
19
22
|
```
|
20
23
|
|
21
24
|
And then execute:
|
22
25
|
|
23
26
|
$ bundle
|
24
27
|
|
25
|
-
Or install it yourself as:
|
28
|
+
Or install it yourself as for the cli by:
|
29
|
+
|
30
|
+
$ gem install inventory-cli
|
31
|
+
|
32
|
+
Add a table to manage:
|
26
33
|
|
27
|
-
|
34
|
+
```bash
|
35
|
+
$ mysql -uroot
|
36
|
+
CREATE TABLE inventory;
|
37
|
+
```
|
28
38
|
|
29
39
|
## Usage
|
30
40
|
|
31
|
-
|
41
|
+
After installation, to get a list of available commands run
|
42
|
+
```
|
43
|
+
$ inventory
|
44
|
+
Commands:
|
45
|
+
inventory add AMOUNT ITEM # Add an amount of an item
|
46
|
+
inventory help [COMMAND] # Describe available commands or one specific command
|
47
|
+
inventory invoice NAME args* # Create an invoice
|
48
|
+
inventory remove AMOUNT ITEM # Remove an amount of an item
|
49
|
+
inventory show # Shows the current state of the inventory
|
50
|
+
```
|
51
|
+
|
32
52
|
|
33
53
|
## Development
|
34
54
|
|
@@ -49,3 +69,4 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
49
69
|
|
50
70
|
- Add some way to control orders, look at how rails goes about `rails generate
|
51
71
|
...` vs `rails server` for inspiration.
|
72
|
+
- Add a script to create a database off the start, maybe like `inventory install`.
|
data/Rakefile
CHANGED
data/bin/inventory
CHANGED
data/bin/setup
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
#ActiveRecord::Tasks::DatabaseTasks.database_configuration = {adapter: 'mysql2', host: 'localhost', database: "inventory"}
|
4
|
+
#ActiveRecord::Tasks::DatabaseTasks.create({adapter: 'mysql2', host: 'localhost', database: "inventory"})
|
5
|
+
|
6
|
+
ActiveRecord::Base.establish_connection(
|
7
|
+
:adapter=> "mysql",
|
8
|
+
:host => "localhost",
|
9
|
+
:database=> "inventory"
|
10
|
+
)
|
11
|
+
|
12
|
+
class CreateThings < ActiveRecord::Migration
|
13
|
+
def self.up
|
14
|
+
create_table :things do |t|
|
15
|
+
t.string :name, null: false
|
16
|
+
t.integer :amount, null: false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
CreateThings.up
|
21
|
+
|
22
|
+
end
|
data/inventory.gemspec
CHANGED
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
# end
|
24
24
|
|
25
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir = "
|
27
|
-
spec.executables =
|
26
|
+
spec.bindir = "bin"
|
27
|
+
spec.executables = ["inventory"]
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
30
|
# Development dependencies
|
@@ -36,4 +36,6 @@ Gem::Specification.new do |spec|
|
|
36
36
|
|
37
37
|
# Production dependencies
|
38
38
|
spec.add_dependency "thor"
|
39
|
+
spec.add_dependency "activerecord"
|
40
|
+
spec.add_dependency "mysql"
|
39
41
|
end
|
data/lib/inventory.rb
CHANGED
data/lib/inventory/bag.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'exceptions'
|
2
|
+
require_relative 'dbconnection'
|
2
3
|
|
3
4
|
class Bag
|
4
5
|
include Enumerable
|
@@ -14,7 +15,8 @@ class Bag
|
|
14
15
|
## => Booleans
|
15
16
|
#Do we have the item?
|
16
17
|
def has?(amount, item)
|
17
|
-
|
18
|
+
Thing.exists?(:name => item) and Thing.find_by(name: item).amount >= amount
|
19
|
+
#@bag.has_key?(item) and @bag[item] >= amount
|
18
20
|
end
|
19
21
|
|
20
22
|
def empty?
|
@@ -28,13 +30,18 @@ class Bag
|
|
28
30
|
raise Exceptions::NotEnoughError
|
29
31
|
"Value must be greater than 0"
|
30
32
|
end
|
31
|
-
if
|
32
|
-
|
33
|
+
if Thing.exists?(:name => item)
|
34
|
+
# find it in the database
|
35
|
+
the_item = Thing.find_by(name: item)
|
36
|
+
the_item.amount += amount
|
37
|
+
the_item.save
|
33
38
|
else
|
34
39
|
@bag[item] = amount
|
40
|
+
Thing.create(:name => item, :amount => amount)
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
44
|
+
# => Should follow
|
38
45
|
def add_all(other)
|
39
46
|
other.each do |item, amount|
|
40
47
|
self.add(amount, item)
|
@@ -43,13 +50,13 @@ class Bag
|
|
43
50
|
|
44
51
|
# Someone bought my things
|
45
52
|
def remove(amount, item)
|
46
|
-
if
|
47
|
-
puts "empty bag"
|
48
|
-
return
|
49
|
-
elsif !self.has?(amount, item)
|
53
|
+
if !self.has?(amount, item)
|
50
54
|
puts "not enough"
|
51
55
|
else
|
52
|
-
|
56
|
+
# find it in the database
|
57
|
+
the_item = Thing.find_by(name: item)
|
58
|
+
the_item.amount -= amount
|
59
|
+
the_item.save
|
53
60
|
end
|
54
61
|
end
|
55
62
|
|
@@ -73,12 +80,9 @@ class Bag
|
|
73
80
|
# Let me know how many things are in my bag man.
|
74
81
|
def print
|
75
82
|
buffer = []
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
buffer << "Current Inventory"
|
80
|
-
@bag.each do |item, amount|
|
81
|
-
buffer << " #{item}: #{amount}"
|
83
|
+
Thing.find_each do |a|
|
84
|
+
if a.amount > 0
|
85
|
+
buffer << " #{a.name}: #{a.amount}"
|
82
86
|
end
|
83
87
|
end
|
84
88
|
buffer
|
data/lib/inventory/cli.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'thor'
|
2
|
-
|
2
|
+
require_relative 'inventory'
|
3
3
|
module Inventory
|
4
4
|
class CLI < Thor
|
5
5
|
|
@@ -14,5 +14,16 @@ module Inventory
|
|
14
14
|
System::Inventory.remove(amount.to_i, item)
|
15
15
|
puts System::Inventory.print
|
16
16
|
end
|
17
|
+
|
18
|
+
desc "show", "Shows the current state of the inventory"
|
19
|
+
def show
|
20
|
+
puts System::Inventory.print
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "invoice NAME args*", "Create an invoice"
|
24
|
+
def invoice(name, *args)
|
25
|
+
System::Inventory.invoice(name, args)
|
26
|
+
puts System::Inventory.print
|
27
|
+
end
|
17
28
|
end
|
18
29
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#require 'rubygems'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
ActiveRecord::Base.establish_connection(
|
5
|
+
:adapter=> "mysql",
|
6
|
+
:host => "localhost",
|
7
|
+
:database=> "inventory"
|
8
|
+
)
|
9
|
+
# :username => "inv",
|
10
|
+
# :password => "inventory_password",
|
11
|
+
|
12
|
+
|
13
|
+
class Thing < ActiveRecord::Base
|
14
|
+
end
|
data/lib/inventory/inventory.rb
CHANGED
@@ -12,7 +12,11 @@ class Inventory
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.add(amount, item)
|
15
|
-
|
15
|
+
if amount > 2147483647
|
16
|
+
puts "Value must be less that 2147483647"
|
17
|
+
else
|
18
|
+
@bag.add(amount, item)
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
def self.add_all(bag)
|
@@ -31,7 +35,27 @@ class Inventory
|
|
31
35
|
@bag.has?(amount, item)
|
32
36
|
end
|
33
37
|
|
38
|
+
def self.invoice(name, *args)
|
39
|
+
puts name
|
40
|
+
this_order = args.at(0)
|
41
|
+
index = 0
|
42
|
+
while index < this_order.size
|
43
|
+
puts index
|
44
|
+
item = this_order[index]
|
45
|
+
puts item
|
46
|
+
index += 1
|
47
|
+
amount = this_order[index]
|
48
|
+
puts amount
|
49
|
+
index += 1
|
50
|
+
# this order add stuff
|
51
|
+
puts
|
52
|
+
end
|
53
|
+
#args.each do |i|
|
54
|
+
#end
|
55
|
+
end
|
56
|
+
|
34
57
|
def self.print
|
58
|
+
puts "INVENTORY: "
|
35
59
|
@bag.print
|
36
60
|
end
|
37
61
|
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require_relative 'exceptions'
|
2
|
+
require_relative 'dbconnection'
|
3
|
+
|
4
|
+
class Order << ActiveRecord::Base
|
5
|
+
include Enumerable
|
6
|
+
# Create the bag
|
7
|
+
def initialize(name)
|
8
|
+
@bag = Hash.new
|
9
|
+
|
10
|
+
create_table :"#{name}" do |t|
|
11
|
+
t.string :item, null:false
|
12
|
+
t.int :amount, null:false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def size
|
17
|
+
@bag.size
|
18
|
+
end
|
19
|
+
|
20
|
+
## => Booleans
|
21
|
+
#Do we have the item?
|
22
|
+
def has?(amount, item)
|
23
|
+
Thing.exists?(:name => item) and Thing.find_by(name: item).amount >= amount
|
24
|
+
#@bag.has_key?(item) and @bag[item] >= amount
|
25
|
+
end
|
26
|
+
|
27
|
+
def empty?
|
28
|
+
@bag.size == 0
|
29
|
+
end
|
30
|
+
|
31
|
+
## => Insertions / Deletions
|
32
|
+
def add(amount, item)
|
33
|
+
|
34
|
+
unless amount > 0
|
35
|
+
raise Exceptions::NotEnoughError
|
36
|
+
"Value must be greater than 0"
|
37
|
+
end
|
38
|
+
if Thing.exists?(:name => item)
|
39
|
+
# find it in the database
|
40
|
+
the_item = Thing.find_by(name: item)
|
41
|
+
the_item.amount += amount
|
42
|
+
the_item.save
|
43
|
+
else
|
44
|
+
@bag[item] = amount
|
45
|
+
Thing.create(:name => item, :amount => amount)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# => Should follow
|
50
|
+
def add_all(other)
|
51
|
+
other.each do |item, amount|
|
52
|
+
self.add(amount, item)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Someone bought my things
|
57
|
+
def remove(amount, item)
|
58
|
+
if !self.has?(amount, item)
|
59
|
+
puts "not enough"
|
60
|
+
else
|
61
|
+
# find it in the database
|
62
|
+
the_item = Thing.find_by(name: item)
|
63
|
+
the_item.amount -= amount
|
64
|
+
the_item.save
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def remove_all(other)
|
69
|
+
if @bag.empty?
|
70
|
+
puts "empty bag"
|
71
|
+
return
|
72
|
+
else
|
73
|
+
other.each do |item, amount|
|
74
|
+
self.remove(amount, item)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
## => Iterating
|
80
|
+
def each(&block)
|
81
|
+
@bag.each(&block)
|
82
|
+
end
|
83
|
+
|
84
|
+
## => Formating
|
85
|
+
# Let me know how many things are in my bag man.
|
86
|
+
def print
|
87
|
+
buffer = []
|
88
|
+
Thing.find_each do |a|
|
89
|
+
buffer << " #{a.name}: #{a.amount}"
|
90
|
+
end
|
91
|
+
#buffer << " #{Thing.all}"
|
92
|
+
|
93
|
+
# if @bag.empty?
|
94
|
+
# buffer << "Bag is empty"
|
95
|
+
# else
|
96
|
+
# buffer << "Current Inventory"
|
97
|
+
# @bag.each do |item, amount|
|
98
|
+
# buffer << " #{Thing.find()}"
|
99
|
+
|
100
|
+
#" #{item}: #{amount}"
|
101
|
+
# end
|
102
|
+
# end
|
103
|
+
buffer
|
104
|
+
end
|
105
|
+
end
|
data/lib/inventory/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inventory-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- skylerto
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,18 +94,49 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activerecord
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: mysql
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
97
125
|
description: A gem that lets you control the flow of products, and orders through
|
98
126
|
invoices
|
99
127
|
email:
|
100
|
-
-
|
101
|
-
|
102
|
-
|
128
|
+
- 'skylerclayne@gmail.com
|
129
|
+
|
130
|
+
'
|
131
|
+
executables:
|
132
|
+
- inventory
|
103
133
|
extensions: []
|
104
134
|
extra_rdoc_files: []
|
105
135
|
files:
|
106
136
|
- ".gitignore"
|
107
137
|
- ".rspec"
|
108
138
|
- ".travis.yml"
|
139
|
+
- CODE_OF_CONDUCT.md
|
109
140
|
- Gemfile
|
110
141
|
- LICENSE.txt
|
111
142
|
- README.md
|
@@ -113,12 +144,15 @@ files:
|
|
113
144
|
- bin/console
|
114
145
|
- bin/inventory
|
115
146
|
- bin/setup
|
147
|
+
- bin/setup_database.rb
|
116
148
|
- inventory.gemspec
|
117
149
|
- lib/inventory.rb
|
118
150
|
- lib/inventory/bag.rb
|
119
151
|
- lib/inventory/cli.rb
|
152
|
+
- lib/inventory/dbconnection.rb
|
120
153
|
- lib/inventory/exceptions.rb
|
121
154
|
- lib/inventory/inventory.rb
|
155
|
+
- lib/inventory/order.rb
|
122
156
|
- lib/inventory/version.rb
|
123
157
|
homepage: https://github.com/skylerto/inventory
|
124
158
|
licenses:
|
@@ -140,9 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
174
|
version: '0'
|
141
175
|
requirements: []
|
142
176
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
177
|
+
rubygems_version: 2.5.1
|
144
178
|
signing_key:
|
145
179
|
specification_version: 4
|
146
180
|
summary: An inventory management gem
|
147
181
|
test_files: []
|
148
|
-
has_rdoc:
|