inventory-cli 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44fbe8616dbfa58b7210503173a573dd3120343f
4
- data.tar.gz: a5b1793a96b890dd847d90c2208fb478f2134fa4
3
+ metadata.gz: e319dea23b4bc60332cb940ba1dd31c40f9fcf17
4
+ data.tar.gz: 0e0ceaffccd1f51072965fb15b7411a7da403272
5
5
  SHA512:
6
- metadata.gz: 17dae877aee8456ac258f901f58a553dd25d0bb072089f0b57bb9d0d26876f175ebfb0b246fd1a37560995ab5fb28d98c463b6d6f90438855ebfa5edc0da4322
7
- data.tar.gz: 2dca8ade19966c70d73cf7317eac8e2656268a8700c7f29f253d6286a3ff755f0a03ec1148edb223b7a4bb4018ee5793a37fed3cba7a751596c0d755097fc73c
6
+ metadata.gz: f4801bc75c135729548ab94a7a5346634d9e6ad3b3779ae8aabb15a9bc74cd76b31df82ed2a496d29bcae96d67ab0cbd954f34cb76ec9e188db590f5d899a132
7
+ data.tar.gz: babfa55ecb9c07082ff53e4b7d19ca4098adcd39f5ef076f3488f515dd508efc8e7bbc6089a4c1637f43d586fae3e5ef5960f537b8fb7d0cd093e4de5b30cf6b
@@ -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
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in inventory.gemspec
4
4
  gemspec
5
-
6
- gem 'coveralls', require: false
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
- $ gem install inventory
34
+ ```bash
35
+ $ mysql -uroot
36
+ CREATE TABLE inventory;
37
+ ```
28
38
 
29
39
  ## Usage
30
40
 
31
- no
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
@@ -4,3 +4,8 @@ require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :default => :spec
7
+
8
+ desc "Sets up the database"
9
+ task :setup do
10
+ exec("./bin/setup")
11
+ end
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'inventory/cli'
2
+ require_relative '../lib/inventory/cli'
3
3
 
4
4
  Inventory::CLI.start
data/bin/setup CHANGED
@@ -1,7 +1,15 @@
1
1
  #!/bin/bash
2
+
2
3
  set -euo pipefail
3
4
  IFS=$'\n\t'
4
5
 
6
+
5
7
  bundle install
6
8
 
9
+ # Creates the database table
10
+ ruby ./bin/setup_database.rb
11
+
7
12
  # Do any other automated setup that you need to do here
13
+
14
+ # CREATE DATABASE AND USER, GRANT PERMISSIONS
15
+
@@ -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
@@ -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 = "exe"
27
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
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
@@ -1,6 +1,4 @@
1
1
  require "inventory/version"
2
- require "inventory/inventory"
3
- #require "inventory/bag"
4
2
 
5
3
  module Inventory
6
4
  # Your code goes here...
@@ -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
- @bag.has_key?(item) and @bag[item] >= amount
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 @bag.has_key?(item)
32
- @bag[item] += amount
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 @bag.empty?
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
- @bag[item] -= amount
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
- if @bag.empty?
77
- buffer << "Bag is empty"
78
- else
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
@@ -1,5 +1,5 @@
1
1
  require 'thor'
2
- require 'inventory'
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
@@ -12,7 +12,11 @@ class Inventory
12
12
  end
13
13
 
14
14
  def self.add(amount, item)
15
- @bag.add(amount, item)
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
@@ -1,3 +1,3 @@
1
1
  module Inventory
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - skylerto
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-09 00:00:00.000000000 Z
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
- skylerclayne@gmail.com
102
- executables: []
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.4.5
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: