mongosteen 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +120 -8
- data/lib/mongosteen/version.rb +1 -1
- data/mongosteen.gemspec +6 -6
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a013b059d3c8a07bd717e0854201d996170ca260
|
4
|
+
data.tar.gz: 1bd552aa8dc317812f20cafb1030dbd479a991ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 553239594c50ef0bb14ec4f519a68f6a1be3b2eb1815f8f395772068c06922cfaeb10820fa5f7b2673d0aac341c803d1769008fd00d0c5c65ef956aa72092f3d
|
7
|
+
data.tar.gz: fe7381bc817c95a95402970a53f85d3e82b293cd7ed4fd435b026e9625b959549b4f2bc6bc5376767efd015ac671dd5cae83830ff15b421b455490965d719618
|
data/README.md
CHANGED
@@ -4,18 +4,130 @@
|
|
4
4
|
|
5
5
|
## An easy way to add restful actions
|
6
6
|
|
7
|
-
Mongosteen is a library that helps to easily add restful actions to mongoid models
|
7
|
+
Mongosteen is a library that helps to easily add restful actions to mongoid models and adds support of search, pagination, scopes, json config and history.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
Mongosteen is based on [inherited_resources](https://github.com/josevalim/inherited_resources) gem, get yourself familiar on how it works and setup using it's documentation.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
1. Add Mongosteen to your Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'mongosteen'
|
17
|
+
```
|
18
|
+
|
19
|
+
2. Create controller for the model (e.g. ```Post```):
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
class PostsController < ApplicationController
|
23
|
+
mongosteen
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
3. Connect new controller in ```routes.rb```:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
resources :posts
|
31
|
+
```
|
32
|
+
|
33
|
+
## Mongosteen API
|
34
|
+
|
35
|
+
#### Index
|
36
|
+
|
37
|
+
Index supports **search**, **page**, **perPage** and **scope** parameters:
|
38
|
+
|
39
|
+
```
|
40
|
+
/posts.json?search=Mongosteen&perPage=10&page=2&scope=gems
|
41
|
+
```
|
42
|
+
Check out external gems documentation to see what options they provide:
|
43
|
+
|
44
|
+
- **[mongoid_search](https://github.com/mauriciozaffari/mongoid_search)** — search for mongoid models;
|
45
|
+
- **[kaminari](https://github.com/amatsuda/kaminari)** — generic Rails pagination solution;
|
46
|
+
- **[has_scope](https://github.com/plataformatec/has_scope)** — easy way to access mongoid model scopes via controller;
|
47
|
+
|
48
|
+
#### Versions
|
49
|
+
|
50
|
+
Get specific resource **version**:
|
51
|
+
|
52
|
+
```
|
53
|
+
/posts/54f4216f4f6c65e414000000.json?version=2
|
54
|
+
```
|
55
|
+
|
56
|
+
No how to add history support for mongoid model, check out:
|
57
|
+
|
58
|
+
- **[mongoid-history](https://github.com/aq1018/mongoid-history)** — track changes to mongoid document;
|
59
|
+
|
60
|
+
#### JSON config for model
|
61
|
+
|
62
|
+
Some times there is a need to configure json output for the model, for example to add model method to output or to exclude some internal fields. Mongosteen provides an easy and isolated way to do that in models controller using ```json_config``` method:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
class PostsController < ApplicationController
|
66
|
+
mongosteen
|
67
|
+
json_config({ methods: [ :published_at ] })
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
```json_config``` accepts configuration hash and passes it to [as_json](http://apidock.com/rails/ActiveResource/Base/as_json) method when render output.
|
72
|
+
|
73
|
+
#### Sorted Relations
|
74
|
+
|
75
|
+
In Mongoid, the HABTM relations return docs in the wrong order. This workaround gives your document the ability to retrieve it's relations in the same order it was placed in. This is refactored version of an original [mongoid-sorted-relations](https://github.com/demarque/mongoid-sorted-relations) gem.
|
76
|
+
|
77
|
+
For more details about this issue, see [#1548](https://github.com/mongoid/mongoid/issues/1548).
|
78
|
+
|
79
|
+
Usage example:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
class Post
|
83
|
+
include Mongoid::Document
|
84
|
+
include Mongoid::SortedRelations
|
85
|
+
|
86
|
+
has_and_belongs_to_many :authors
|
87
|
+
end
|
88
|
+
|
89
|
+
post = Book.new title: 'Restful actions with Mongosteen'
|
90
|
+
post.authors << Author.create name: "Alexander Kravets"
|
91
|
+
post.authors << Author.create name: "Roman Brazhnyk"
|
92
|
+
post.authors << Author.create name: "Maxim Melnyk"
|
93
|
+
|
94
|
+
post.sorted_authors.map(&:name)
|
95
|
+
#=> ['Alexander Kravets', 'Roman Brazhnyk', 'Maxim Melnyk']
|
96
|
+
```
|
97
|
+
|
98
|
+
Check out orignal gem [documentation](https://github.com/demarque/mongoid-sorted-relations) for more usage examples.
|
99
|
+
|
100
|
+
#### Permitted Parameters
|
101
|
+
|
102
|
+
For easiness of prototyping, Mongosteen has a workaround that allows all input parameters for ```create``` and ```update``` methods. This default behaviour can be overriden by using ```permitted_params``` method inside of models controller, e.g.:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
class Admin::PostsController < Admin::BaseController
|
106
|
+
mongosteen
|
107
|
+
|
108
|
+
protected
|
109
|
+
|
110
|
+
def permitted_params
|
111
|
+
params.permit(:post => [:title, :body])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
```
|
115
|
+
|
116
|
+
#### Serializable Model Id
|
117
|
+
|
118
|
+
By default mongoid model serializes document id into hash, to override that add ```Mongoid::SerializedId``` to model class:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
class Post
|
122
|
+
include Mongoid::Document
|
123
|
+
include Mongoid::SortedRelations
|
124
|
+
include Mongoid::SerializedId
|
125
|
+
end
|
126
|
+
```
|
14
127
|
|
15
128
|
## The Mongosteen family
|
16
129
|
|
17
|
-
- [Character](https://github.com/slate-studio/chr): A simple and lightweight library for building data management web apps
|
18
|
-
- [Character Admin](https://github.com/slate-studio/chr-admin): Flexible javascript admin solution for Rails applications
|
130
|
+
- [Character](https://github.com/slate-studio/chr): A simple and lightweight javascript library for building data management web apps
|
19
131
|
|
20
132
|
## Credits
|
21
133
|
|
data/lib/mongosteen/version.rb
CHANGED
data/mongosteen.gemspec
CHANGED
@@ -22,12 +22,12 @@ json config.
|
|
22
22
|
s.files = `git ls-files`.split("\n")
|
23
23
|
s.require_paths = ['lib']
|
24
24
|
|
25
|
-
s.add_dependency('mongoid', '
|
26
|
-
s.add_dependency('inherited_resources', '
|
27
|
-
s.add_dependency('kaminari', '
|
28
|
-
s.add_dependency('mongoid_search', '
|
29
|
-
s.add_dependency('has_scope', '
|
30
|
-
s.add_dependency('mongoid-history', '
|
25
|
+
s.add_dependency('mongoid', '>= 4.0') # orm
|
26
|
+
s.add_dependency('inherited_resources', '>= 1.6') # base actions
|
27
|
+
s.add_dependency('kaminari', '>= 0.16') # pagination
|
28
|
+
s.add_dependency('mongoid_search', '>= 0.3') # search
|
29
|
+
s.add_dependency('has_scope', '> 0.5') # scopes
|
30
|
+
s.add_dependency('mongoid-history', '>= 0.4') # history
|
31
31
|
end
|
32
32
|
|
33
33
|
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongosteen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kravets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: inherited_resources
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.6'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: kaminari
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0.16'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.16'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mongoid_search
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0.3'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: has_scope
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.5'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.5'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: mongoid-history
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0.4'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.4'
|
97
97
|
description: |
|