openstax_utilities 1.3.0 → 2.0.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjA4NWY1YWY4YjIyMDBkYjAxODE0MDU4YjlmODE0ZTJjNjE5ZjkyMA==
4
+ YWZhYmU2NTY1MjJiZDNiNTE1YTFiZDI1YTk0YzcwYmY3ODAzZmEzMg==
5
5
  data.tar.gz: !binary |-
6
- OWQyYzJkYzYxZjczNTcwYTY2MzYxMmM3NzU0NzQ1ZjU4MWQ0YWQwOA==
6
+ YWRhMTg0MmIyMmM3NGMzYzk4OWRlNWNmYTQ3NjA5MGYxMzdmMDNiZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjQ3YWU0MzlhMmQzZjg1OWQwMDhiZTk0MzJmYmU3MDkxN2EzMmZmNjFiMTBl
10
- ODA2ZGFjMDMzNjQ0NTRkYTM0NzZmMjIxNDkzNWNmNzIxMTFlMTQ0ZGRmZWE2
11
- MDY3NTQ2ZjAzZGUwNzU0NTk0MDAwNGJmMjI4YTAwNjdkN2YxODE=
9
+ ZmEyNjIwM2YxMDI5YjkxNDc4MWUyM2NlZDhmZGVjZDYyNzZmMGQ5ZTJlMGI1
10
+ OTVjMjAxZDYxMTg0Yjg4ODljMDk4MWUxODIxMWYxOTMwZWY0NDI3MWRlNmUw
11
+ NzM5MjJmMmFkNDE1NmM0ZGY2MTdmMjljMGFhYzljZjdiN2I0YTA=
12
12
  data.tar.gz: !binary |-
13
- YTVkNDM3MGE5MGI2Y2M2YmU1NTVhMGE4MTU1MmFkNjQ1ZDRmN2Q5OGYwMTFh
14
- ZmU1NjA0OTg4YzdiMmMwMGMwMTVkNDkwNWM0MGE3ZjMwMjJhZDJkZjdkMzEy
15
- NjFjYjhjMjQ2YTNmNGQ1NDQxNGI0MDgzNDdiYjIyMGIyN2U0OTA=
13
+ Mjc1YjE5MTYwMjZiM2RkMzQ3MGY3MmMxOGQ3ZjI3NGU0MGU3MDI3MjFmYTBi
14
+ YzhmY2YzMDU3OWU5NWZmNDkxZGM5OTg4MTI4NDVjYmQxMGE5NTA1Y2EzNWNk
15
+ NWNjNzE1ZGU1MjRiMTY2OWRkMWVkMzk2MGViNDc3ZWI1ZDk5NTQ=
@@ -19,13 +19,13 @@ module OpenStax
19
19
  end
20
20
  end
21
21
 
22
- def rest_get(model_klass, id, represent_with=nil)
22
+ def standard_read(model_klass, id, represent_with=nil)
23
23
  @model = model_klass.find(id)
24
24
  raise SecurityTransgression unless current_user.can_read?(@model)
25
25
  respond_with @model, represent_with: get_representer(represent_with, @model)
26
26
  end
27
27
 
28
- def rest_update(model_klass, id, represent_with=nil)
28
+ def standard_update(model_klass, id, represent_with=nil)
29
29
  @model = model_klass.find(id)
30
30
  raise SecurityTransgression unless current_user.can_update?(@model)
31
31
  consume!(@model, represent_with: get_representer(represent_with, @model))
@@ -37,9 +37,18 @@ module OpenStax
37
37
  end
38
38
  end
39
39
 
40
- def rest_create(model_klass)
40
+ def standard_create(model_klass, represent_with=nil)
41
+ standard_nested_create(model_klass, nil, nil, represent_with)
42
+ end
43
+
44
+ def standard_nested_create(model_klass, container_association=nil, container_id=nil, represent_with=nil)
41
45
  @model = model_klass.new()
42
46
 
47
+ if container_association && container_id
48
+ foreign_key = model_klass.reflect_on_association(container_association).association_foreign_key
49
+ @model.send(foreign_key + '=', container_id)
50
+ end
51
+
43
52
  # Unlike the implications of the representable README, "consume!" can
44
53
  # actually make changes to the database. See http://goo.gl/WVLBqA.
45
54
  # We do want to consume before checking the permissions so we can know
@@ -47,18 +56,18 @@ module OpenStax
47
56
  # want to have changed the DB. Wrap in a transaction to protect ourselves.
48
57
 
49
58
  model_klass.transaction do
50
- consume!(@model)
59
+ consume!(@model, represent_with: get_representer(represent_with, @model))
51
60
  raise SecurityTransgression unless current_user.can_create?(@model)
52
61
  end
53
62
 
54
63
  if @model.save
55
- respond_with @model
64
+ respond_with @model, represent_with: get_representer(represent_with, @model), status: :created
56
65
  else
57
66
  render json: @model.errors, status: :unprocessable_entity
58
67
  end
59
68
  end
60
69
 
61
- def rest_destroy(model_klass, id)
70
+ def standard_destroy(model_klass, id)
62
71
  @model = model_klass.find(id)
63
72
  raise SecurityTransgression unless current_user.can_destroy?(@model)
64
73
 
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Utilities
3
- VERSION = "1.3.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_utilities
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-01 00:00:00.000000000 Z
11
+ date: 2014-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails