modest_model 0.0.4 → 0.1.0
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.
- data/README.md +58 -0
- metadata +30 -13
data/README.md
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
# ModestModel
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
Inspired by Crafting Rails Applications by Jose Valim, ModestModel provides an ActiveModel-compliant class that allows you to quickly create simple, table-less models. The intended use is to back interactions with external APIs with Ruby-friendly models rather than raw structured data (such as hashes).
|
6
|
+
|
7
|
+
## Example
|
8
|
+
|
9
|
+
json = MyExternalApi.call('/some/path')
|
10
|
+
attributes_hash = JSON.decode(json)
|
11
|
+
|
12
|
+
# => {'name' => 'Michael', 'email' => 'michael@example.com'}
|
13
|
+
|
14
|
+
class SampleModel < ModestModel::Base
|
15
|
+
attributes :name, :email
|
16
|
+
end
|
17
|
+
|
18
|
+
SampleModel.new(attributes_hash)
|
19
|
+
|
20
|
+
# => #<SampleModel @name="Michael"...
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
ModestModel has been tested and works on MRI 1.8.7 and 1.9.2.
|
25
|
+
|
26
|
+
### Rubygems
|
27
|
+
|
28
|
+
gem install modest_model
|
29
|
+
|
30
|
+
### Bundler
|
31
|
+
|
32
|
+
gem 'modest_model'
|
33
|
+
|
34
|
+
### Usage
|
35
|
+
|
36
|
+
Similar to ActiveRecord models, simply create a class which inherits from `ModestModel::Base`, and define the attributes by calling the `attributes` method:
|
37
|
+
|
38
|
+
class SampleModel < ModestModel::Base
|
39
|
+
attributes :name, :email
|
40
|
+
end
|
41
|
+
|
42
|
+
## Features
|
43
|
+
|
44
|
+
ModestModel includes the following ActiveModel modules:
|
45
|
+
|
46
|
+
* `ActiveModel::Conversion`
|
47
|
+
* `ActiveModel::Naming`
|
48
|
+
* `ActiveModel::Translation`
|
49
|
+
* `ActiveModel::Validations`
|
50
|
+
* `ActiveModel::AttributeMethods`
|
51
|
+
|
52
|
+
These allow your ModestModel models to act almost the same as an ActiveRecord model, but without the database. You can mass-assign attributes, add validations, add translations, and call familiar methods like `model_name.human`.
|
53
|
+
|
54
|
+
Please refer to chapter 2, Building Models with Active Model, from [Crafting Rails Applications](http://pragprog.com/book/jvrails/crafting-rails-applications) for an in-depth explanation of the inner workings of ModestModel.
|
55
|
+
|
56
|
+
## Credits
|
57
|
+
|
58
|
+
This code has been derived from Crafting Rails Applications by Jose Valim, so all credit goes to Jose and [Plataforma](http://blog.plataformatec.com.br/) for granting permission to release this gem.
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modest_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Mike Fulcher
|
@@ -10,41 +15,53 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-08-01 00:00:00 Z
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: activemodel
|
17
|
-
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
18
24
|
none: false
|
19
25
|
requirements:
|
20
26
|
- - ~>
|
21
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 5
|
29
|
+
segments:
|
30
|
+
- 3
|
22
31
|
version: "3"
|
23
32
|
type: :runtime
|
24
|
-
|
25
|
-
version_requirements: *id001
|
33
|
+
requirement: *id001
|
26
34
|
- !ruby/object:Gem::Dependency
|
27
35
|
name: rails
|
28
|
-
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
29
38
|
none: false
|
30
39
|
requirements:
|
31
40
|
- - ~>
|
32
41
|
- !ruby/object:Gem::Version
|
42
|
+
hash: 15424215
|
43
|
+
segments:
|
44
|
+
- 3
|
45
|
+
- 1
|
46
|
+
- rc
|
47
|
+
- 5
|
33
48
|
version: 3.1.rc5
|
34
49
|
type: :development
|
35
|
-
|
36
|
-
version_requirements: *id002
|
50
|
+
requirement: *id002
|
37
51
|
- !ruby/object:Gem::Dependency
|
38
52
|
name: sqlite3
|
39
|
-
|
53
|
+
prerelease: false
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
40
55
|
none: false
|
41
56
|
requirements:
|
42
57
|
- - ">="
|
43
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
44
62
|
version: "0"
|
45
63
|
type: :development
|
46
|
-
|
47
|
-
version_requirements: *id003
|
64
|
+
requirement: *id003
|
48
65
|
description: Simple, tableless ActiveModel-compliant models. Like ActiveRecord models without the database.
|
49
66
|
email:
|
50
67
|
executables: []
|
@@ -106,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
123
|
requirements:
|
107
124
|
- - ">="
|
108
125
|
- !ruby/object:Gem::Version
|
109
|
-
hash:
|
126
|
+
hash: 3
|
110
127
|
segments:
|
111
128
|
- 0
|
112
129
|
version: "0"
|
@@ -115,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
132
|
requirements:
|
116
133
|
- - ">="
|
117
134
|
- !ruby/object:Gem::Version
|
118
|
-
hash:
|
135
|
+
hash: 3
|
119
136
|
segments:
|
120
137
|
- 0
|
121
138
|
version: "0"
|