minidoc 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/minidoc.rb +0 -27
- data/lib/minidoc/associations.rb +5 -0
- data/lib/minidoc/version.rb +1 -1
- data/spec/minidoc/associations_spec.rb +8 -0
- data/spec/spec_helper.rb +2 -2
- metadata +2 -17
- data/.codeclimate.yml +0 -16
- data/.gitignore +0 -17
- data/.rspec +0 -2
- data/.rubocop.yml +0 -152
- data/.ruby-version +0 -1
- data/.travis.yml +0 -12
- data/CHANGELOG.md +0 -65
- data/CODE_OF_CONDUCT.md +0 -49
- data/Gemfile +0 -8
- data/LICENSE.txt +0 -22
- data/README.md +0 -154
- data/Rakefile +0 -6
- data/minidoc.gemspec +0 -24
- data/spec/locale/en.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: f94229d111dbbb7b7abdaaf21036b775c4dae1f0
|
4
|
+
data.tar.gz: 79957eed89f74d4564806d05e12b0f6c095e3bc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a74d5b6d68dbfd2abd69b669ca8ac5be982da8cfe643357aa4707f1a0e5d9a0bcd13942dd4be8ea541cb1ab957b3c6ad0b8d80a9e49a694eda2b5b5741a43c6
|
7
|
+
data.tar.gz: eb0c2fb02647e48fbce4e3ca68f9868d82f26d2032741ea312697ffc041a2ebcfa6033464aa6d2e95c5b4176782681b296876bf8afff4c8f08c8023739e565a2
|
data/lib/minidoc.rb
CHANGED
@@ -79,28 +79,6 @@ class Minidoc
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
# For databases that support it (e.g. TokuMX), perform the block within a
|
83
|
-
# transaction. For information on the +isolation+ argument, see
|
84
|
-
# https://www.percona.com/doc/percona-tokumx/commands.html#beginTransaction
|
85
|
-
def self.transaction(isolation = "mvcc")
|
86
|
-
return yield unless tokumx?
|
87
|
-
|
88
|
-
begin
|
89
|
-
database.command(beginTransaction: 1, isolation: isolation)
|
90
|
-
yield
|
91
|
-
rescue Exception => error
|
92
|
-
database.command(rollbackTransaction: 1) rescue nil
|
93
|
-
raise
|
94
|
-
ensure
|
95
|
-
begin
|
96
|
-
database.command(commitTransaction: 1) unless error
|
97
|
-
rescue Exception
|
98
|
-
database.command(rollbackTransaction: 1)
|
99
|
-
raise
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
82
|
# Rescue a duplicate key exception in the given block. Returns the result of
|
105
83
|
# the block, or +false+ if the exception was raised.
|
106
84
|
def self.rescue_duplicate_key_errors
|
@@ -115,11 +93,6 @@ class Minidoc
|
|
115
93
|
end
|
116
94
|
end
|
117
95
|
|
118
|
-
def self.tokumx?
|
119
|
-
@server_info ||= connection.server_info
|
120
|
-
@server_info.key?("tokumxVersion")
|
121
|
-
end
|
122
|
-
|
123
96
|
def initialize(attrs = {})
|
124
97
|
if attrs["_id"].nil? && attrs[:_id].nil?
|
125
98
|
attrs[:_id] = BSON::ObjectId.new
|
data/lib/minidoc/associations.rb
CHANGED
@@ -28,6 +28,11 @@ module Minidoc::Associations
|
|
28
28
|
define_method(association_name) do
|
29
29
|
read_association(association_name)
|
30
30
|
end
|
31
|
+
|
32
|
+
define_method("#{association_name}!") do
|
33
|
+
read_association(association_name) or
|
34
|
+
raise Minidoc::DocumentNotFoundError
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
data/lib/minidoc/version.rb
CHANGED
@@ -30,8 +30,16 @@ describe Minidoc::Associations do
|
|
30
30
|
user = User.create
|
31
31
|
cat = Cat.new(owner_id: user.id)
|
32
32
|
expect(cat.owner.id).to eq user.id
|
33
|
+
expect(cat.owner!.id).to eq user.id
|
33
34
|
cat.save
|
34
35
|
expect(cat.owner.id).to eq user.id
|
36
|
+
expect(cat.owner!.id).to eq user.id
|
37
|
+
end
|
38
|
+
|
39
|
+
it "defines methods that raise when not found" do
|
40
|
+
cat = Cat.new
|
41
|
+
cat.owner_id = BSON::ObjectId.new
|
42
|
+
expect { cat.owner! }.to raise_error(Minidoc::DocumentNotFoundError)
|
35
43
|
end
|
36
44
|
|
37
45
|
it "caches the association cache rather than go to the database each time" do
|
data/spec/spec_helper.rb
CHANGED
@@ -22,9 +22,9 @@ class SecondUser < Minidoc
|
|
22
22
|
attribute :age, Integer
|
23
23
|
end
|
24
24
|
|
25
|
-
$mongo = Mongo::MongoClient.from_uri(ENV["MONGODB_URI"] || "mongodb://localhost")
|
25
|
+
$mongo = Mongo::MongoClient.from_uri(ENV["MONGODB_URI"] || "mongodb://localhost/minidoc_test")
|
26
26
|
Minidoc.connection = $mongo
|
27
|
-
Minidoc.database_name =
|
27
|
+
Minidoc.database_name = $mongo.db.name
|
28
28
|
|
29
29
|
RSpec.configure do |config|
|
30
30
|
if config.files_to_run.one?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minidoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Helmkamp
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -93,18 +93,6 @@ executables: []
|
|
93
93
|
extensions: []
|
94
94
|
extra_rdoc_files: []
|
95
95
|
files:
|
96
|
-
- ".codeclimate.yml"
|
97
|
-
- ".gitignore"
|
98
|
-
- ".rspec"
|
99
|
-
- ".rubocop.yml"
|
100
|
-
- ".ruby-version"
|
101
|
-
- ".travis.yml"
|
102
|
-
- CHANGELOG.md
|
103
|
-
- CODE_OF_CONDUCT.md
|
104
|
-
- Gemfile
|
105
|
-
- LICENSE.txt
|
106
|
-
- README.md
|
107
|
-
- Rakefile
|
108
96
|
- lib/minidoc.rb
|
109
97
|
- lib/minidoc/associations.rb
|
110
98
|
- lib/minidoc/autoload.rb
|
@@ -120,8 +108,6 @@ files:
|
|
120
108
|
- lib/minidoc/validations.rb
|
121
109
|
- lib/minidoc/value.rb
|
122
110
|
- lib/minidoc/version.rb
|
123
|
-
- minidoc.gemspec
|
124
|
-
- spec/locale/en.yml
|
125
111
|
- spec/minidoc/associations_spec.rb
|
126
112
|
- spec/minidoc/connection_spec.rb
|
127
113
|
- spec/minidoc/counters_spec.rb
|
@@ -157,7 +143,6 @@ signing_key:
|
|
157
143
|
specification_version: 4
|
158
144
|
summary: Lightweight wrapper for MongoDB documents
|
159
145
|
test_files:
|
160
|
-
- spec/locale/en.yml
|
161
146
|
- spec/minidoc/associations_spec.rb
|
162
147
|
- spec/minidoc/connection_spec.rb
|
163
148
|
- spec/minidoc/counters_spec.rb
|
data/.codeclimate.yml
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
################################################################################
|
2
|
-
# Metrics
|
3
|
-
################################################################################
|
4
|
-
|
5
|
-
Metrics/LineLength:
|
6
|
-
Enabled: false
|
7
|
-
|
8
|
-
Metrics/AbcSize:
|
9
|
-
Enabled: false
|
10
|
-
|
11
|
-
################################################################################
|
12
|
-
# Style
|
13
|
-
################################################################################
|
14
|
-
|
15
|
-
# Executables are conventionally named bin/foo-bar
|
16
|
-
Style/FileName:
|
17
|
-
Exclude:
|
18
|
-
- bin/**/*
|
19
|
-
|
20
|
-
# We don't (currently) document our code
|
21
|
-
Style/Documentation:
|
22
|
-
Enabled: false
|
23
|
-
|
24
|
-
# Always use double-quotes to keep things simple
|
25
|
-
Style/StringLiterals:
|
26
|
-
EnforcedStyle: double_quotes
|
27
|
-
|
28
|
-
Style/StringLiteralsInInterpolation:
|
29
|
-
EnforcedStyle: double_quotes
|
30
|
-
|
31
|
-
# Use a trailing comma to keep diffs clean when elements are inserted or removed
|
32
|
-
Style/TrailingCommaInArguments:
|
33
|
-
EnforcedStyleForMultiline: comma
|
34
|
-
|
35
|
-
Style/TrailingCommaInLiteral:
|
36
|
-
EnforcedStyleForMultiline: comma
|
37
|
-
|
38
|
-
# We avoid GuardClause because it can result in "suprise return"
|
39
|
-
Style/GuardClause:
|
40
|
-
Enabled: false
|
41
|
-
|
42
|
-
# We avoid IfUnlessModifier because it can result in "suprise if"
|
43
|
-
Style/IfUnlessModifier:
|
44
|
-
Enabled: false
|
45
|
-
|
46
|
-
# We don't care about the fail/raise distinction
|
47
|
-
Style/SignalException:
|
48
|
-
EnforcedStyle: only_raise
|
49
|
-
|
50
|
-
Style/DotPosition:
|
51
|
-
EnforcedStyle: trailing
|
52
|
-
|
53
|
-
# Common globals we allow
|
54
|
-
Style/GlobalVars:
|
55
|
-
AllowedVariables:
|
56
|
-
- "$statsd"
|
57
|
-
- "$mongo"
|
58
|
-
- "$rollout"
|
59
|
-
|
60
|
-
# Using english names requires loading an extra module, which is annoying, so
|
61
|
-
# we prefer the perl names for consistency.
|
62
|
-
Style/SpecialGlobalVars:
|
63
|
-
EnforcedStyle: use_perl_names
|
64
|
-
|
65
|
-
# We have common cases where has_ and have_ make sense
|
66
|
-
Style/PredicateName:
|
67
|
-
Enabled: true
|
68
|
-
NamePrefixBlacklist:
|
69
|
-
- is_
|
70
|
-
|
71
|
-
# We use %w[ ], not %w( ) because the former looks like an array
|
72
|
-
Style/PercentLiteralDelimiters:
|
73
|
-
PreferredDelimiters:
|
74
|
-
"%i": "[]"
|
75
|
-
"%I": "[]"
|
76
|
-
"%w": "[]"
|
77
|
-
"%W": "[]"
|
78
|
-
|
79
|
-
# Allow "trivial" accessors when defined as a predicate? method
|
80
|
-
Style/TrivialAccessors:
|
81
|
-
AllowPredicates: true
|
82
|
-
|
83
|
-
Style/Next:
|
84
|
-
Enabled: false
|
85
|
-
|
86
|
-
# We think it's OK to use the "extend self" module pattern
|
87
|
-
Style/ModuleFunction:
|
88
|
-
Enabled: false
|
89
|
-
|
90
|
-
# Disallow extra spacing for token alignment
|
91
|
-
Style/ExtraSpacing:
|
92
|
-
AllowForAlignment: false
|
93
|
-
|
94
|
-
# and/or in conditionals has no meaningful difference (only gotchas), so we
|
95
|
-
# disallow them there. When used for control flow, the difference in precedence
|
96
|
-
# can make for a less noisy expression, as in:
|
97
|
-
#
|
98
|
-
# x = find_x or raise XNotFound
|
99
|
-
#
|
100
|
-
Style/AndOr:
|
101
|
-
EnforcedStyle: conditionals
|
102
|
-
|
103
|
-
Style/AlignParameters:
|
104
|
-
EnforcedStyle: with_fixed_indentation
|
105
|
-
|
106
|
-
Style/MultilineOperationIndentation:
|
107
|
-
EnforcedStyle: indented
|
108
|
-
|
109
|
-
Style/AlignHash:
|
110
|
-
EnforcedLastArgumentHashStyle: ignore_implicit
|
111
|
-
|
112
|
-
# This has the behavior we want, but it has a bug in it which produces a lot of false positives
|
113
|
-
# https://github.com/bbatsov/rubocop/issues/3462
|
114
|
-
# MultilineMethodCallBraceLayout:
|
115
|
-
# EnforcedStyle: new_line
|
116
|
-
|
117
|
-
################################################################################
|
118
|
-
# Performance
|
119
|
-
################################################################################
|
120
|
-
|
121
|
-
Performance/RedundantMerge:
|
122
|
-
Enabled: false
|
123
|
-
|
124
|
-
################################################################################
|
125
|
-
# Rails - disable things because we're primarily non-rails
|
126
|
-
################################################################################
|
127
|
-
|
128
|
-
Rails/Delegate:
|
129
|
-
Enabled: false
|
130
|
-
|
131
|
-
Rails/TimeZone:
|
132
|
-
Enabled: false
|
133
|
-
|
134
|
-
################################################################################
|
135
|
-
# Specs - be more lenient on length checks and block styles
|
136
|
-
################################################################################
|
137
|
-
|
138
|
-
Metrics/ModuleLength:
|
139
|
-
Exclude:
|
140
|
-
- spec/**/*
|
141
|
-
|
142
|
-
Metrics/MethodLength:
|
143
|
-
Exclude:
|
144
|
-
- spec/**/*
|
145
|
-
|
146
|
-
Style/ClassAndModuleChildren:
|
147
|
-
Exclude:
|
148
|
-
- spec/**/*
|
149
|
-
|
150
|
-
Style/BlockDelimiters:
|
151
|
-
Exclude:
|
152
|
-
- spec/**/*
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.3.1
|
data/.travis.yml
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 1.9.3
|
4
|
-
- 2.0.0
|
5
|
-
- 2.1.1
|
6
|
-
services: mongodb
|
7
|
-
before_install:
|
8
|
-
- gem update bundler
|
9
|
-
script:
|
10
|
-
- rake
|
11
|
-
after_script:
|
12
|
-
- CODECLIMATE_REPO_TOKEN=787a2f89b15c637323c7340d65ec17e898ac44480706b4b4122ea040c2a88f1d bundle exec codeclimate-test-reporter
|
data/CHANGELOG.md
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# Change log
|
2
|
-
|
3
|
-
## master (unreleased)
|
4
|
-
|
5
|
-
### New features
|
6
|
-
|
7
|
-
### Bug fixes
|
8
|
-
|
9
|
-
### Changes
|
10
|
-
|
11
|
-
## v1.0.1 (2016-10-31)
|
12
|
-
|
13
|
-
### Bug fixes
|
14
|
-
|
15
|
-
* Updated `updated_at` when enabled from all setter methods. ([@wfleming][])
|
16
|
-
|
17
|
-
## v1.0.0 (2016-10-27)
|
18
|
-
|
19
|
-
No changes! Same as v1.0.0.rc2
|
20
|
-
|
21
|
-
:tada:
|
22
|
-
|
23
|
-
## v1.0.0.rc2 (2016-10-26)
|
24
|
-
|
25
|
-
### New features
|
26
|
-
|
27
|
-
* Allow omitting selectors to finder methods. ([@maxjacobson][])
|
28
|
-
|
29
|
-
### Bug fixes
|
30
|
-
|
31
|
-
* Minidoc#reload will raise Minidoc::DocumentNotFoundError when the document no longer exists, rather than a nil error. ([@maxjacobson][])
|
32
|
-
|
33
|
-
### Changes
|
34
|
-
|
35
|
-
* Make Minidoc.wrap and Minidoc.from_db private. ([@maxjacobson][])
|
36
|
-
|
37
|
-
## v1.0.0.rc1 (2016-09-29)
|
38
|
-
|
39
|
-
### New features
|
40
|
-
|
41
|
-
* [#24](https://github.com/codeclimate/minidoc/pull/24): Add `Minidoc.all`. ([@pbrisbin][])
|
42
|
-
* [#24](https://github.com/codeclimate/minidoc/pull/24): Add `Minidoc.find_one!`. ([@pbrisbin][])
|
43
|
-
* [#28](https://github.com/codeclimate/minidoc/pull/28): Add `Minidoc.find_one_or_initialize`. ([@nporteschaikin][])
|
44
|
-
* [#32](https://github.com/codeclimate/minidoc/pull/32): Infer class names for associations when not provided. ([@wfleming][])
|
45
|
-
|
46
|
-
### Bug fixes
|
47
|
-
|
48
|
-
* [#26](https://github.com/codeclimate/minidoc/pull/26): Improve performance of `Minidoc.exists?`. ([@wfleming][])
|
49
|
-
* [#31](https://github.com/codeclimate/minidoc/pull/31): Fix `save` dropping some attributes. ([@nporteschaikin][])
|
50
|
-
* Improve errors when the user has forgotten to provide database connection information. ([@maxjacobson][])
|
51
|
-
|
52
|
-
### Changes
|
53
|
-
|
54
|
-
* [#23](https://github.com/codeclimate/minidoc/pull/23): Remove `ensure_index`. ([@pbrisbin][])
|
55
|
-
|
56
|
-
## v0.0.1 (2016-09-28)
|
57
|
-
|
58
|
-
Minidoc was originally created by [@brynary][] and has been used in production extensively at Code Climate.
|
59
|
-
This is the first version released to rubygems.
|
60
|
-
|
61
|
-
[@brynary]: https://github.com/brynary
|
62
|
-
[@maxjacobson]: https://github.com/maxjacobson
|
63
|
-
[@nporteschaikin]: https://github.com/nporteschaikin
|
64
|
-
[@pbrisbin]: https://github.com/pbrisbin
|
65
|
-
[@wfleming]: https://github.com/wfleming
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,49 +0,0 @@
|
|
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 hello@codeclimate.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
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2016 Bryan Helmkamp
|
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
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/codeclimate/minidoc.svg)](https://travis-ci.org/codeclimate/minidoc)
|
2
|
-
[![Gem Version](https://badge.fury.io/rb/minidoc.svg)](http://badge.fury.io/rb/minidoc)
|
3
|
-
[![Code Climate](https://codeclimate.com/github/codeclimate/minidoc/badges/gpa.svg)](https://codeclimate.com/github/codeclimate/minidoc)
|
4
|
-
[![Test Coverage](https://codeclimate.com/github/codeclimate/minidoc/badges/coverage.svg)](https://codeclimate.com/github/codeclimate/minidoc/coverage)
|
5
|
-
|
6
|
-
# Minidoc
|
7
|
-
|
8
|
-
Minidoc is an extremely lightweight layer on top of the MongoDB client to
|
9
|
-
make interacting with documents from Ruby more convenient.
|
10
|
-
|
11
|
-
We rely heavily on the MongoDB client, Virtus and ActiveModel to keep
|
12
|
-
things as simple as possible.
|
13
|
-
|
14
|
-
## Features
|
15
|
-
|
16
|
-
* Interact with Ruby objects instead of hashes
|
17
|
-
* Full access to the powerful MongoDB client
|
18
|
-
* Thread safe (hopefully)
|
19
|
-
* Simple and easily extensible
|
20
|
-
* ActiveModel-compatible
|
21
|
-
* Validations
|
22
|
-
* Timestamp tracking (created_at/updated_at)
|
23
|
-
* Very basic associations (for reads)
|
24
|
-
* Conversion into immutable value objects
|
25
|
-
* Read-only records
|
26
|
-
|
27
|
-
## Anti-Features
|
28
|
-
|
29
|
-
* Custom query API (just use Mongo)
|
30
|
-
* Callbacks (just define a method like save and call super)
|
31
|
-
|
32
|
-
## Installation
|
33
|
-
|
34
|
-
Add this line to your application's Gemfile:
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
gem "minidoc"
|
38
|
-
```
|
39
|
-
|
40
|
-
And then execute:
|
41
|
-
|
42
|
-
```
|
43
|
-
$ bundle
|
44
|
-
```
|
45
|
-
|
46
|
-
Or install it yourself as:
|
47
|
-
|
48
|
-
```
|
49
|
-
$ gem install minidoc
|
50
|
-
```
|
51
|
-
|
52
|
-
## Usage
|
53
|
-
|
54
|
-
### Setup
|
55
|
-
|
56
|
-
```ruby
|
57
|
-
Minidoc.connection = Mongo::MongoClient.from_uri("mongodb://localhost")
|
58
|
-
Minidoc.database_name = "my_great_app_development"
|
59
|
-
```
|
60
|
-
|
61
|
-
### Basics
|
62
|
-
|
63
|
-
```ruby
|
64
|
-
class User < Minidoc
|
65
|
-
include Minidoc::Timestamps
|
66
|
-
|
67
|
-
attribute :name, String
|
68
|
-
attribute :language, String
|
69
|
-
timestamps!
|
70
|
-
end
|
71
|
-
|
72
|
-
user = User.create!(name: "Bryan", language: "Cobol")
|
73
|
-
User.count # => 1
|
74
|
-
|
75
|
-
user.language = "Lisp"
|
76
|
-
user.save!
|
77
|
-
|
78
|
-
user.set(language: "Fortran")
|
79
|
-
|
80
|
-
user.destroy
|
81
|
-
User.count # => 0
|
82
|
-
```
|
83
|
-
|
84
|
-
### Validations
|
85
|
-
|
86
|
-
Just uses [`ActiveModel::Validations`](http://api.rubyonrails.org/classes/ActiveModel/Validations.html):
|
87
|
-
|
88
|
-
```ruby
|
89
|
-
class User < Minidoc
|
90
|
-
attribute :name, String
|
91
|
-
|
92
|
-
validates :name, presence: true
|
93
|
-
end
|
94
|
-
|
95
|
-
user = User.new
|
96
|
-
user.valid? # => false
|
97
|
-
user.name = "Bryan"
|
98
|
-
user.valid? # => true
|
99
|
-
```
|
100
|
-
|
101
|
-
### Value Objects
|
102
|
-
|
103
|
-
```ruby
|
104
|
-
bryan = User.create(name: "Bryan").as_value
|
105
|
-
bryan.name #=> "Bryan"
|
106
|
-
bryan.name = "Brian" #=> NoMethodError
|
107
|
-
```
|
108
|
-
|
109
|
-
### Associations
|
110
|
-
|
111
|
-
```ruby
|
112
|
-
class Drink < Minidoc
|
113
|
-
include Minidoc::Associations
|
114
|
-
|
115
|
-
attribute :name, String
|
116
|
-
|
117
|
-
belongs_to :user
|
118
|
-
end
|
119
|
-
|
120
|
-
bryan = User.create(name: "Bryan")
|
121
|
-
drink = Drink.create(name: "Paloma", user: bryan)
|
122
|
-
drink.user == bryan #=> true
|
123
|
-
```
|
124
|
-
|
125
|
-
### Read-only records
|
126
|
-
|
127
|
-
```ruby
|
128
|
-
class DrinkEvents < Minidoc::ReadOnly
|
129
|
-
include Minidoc::Timestamps
|
130
|
-
timestamps!
|
131
|
-
end
|
132
|
-
|
133
|
-
DrinkEvents.count(created_at: { "$gt": 4.days.ago }) #=> 0
|
134
|
-
DrinkEvents.create #=> NoMethodError
|
135
|
-
```
|
136
|
-
|
137
|
-
## Contributing
|
138
|
-
|
139
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/codeclimate/minidoc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
140
|
-
|
141
|
-
When making a pull request, please update the [changelog](CHANGELOG.md).
|
142
|
-
|
143
|
-
## Releasing
|
144
|
-
|
145
|
-
* Update the changelog to mark the unreleased changes as part of the new release.
|
146
|
-
* Update the version.rb with the new version number
|
147
|
-
* Make a pull request with those changes
|
148
|
-
* Merge those changes to master
|
149
|
-
* Check out and pull down the latest master locally
|
150
|
-
* `rake release` which will
|
151
|
-
* tag the latest commit based on version.rb
|
152
|
-
* push to github
|
153
|
-
* push to rubygems
|
154
|
-
* Copy the relevant changelog entries into a new [GitHub release](https://github.com/codeclimate/minidoc/releases).
|
data/Rakefile
DELETED
data/minidoc.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "minidoc/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "minidoc"
|
8
|
-
spec.version = Minidoc::VERSION
|
9
|
-
spec.authors = ["Bryan Helmkamp", "Code Climate"]
|
10
|
-
spec.email = ["bryan@brynary.com", "hello@codeclimate.com"]
|
11
|
-
spec.summary = %q{Lightweight wrapper for MongoDB documents}
|
12
|
-
spec.homepage = "https://github.com/codeclimate/minidoc"
|
13
|
-
spec.license = "MIT"
|
14
|
-
|
15
|
-
spec.files = `git ls-files`.split($/)
|
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 "activesupport", ">= 3.0.0", "< 5"
|
21
|
-
spec.add_dependency "activemodel", ">= 3.0.0", "< 5"
|
22
|
-
spec.add_dependency "virtus", "~> 1.0", ">= 1.0.0"
|
23
|
-
spec.add_dependency "mongo", "~> 1"
|
24
|
-
end
|