djoini 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -13
- data/Rakefile +0 -1
- data/config/database.yml +11 -0
- data/config/database.yml.travis +4 -0
- data/lib/djoini/connection.rb +16 -4
- data/lib/djoini/version.rb +1 -1
- data/lib/tasks/load.rake +0 -13
- data/spec/djoini/model_spec.rb +14 -0
- data/spec/spec_helper.rb +10 -3
- metadata +4 -4
- data/spec/database.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 870f9cfc0a600280051364300fb115d5a713d2fc
|
4
|
+
data.tar.gz: 73c7d52393c9f1153dce426a8eeed869e44c647e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed50e4c22e6c7bce5324b515790ecad6469e8f25fd4e2476a6c58fa74878f99cb760fedcdedeab698ee629c2a7ba73f865f465a5494e2b73e2c423db923f60f1
|
7
|
+
data.tar.gz: 57676310a0640557db3a1adf8c847d324d54eb772c5dc4965f61c067c443a1e4cdb9c5e30f8e88c56854a47a4ab4721979577018e1ec623382056e82f1fac1b0
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Djoini
|
2
|
+
[![Build Status](https://travis-ci.org/Faulik/djoini.svg?branch=master)](https://travis-ci.org/Faulik/djoini)
|
2
3
|
|
3
|
-
DJsOnINI is a
|
4
|
+
DJsOnINI is a implementation of ActiveRecord pattern and a fixture loader for json and ini formats. It implement's only a little part of pattern, so isn't usable in serious applications.
|
4
5
|
|
5
6
|
Thing's that are implemented:
|
6
7
|
- Djoini::Base class to inherit from
|
@@ -38,7 +39,7 @@ Or install it yourself as:
|
|
38
39
|
**Important**
|
39
40
|
Make appropriate tables or use other gem to create migrations. This gem doesn't handle migrations only mapping and loading.
|
40
41
|
|
41
|
-
Also you need to create database.yml in your `PWD/config/` folder with
|
42
|
+
Also you need to create database.yml in your `PWD/config/` folder with at least this content to use local db with specified credentials.
|
42
43
|
|
43
44
|
```yaml
|
44
45
|
postgres:
|
@@ -60,7 +61,7 @@ class Post < Djoini::Base # Inherit from Base class to use the power of ActiveRe
|
|
60
61
|
end
|
61
62
|
```
|
62
63
|
|
63
|
-
After that just use them like you normaly would with
|
64
|
+
After that just use them like you normaly would with ActiveRecord:
|
64
65
|
|
65
66
|
```ruby
|
66
67
|
user = User.create(name: 'Jack', last_name: 'Daniels')
|
@@ -75,6 +76,9 @@ user.destroy
|
|
75
76
|
For more examples see tests.
|
76
77
|
|
77
78
|
### Rake task usage
|
79
|
+
|
80
|
+
Example app can be found at https://github.com/Faulik/djoini_example .
|
81
|
+
|
78
82
|
**Important**
|
79
83
|
- With `mixed` loading .ini files will be loaded first.
|
80
84
|
- All file names must be named after coresponding tables, not models.
|
@@ -92,7 +96,7 @@ To load fixtures all fixtures(both ini and json) from default directory(`PWD/db/
|
|
92
96
|
bundle exec rake djoini:load
|
93
97
|
```
|
94
98
|
|
95
|
-
To load only ini fixtures, overrides options in config file:
|
99
|
+
To load only `ini` fixtures, overrides options in config file:
|
96
100
|
|
97
101
|
```
|
98
102
|
bundle exec rake djoini:load[ini]
|
@@ -108,19 +112,10 @@ end
|
|
108
112
|
```
|
109
113
|
Djoini will try to find `PWD/config/initializers/djoini.rb` and load it.
|
110
114
|
|
111
|
-
|
112
|
-
## Development
|
113
|
-
|
114
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
115
|
-
|
116
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
117
|
-
|
118
115
|
## Contributing
|
119
116
|
|
120
117
|
Bug reports and pull requests are welcome on GitHub at https://github.com/faullik/djoini. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
121
118
|
|
122
|
-
|
123
119
|
## License
|
124
120
|
|
125
121
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
126
|
-
|
data/Rakefile
CHANGED
data/config/database.yml
ADDED
data/lib/djoini/connection.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require 'pg'
|
3
|
+
require 'yaml'
|
3
4
|
|
4
5
|
# Holds connection singleton class
|
5
6
|
module Djoini
|
@@ -11,21 +12,32 @@ module Djoini
|
|
11
12
|
class Connection
|
12
13
|
include Singleton
|
13
14
|
|
14
|
-
|
15
|
+
def conn
|
16
|
+
db || load_database
|
17
|
+
end
|
15
18
|
|
16
19
|
def establish_connection(params)
|
17
20
|
_adapter = params.fetch('adapter', 'postgres')
|
18
21
|
_username = params.fetch('username')
|
19
|
-
_password = params.fetch('password')
|
22
|
+
_password = params.fetch('password', '')
|
20
23
|
_host = params.fetch('host', 'localhost')
|
21
24
|
_port = params.fetch('port', '5432')
|
22
25
|
_db_name = params.fetch('db_name')
|
23
26
|
|
24
|
-
|
27
|
+
self.db = PG.connect("#{_adapter}://#{_username}:#{_password}@#{_host}:#{_port}/#{_db_name}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.load_database(db_name = 'postgres')
|
31
|
+
_db_config_path = File.join(Dir.pwd, '/config/database.yml')
|
32
|
+
|
33
|
+
fail unless File.file?(_db_config_path)
|
34
|
+
|
35
|
+
_conn_config = YAML.load(File.read(_db_config_path))
|
36
|
+
Djoini::Connection.instance.establish_connection(_conn_config[db_name])
|
25
37
|
end
|
26
38
|
|
27
39
|
private
|
28
40
|
|
29
|
-
|
41
|
+
attr_accessor :db
|
30
42
|
end
|
31
43
|
end
|
data/lib/djoini/version.rb
CHANGED
data/lib/tasks/load.rake
CHANGED
@@ -6,8 +6,6 @@ namespace :djoini do
|
|
6
6
|
|
7
7
|
load_configuration
|
8
8
|
|
9
|
-
load_database
|
10
|
-
|
11
9
|
_loader = Djoini::Files.new
|
12
10
|
|
13
11
|
_type = args[:type] || Djoini.configuration.fixtures_type
|
@@ -24,15 +22,4 @@ namespace :djoini do
|
|
24
22
|
# To make sure configure was called if initializer wasn't found
|
25
23
|
Djoini.configure {}
|
26
24
|
end
|
27
|
-
|
28
|
-
def load_database
|
29
|
-
require 'yaml'
|
30
|
-
|
31
|
-
_db_config_path = File.join(Dir.pwd, '/config/database.yml')
|
32
|
-
|
33
|
-
fail unless File.file?(_db_config_path)
|
34
|
-
|
35
|
-
_conn_config = YAML.load(File.read(_db_config_path))
|
36
|
-
Djoini::Connection.instance.establish_connection(_conn_config['postgres'])
|
37
|
-
end
|
38
25
|
end
|
data/spec/djoini/model_spec.rb
CHANGED
@@ -54,4 +54,18 @@ describe Djoini::Base do
|
|
54
54
|
expect(_users[0].last_name).to eq 'Beggins'
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
context 'nonexisting table ' do
|
59
|
+
it 'expected to 0 rows' do
|
60
|
+
_table = Djoini::Table.new(name: 'NonExist')
|
61
|
+
|
62
|
+
expect(_table.columns.count).to eq 0
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'expected to fail on insert' do
|
66
|
+
_table = Djoini::Table.new(name: 'NonExist')
|
67
|
+
|
68
|
+
expect { _table.insert(name: 'Bull') }.to raise_error(RuntimeError)
|
69
|
+
end
|
70
|
+
end
|
57
71
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'yaml'
|
3
2
|
require 'pry'
|
4
3
|
|
5
4
|
require_relative '../lib/djoini'
|
6
5
|
|
7
|
-
|
6
|
+
Djoini::Connection.load_database('test')
|
8
7
|
|
9
|
-
Djoini
|
8
|
+
Djoini.db.exec("CREATE TABLE IF NOT EXISTS users
|
9
|
+
(
|
10
|
+
id SERIAL,
|
11
|
+
name text,
|
12
|
+
last_name text,
|
13
|
+
age integer,
|
14
|
+
CONSTRAINT user_pk PRIMARY KEY (id)
|
15
|
+
)
|
16
|
+
")
|
10
17
|
|
11
18
|
require_relative 'models/post'
|
12
19
|
require_relative 'models/user'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: djoini
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- faul
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -119,6 +119,8 @@ files:
|
|
119
119
|
- Rakefile
|
120
120
|
- bin/console
|
121
121
|
- bin/setup
|
122
|
+
- config/database.yml
|
123
|
+
- config/database.yml.travis
|
122
124
|
- lib/djoini.rb
|
123
125
|
- lib/djoini/base.rb
|
124
126
|
- lib/djoini/composite.rb
|
@@ -134,7 +136,6 @@ files:
|
|
134
136
|
- lib/djoini/table.rb
|
135
137
|
- lib/djoini/version.rb
|
136
138
|
- lib/tasks/load.rake
|
137
|
-
- spec/database.yml
|
138
139
|
- spec/djoini/model_spec.rb
|
139
140
|
- spec/djoini/task_fixtures/users.ini
|
140
141
|
- spec/djoini/task_fixtures/users.json
|
@@ -167,7 +168,6 @@ signing_key:
|
|
167
168
|
specification_version: 4
|
168
169
|
summary: Implimentation of ActiveModel pattern and a fixture loader
|
169
170
|
test_files:
|
170
|
-
- spec/database.yml
|
171
171
|
- spec/djoini/model_spec.rb
|
172
172
|
- spec/djoini/task_fixtures/users.ini
|
173
173
|
- spec/djoini/task_fixtures/users.json
|