openbill-ruby 0.1.10 → 0.1.11
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 +4 -4
- data/CHANGELOG.md +1 -0
- data/db/migrate/20160320150928_add_openbill.rb +3 -18
- data/lib/openbill.rb +17 -3
- data/lib/openbill/category.rb +8 -0
- data/lib/openbill/database.rb +4 -3
- data/lib/openbill/migration.rb +35 -0
- data/lib/openbill/service.rb +16 -1
- data/lib/openbill/version.rb +1 -1
- data/openbill-ruby.gemspec +5 -0
- metadata +61 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fece53206838ee77a91700fa51f423e195e16a35
|
4
|
+
data.tar.gz: fd9126c93d7d8e57fadb32c247676b46884e1f90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f236888aded1c32b29ffc31a2d1a31cc1387333f82693a83cdb2fbdd059984d569970a5f2e7d4a4fd712ece23cc4f0983b3397ef766c2068539719c235e0e290
|
7
|
+
data.tar.gz: e9b78877fc40b00b99161663411dc48f9ae8f99c1033a4fe852c0b17b026024ae999963b9189b3a17b5df999556d35f1c91d475c6cf6ae0b6001210539120330
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* Rename Openbill.current to Openbill.service
|
@@ -1,20 +1,5 @@
|
|
1
|
-
|
2
|
-
def up
|
3
|
-
Dir.entries(sql_dir).select{|f| File.file? sql_dir + f }.sort.each do |file|
|
4
|
-
say_with_time "Migrate with #{file}" do
|
5
|
-
execute File.read sql_dir + file
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def down
|
11
|
-
execute "DROP TABLE openbill_accounts CASCADE"
|
12
|
-
execute "DROP TABLE openbill_transactions CASCADE"
|
13
|
-
end
|
1
|
+
require 'openbill/migration'
|
14
2
|
|
15
|
-
|
16
|
-
|
17
|
-
def sql_dir
|
18
|
-
Openbill.root + '/sql/'
|
19
|
-
end
|
3
|
+
class AddOpenbill < ActiveRecord::Migration
|
4
|
+
include Openbill::Migration
|
20
5
|
end
|
data/lib/openbill.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'openbill/engine'
|
2
|
+
|
2
3
|
module Openbill
|
3
|
-
autoload :
|
4
|
+
autoload :Category, 'openbill/category'
|
4
5
|
autoload :Account, 'openbill/account'
|
6
|
+
autoload :Service, 'openbill/service'
|
5
7
|
autoload :Transaction, 'openbill/transaction'
|
6
8
|
autoload :Configuration, 'openbill/configuration'
|
7
9
|
autoload :Registry, 'openbill/registry'
|
@@ -17,6 +19,7 @@ module Openbill
|
|
17
19
|
|
18
20
|
def configure
|
19
21
|
yield self.config
|
22
|
+
service
|
20
23
|
end
|
21
24
|
|
22
25
|
def config
|
@@ -24,9 +27,20 @@ module Openbill
|
|
24
27
|
end
|
25
28
|
|
26
29
|
def current
|
27
|
-
|
30
|
+
deprecate 'Openbill.current is deprecated. Use Openbill.service instead'
|
31
|
+
service
|
32
|
+
end
|
33
|
+
|
34
|
+
# Return default Openbill::Service instance
|
35
|
+
#
|
36
|
+
def service
|
37
|
+
return @service if @service
|
38
|
+
|
39
|
+
@service = Openbill::Service.new config
|
40
|
+
end
|
28
41
|
|
29
|
-
|
42
|
+
def deprecate(message)
|
43
|
+
STDERR.puts "DEPRECATE: #{message}"
|
30
44
|
end
|
31
45
|
end
|
32
46
|
end
|
data/lib/openbill/database.rb
CHANGED
@@ -2,13 +2,14 @@ module Openbill
|
|
2
2
|
class Database
|
3
3
|
MAX_CONNECTIONS = 10
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
7
|
-
@db = Sequel.connect db_config, logger: logger, max_connections: MAX_CONNECTIONS
|
5
|
+
def initialize(config)
|
6
|
+
@db = Sequel.connect config, logger: logger, max_connections: MAX_CONNECTIONS
|
8
7
|
@db.extension :pagination
|
9
8
|
@db.extension :pg_hstore
|
10
9
|
end
|
11
10
|
|
11
|
+
attr_reader :db
|
12
|
+
|
12
13
|
delegate :logger, to: Rails
|
13
14
|
end
|
14
15
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Openbill::Migration
|
2
|
+
def up
|
3
|
+
openbill_up
|
4
|
+
end
|
5
|
+
|
6
|
+
def down
|
7
|
+
openbill_down
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def openbill_up
|
13
|
+
Dir.entries(sql_dir).select{|f| File.file? sql_dir + f }.sort.each do |file|
|
14
|
+
say_with_time "Migrate with #{file}" do
|
15
|
+
execute File.read sql_dir + file
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def openbill_down
|
21
|
+
execute "DROP TABLE IF EXISTS OPENBILL_ACCOUNTS CASCADE"
|
22
|
+
execute "DROP TABLE IF EXISTS OPENBILL_TRANSACTIONS CASCADE"
|
23
|
+
execute "DROP TABLE IF EXISTS OPENBILL_GOODS CASCADE"
|
24
|
+
execute "DROP TABLE IF EXISTS OPENBILL_GOODS_AVAILABILITIES CASCADE"
|
25
|
+
end
|
26
|
+
|
27
|
+
def openbill_reset
|
28
|
+
down
|
29
|
+
up
|
30
|
+
end
|
31
|
+
|
32
|
+
def sql_dir
|
33
|
+
Openbill.root + '/sql/'
|
34
|
+
end
|
35
|
+
end
|
data/lib/openbill/service.rb
CHANGED
@@ -4,11 +4,27 @@ require 'money'
|
|
4
4
|
module Openbill
|
5
5
|
|
6
6
|
class Service
|
7
|
+
attr_reader :database, :config
|
8
|
+
|
7
9
|
def initialize(config)
|
8
10
|
@config = config
|
9
11
|
@database = Openbill::Database.new config.database
|
10
12
|
end
|
11
13
|
|
14
|
+
def categories
|
15
|
+
database
|
16
|
+
.db[ACCOUNTS_TABLE_NAME]
|
17
|
+
.group_and_count(:category)
|
18
|
+
.all
|
19
|
+
.map { |raw| Category.new name: raw[:category], accounts_count: raw[:count] }
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return accounts repositiory (actualy sequel dataset)
|
23
|
+
#
|
24
|
+
def accounts
|
25
|
+
Openbill::Account.dataset
|
26
|
+
end
|
27
|
+
|
12
28
|
# @param ident - ident аккаунта в виде: [:category, :key]
|
13
29
|
#
|
14
30
|
# @param options - опции применяемые для создания аккаунта (см create_account)
|
@@ -74,7 +90,6 @@ module Openbill
|
|
74
90
|
|
75
91
|
private
|
76
92
|
|
77
|
-
attr_reader :database, :config
|
78
93
|
|
79
94
|
delegate :logger, to: Rails
|
80
95
|
|
data/lib/openbill/version.rb
CHANGED
data/openbill-ruby.gemspec
CHANGED
@@ -19,6 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.add_dependency "money"
|
23
|
+
spec.add_dependency "sequel"
|
24
|
+
spec.add_dependency "virtus"
|
25
|
+
spec.add_dependency "pg"
|
26
|
+
|
22
27
|
spec.add_development_dependency "bundler", "~> 1.10"
|
23
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
29
|
spec.add_development_dependency "minitest"
|
metadata
CHANGED
@@ -1,15 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openbill-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danil Pismenny
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: money
|
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: sequel
|
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: virtus
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pg
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
13
69
|
- !ruby/object:Gem::Dependency
|
14
70
|
name: bundler
|
15
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,6 +117,7 @@ extra_rdoc_files: []
|
|
61
117
|
files:
|
62
118
|
- ".gitignore"
|
63
119
|
- ".travis.yml"
|
120
|
+
- CHANGELOG.md
|
64
121
|
- CODE_OF_CONDUCT.md
|
65
122
|
- Gemfile
|
66
123
|
- LICENSE.txt
|
@@ -72,9 +129,11 @@ files:
|
|
72
129
|
- lib/openbill-ruby.rb
|
73
130
|
- lib/openbill.rb
|
74
131
|
- lib/openbill/account.rb
|
132
|
+
- lib/openbill/category.rb
|
75
133
|
- lib/openbill/configuration.rb
|
76
134
|
- lib/openbill/database.rb
|
77
135
|
- lib/openbill/engine.rb
|
136
|
+
- lib/openbill/migration.rb
|
78
137
|
- lib/openbill/registry.rb
|
79
138
|
- lib/openbill/service.rb
|
80
139
|
- lib/openbill/transaction.rb
|