her 0.5.5 → 0.6

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.
Files changed (63) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +1 -1
  3. data/README.md +78 -63
  4. data/UPGRADE.md +21 -0
  5. data/lib/her/model.rb +2 -1
  6. data/lib/her/model/associations.rb +17 -54
  7. data/lib/her/model/associations/association.rb +46 -0
  8. data/lib/her/model/associations/belongs_to_association.rb +34 -0
  9. data/lib/her/model/associations/has_many_association.rb +43 -0
  10. data/lib/her/model/associations/has_one_association.rb +33 -0
  11. data/lib/her/model/attributes.rb +19 -19
  12. data/lib/her/model/base.rb +5 -0
  13. data/lib/her/model/http.rb +17 -21
  14. data/lib/her/model/orm.rb +11 -35
  15. data/lib/her/model/parse.rb +4 -12
  16. data/lib/her/model/paths.rb +3 -2
  17. data/lib/her/model/relation.rb +113 -0
  18. data/lib/her/version.rb +1 -1
  19. data/spec/model/associations_spec.rb +48 -4
  20. data/spec/model/introspection_spec.rb +1 -1
  21. data/spec/model/orm_spec.rb +21 -102
  22. data/spec/model/parse_spec.rb +36 -7
  23. data/spec/model/paths_spec.rb +3 -3
  24. data/spec/model/relation_spec.rb +89 -0
  25. data/spec/spec_helper.rb +1 -0
  26. data/spec/support/macros/her_macros.rb +17 -0
  27. data/spec/support/macros/request_macros.rb +19 -0
  28. metadata +13 -37
  29. data/examples/grape-and-her/.env.default +0 -3
  30. data/examples/grape-and-her/Procfile +0 -2
  31. data/examples/grape-and-her/README.md +0 -27
  32. data/examples/grape-and-her/api/Gemfile +0 -11
  33. data/examples/grape-and-her/api/Rakefile +0 -14
  34. data/examples/grape-and-her/api/app/api.rb +0 -49
  35. data/examples/grape-and-her/api/app/models/organization.rb +0 -7
  36. data/examples/grape-and-her/api/app/models/user.rb +0 -9
  37. data/examples/grape-and-her/api/app/views/organizations/_base.rabl +0 -2
  38. data/examples/grape-and-her/api/app/views/organizations/index.rabl +0 -3
  39. data/examples/grape-and-her/api/app/views/organizations/show.rabl +0 -3
  40. data/examples/grape-and-her/api/app/views/users/_base.rabl +0 -8
  41. data/examples/grape-and-her/api/app/views/users/index.rabl +0 -3
  42. data/examples/grape-and-her/api/app/views/users/show.rabl +0 -3
  43. data/examples/grape-and-her/api/config.ru +0 -5
  44. data/examples/grape-and-her/api/config/boot.rb +0 -17
  45. data/examples/grape-and-her/api/config/unicorn.rb +0 -7
  46. data/examples/grape-and-her/api/db/migrations/001_create_users.rb +0 -11
  47. data/examples/grape-and-her/api/db/migrations/002_create_organizations.rb +0 -8
  48. data/examples/grape-and-her/consumer/Gemfile +0 -23
  49. data/examples/grape-and-her/consumer/app/assets/stylesheets/application.scss +0 -190
  50. data/examples/grape-and-her/consumer/app/assets/stylesheets/reset.scss +0 -53
  51. data/examples/grape-and-her/consumer/app/consumer.rb +0 -74
  52. data/examples/grape-and-her/consumer/app/models/organization.rb +0 -13
  53. data/examples/grape-and-her/consumer/app/models/user.rb +0 -13
  54. data/examples/grape-and-her/consumer/app/views/index.haml +0 -9
  55. data/examples/grape-and-her/consumer/app/views/layout.haml +0 -20
  56. data/examples/grape-and-her/consumer/app/views/organizations/index.haml +0 -25
  57. data/examples/grape-and-her/consumer/app/views/organizations/show.haml +0 -11
  58. data/examples/grape-and-her/consumer/app/views/users/index.haml +0 -33
  59. data/examples/grape-and-her/consumer/app/views/users/show.haml +0 -9
  60. data/examples/grape-and-her/consumer/config.ru +0 -20
  61. data/examples/grape-and-her/consumer/config/boot.rb +0 -30
  62. data/examples/grape-and-her/consumer/config/unicorn.rb +0 -7
  63. data/examples/grape-and-her/consumer/lib/response_logger.rb +0 -18
@@ -1,17 +0,0 @@
1
- # Bundler setup
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
4
- Bundler.require(:default, ENV['RACK_ENV']) if defined? Bundler
5
-
6
- # Configure ActiveRecord
7
- ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: File.expand_path('../../db/development.db', __FILE__)
8
-
9
- # Require models
10
- Dir[File.expand_path('../../app/models/**/*.rb', __FILE__)].each do |file|
11
- dirname = File.dirname(file)
12
- file_basename = File.basename(file, File.extname(file))
13
- require "#{dirname}/#{file_basename}"
14
- end
15
-
16
- # Application setup
17
- require File.expand_path('../../app/api', __FILE__)
@@ -1,7 +0,0 @@
1
- if ENV["RACK_ENV"] == "development"
2
- worker_processes 1
3
- else
4
- worker_processes 4
5
- end
6
-
7
- timeout 30
@@ -1,11 +0,0 @@
1
- class CreateUsers < ActiveRecord::Migration
2
- def change
3
- create_table :users do |t|
4
- t.string :email
5
- t.string :fullname
6
- t.integer :organization_id, null: false
7
-
8
- t.timestamps
9
- end
10
- end
11
- end
@@ -1,8 +0,0 @@
1
- class CreateOrganizations < ActiveRecord::Migration
2
- def change
3
- create_table :organizations do |t|
4
- t.string :name
5
- t.timestamps
6
- end
7
- end
8
- end
@@ -1,23 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Server
4
- gem 'unicorn'
5
-
6
- # Web
7
- gem 'sinatra'
8
- gem 'sinatra-reloader'
9
- gem 'haml'
10
- gem 'her'
11
- gem 'multi_json'
12
-
13
- # Assets
14
- gem 'sass'
15
- gem 'sprockets'
16
- gem 'sprockets-sass'
17
- gem 'sprockets-helpers'
18
-
19
- group :development do
20
- gem 'pry'
21
- gem 'rake'
22
- gem 'foreman'
23
- end
@@ -1,190 +0,0 @@
1
- @import "reset.css";
2
-
3
- * {
4
- -webkit-box-sizing: border-box;
5
- -moz-box-sizing: border-box;
6
- box-sizing: border-box;
7
- }
8
-
9
- html {
10
- font-size: 62.5%;
11
- }
12
-
13
- body {
14
- background: #eee;
15
- color: #000;
16
- padding: 30px;
17
- font-family: 'Helvetica Neue', Helvetica, sans-serif;
18
- font-size: 150%;
19
- }
20
-
21
- input, textarea, select, option, button {
22
- font-family: 'Helvetica Neue', Helvetica, sans-serif;
23
- font-size: 100%;
24
- }
25
-
26
- hr {
27
- display: none;
28
- }
29
-
30
- a {
31
- color: #1b49ff;
32
- }
33
-
34
- #wrap {
35
- background: #fff;
36
- box-shadow: 0 0 20px rgba(0,0,0,0.3);
37
- border: 1px solid #bbb;
38
- border-radius: 4px;
39
- overflow:hidden;
40
- }
41
-
42
- #main-header {
43
- font-size: 130%;
44
- background: #ddd;
45
-
46
- strong {
47
- font-family: Pacifico, serif;
48
- font-size: 250%;
49
- font-weight: normal;
50
- display: inline-block;
51
- vertical-align: middle;
52
- }
53
-
54
- span {
55
- display: inline-block;
56
- vertical-align: middle;
57
- color: rgba(0,0,0,0.4);
58
- font-weight: normal;
59
- margin: 0 0 0 20px;
60
- font-size: 80%;
61
- }
62
-
63
- a {
64
- display: block;
65
- padding: 30px 20px;
66
- color: #000;
67
- text-decoration: none;
68
-
69
- &:hover {
70
- background: rgba(0,0,0,0.05);
71
- }
72
- }
73
- }
74
-
75
- #main-footer {
76
- pre {
77
- padding: 20px;
78
- color: rgba(0,0,0,0.75);
79
- line-height: 1.4;
80
- font-size: 80%;
81
- }
82
- }
83
-
84
- #content {
85
- padding: 30px;
86
-
87
- h1 {
88
- margin: 25px 0 15px;
89
- font-size: 150%;
90
- &:first-child { margin-top: 0; }
91
- }
92
-
93
- h2 {
94
- margin: 25px 0 15px;
95
- font-size: 120%;
96
- &:first-child { margin-top: 0; }
97
- }
98
-
99
- h3 {
100
- margin: 25px 0 15px;
101
- font-size: 110%;
102
- &:first-child { margin-top: 0; }
103
- }
104
-
105
- pre {
106
- background: #f9ffeb;
107
- border: 1px solid rgba(0,0,0,0.15);
108
- padding: 15px;
109
- }
110
-
111
- form {
112
- margin: 0 0 15px;
113
- padding: 0 0 15px;
114
- border-bottom: 1px solid #ddd;
115
-
116
- p {
117
- margin: 0 0 15px;
118
- }
119
-
120
- label {
121
- display: block;
122
- margin: 0 0 6px;
123
- cursor: pointer;
124
- }
125
-
126
- input[type=text], input[type=email] {
127
- padding: 10px;
128
- width: 100%;
129
- border: 1px solid #ccc;
130
- border-radius: 2px;
131
- }
132
-
133
- button {
134
- cursor: pointer;
135
- background: #1b49ff;
136
- color: #fff;
137
- padding: 8px 11px;
138
- border-radius: 3px;
139
- border: 1px solid rgba(0,0,0,0.3);
140
- }
141
-
142
- .errors {
143
- padding: 15px;
144
- background: #fcc;
145
- border: 1px solid rgba(0,0,0,0.2);
146
- margin: 0 0 20px;
147
- font-size: 90%;
148
- color: #900;
149
-
150
- li {
151
- margin: 0 0 5px 20px;
152
- list-style: disc;
153
- &:last-child { margin-bottom: 0; }
154
- }
155
- }
156
- }
157
-
158
- .records {
159
- li {
160
- list-style: disc;
161
- margin: 0 0 10px 20px;
162
-
163
- &:last-child { margin-bottom: 0; }
164
- }
165
- }
166
-
167
- .no-records {
168
- color: rgba(0,0,0,0.8);
169
- font-style: italic;
170
- font-size: 80%;
171
- }
172
-
173
- .details {
174
- margin: 0 0 20px;
175
-
176
- li {
177
- list-style: disc;
178
- margin: 0 0 6px 20px;
179
-
180
- &:last-child { margin-bottom: 0; }
181
- }
182
- }
183
-
184
- .back {
185
- border-top: 1px solid #ddd;
186
- padding: 15px 0 0;
187
- margin: 30px 0 0;
188
- font-size: 85%;
189
- }
190
- }
@@ -1,53 +0,0 @@
1
- /* http://meyerweb.com/eric/tools/css/reset/ */
2
- /* v1.0 | 20080212 */
3
-
4
- html, body, div, span, applet, object, iframe,
5
- h1, h2, h3, h4, h5, h6, p, blockquote, pre,
6
- a, abbr, acronym, address, big, cite, code,
7
- del, dfn, em, font, img, ins, kbd, q, s, samp,
8
- small, strike, strong, sub, sup, tt, var,
9
- b, u, i, center,
10
- dl, dt, dd, ol, ul, li,
11
- fieldset, form, label, legend,
12
- table, caption, tbody, tfoot, thead, tr, th, td {
13
- margin: 0;
14
- padding: 0;
15
- border: 0;
16
- outline: 0;
17
- font-size: 100%;
18
- vertical-align: baseline;
19
- background: transparent;
20
- }
21
- body {
22
- line-height: 1;
23
- }
24
- ol, ul {
25
- list-style: none;
26
- }
27
- blockquote, q {
28
- quotes: none;
29
- }
30
- blockquote:before, blockquote:after,
31
- q:before, q:after {
32
- content: '';
33
- content: none;
34
- }
35
-
36
- /* remember to define focus styles! */
37
- :focus {
38
- outline: 0;
39
- }
40
-
41
- /* remember to highlight inserts somehow! */
42
- ins {
43
- text-decoration: none;
44
- }
45
- del {
46
- text-decoration: line-through;
47
- }
48
-
49
- /* tables still need 'cellspacing="0"' in the markup */
50
- table {
51
- border-collapse: collapse;
52
- border-spacing: 0;
53
- }
@@ -1,74 +0,0 @@
1
- class Consumer < Sinatra::Base
2
- configure do
3
- set :root, -> { File.expand_path("./") }
4
- set :views, -> { File.join(root, "app/views") }
5
- set :haml, :format => :html5, :attr_wrapper => '"', :ugly => true
6
- end
7
-
8
- configure :development do
9
- register Sinatra::Reloader
10
- end
11
-
12
- helpers Sprockets::Helpers
13
-
14
- before do
15
- $strio.truncate(0)
16
- end
17
-
18
- # GET /
19
- get '/' do
20
- haml :index
21
- end
22
-
23
- # GET /users
24
- get '/users' do
25
- @users = User.all
26
- @user = User.new
27
-
28
- haml :'users/index'
29
- end
30
-
31
- # GET /users/:id
32
- get '/users/:id' do
33
- @user = User.find(params[:id])
34
- haml :'users/show'
35
- end
36
-
37
- # GET /post
38
- post '/users' do
39
- @users = User.all
40
- @user = User.new(params[:user])
41
-
42
- if @user.save
43
- redirect to('/users')
44
- else
45
- haml :'users/index'
46
- end
47
- end
48
-
49
- # GET /organizations
50
- get '/organizations' do
51
- @organizations = Organization.all
52
- @organization = Organization.new
53
-
54
- haml :'organizations/index'
55
- end
56
-
57
- # GET /organizations/:id
58
- get '/organizations/:id' do
59
- @organization = Organization.find(params[:id])
60
- haml :'organizations/show'
61
- end
62
-
63
- # GET /post
64
- post '/organizations' do
65
- @organizations = Organization.all
66
- @organization = Organization.new(params[:organization])
67
-
68
- if @organization.save
69
- redirect to('/organizations')
70
- else
71
- haml :'organizations/index'
72
- end
73
- end
74
- end
@@ -1,13 +0,0 @@
1
- class Organization
2
- include Her::Model
3
-
4
- # Attributes
5
- attributes :name
6
-
7
- # Associations
8
- has_many :users
9
-
10
- # Parsing options
11
- parse_root_in_json true
12
- include_root_in_json true
13
- end
@@ -1,13 +0,0 @@
1
- class User
2
- include Her::Model
3
-
4
- # Attributes
5
- attributes :email, :fullname, :organization_id
6
-
7
- # Associations
8
- belongs_to :organization
9
-
10
- # Parsing options
11
- parse_root_in_json true
12
- include_root_in_json true
13
- end
@@ -1,9 +0,0 @@
1
- %h2
2
- %a{ href: '/organizations' } Organizations
3
- %pre= File.read(File.join(settings.root, "app/models/organization.rb"))
4
-
5
- %hr
6
-
7
- %h2
8
- %a{ href: '/users' } Users
9
- %pre= File.read(File.join(settings.root, "app/models/user.rb"))
@@ -1,20 +0,0 @@
1
- !!! 5
2
- %head
3
- %title Grape + Her example
4
- %link{ rel: "stylesheet", type: "text/css", href: "http://fonts.googleapis.com/css?family=Pacifico" }
5
- %link{ type: "text/css", rel: "stylesheet", media: 'screen', href: stylesheet_path("application") }
6
- %body
7
- #wrap
8
- %header#main-header
9
- %h1
10
- %a{ href: '/' }
11
- %strong
12
- Her
13
- %span
14
- Grape + Her example
15
- %hr
16
- #content
17
- = yield
18
- %footer#main-footer
19
- %pre
20
- = $strio.string