softwear-lib 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4747a563a62d0fa81d639b3451f08f16f08504fd
4
- data.tar.gz: 965f5f4c0a52c1f27246774087cf867db3dd1016
3
+ metadata.gz: 18852132ef59f403e4bf39ccbfb9924d26aa7a1b
4
+ data.tar.gz: 25a246735e20b6e342b804955844d0303daca545
5
5
  SHA512:
6
- metadata.gz: ba81d1344a8b00df0410f2f149911a2ecaeb3344a8d1ef596cc535ee7f1ee049f3cbfaa22ceec1988910e408bfc08ae89a2d4861610d071e5647fb28310fd2eb
7
- data.tar.gz: 982eef95324c1a19a775d02c7db7d81426c08f9bcb64fc1d48670fe350ab89cc4fc061e4566f23d04a56f1b1886a402ce80be4dddbf2ae5a798664b3bea37b9e
6
+ metadata.gz: 276834739a66871a69a863e85dcb6529f900d5c58d409ee5bd5b874f7fe13e92d31c4f9f28546906baa02de865c41103f1ea1c50df112a66f5178624e885a331
7
+ data.tar.gz: 80e35e5017f1343c848ca76a650dadbaf890da1116ca890719d802b46806756c8d8938b7248e39e4c72cabef0a8afa93ed5f63f1297c2195dd384167db5c3a82
@@ -1,115 +1,118 @@
1
- module Api
2
- class ApiController < ActionController::Base
3
- include InheritedResources::Actions
4
- include InheritedResources::BaseHelpers
5
- extend InheritedResources::ClassMethods
6
- extend InheritedResources::UrlHelpers
1
+ require 'inherited_resources'
7
2
 
8
- acts_as_token_authentication_handler_for User
9
- skip_before_filter :authenticate_user!
10
- skip_before_filter :verify_authenticity_token
3
+ module Softwear
4
+ module Lib
5
+ class ApiController < ActionController::Base
6
+ include ::InheritedResources::Actions
7
+ include ::InheritedResources::BaseHelpers
8
+ extend ::InheritedResources::ClassMethods
9
+ extend ::InheritedResources::UrlHelpers
11
10
 
12
- before_filter :allow_origin
11
+ skip_before_filter :authenticate_user!
12
+ skip_before_filter :verify_authenticity_token
13
13
 
14
- respond_to :json
15
- self.responder = InheritedResources::Responder
14
+ before_filter :allow_origin
16
15
 
17
- self.class_attribute :resource_class, :instance_writer => false unless self.respond_to? :resource_class
18
- self.class_attribute :parents_symbols, :resources_configuration, :instance_writer => false
16
+ respond_to :json
17
+ self.responder = InheritedResources::Responder
19
18
 
20
- def index(&block)
21
- yield if block_given?
19
+ self.class_attribute :resource_class, :instance_writer => false unless self.respond_to? :resource_class
20
+ self.class_attribute :parents_symbols, :resources_configuration, :instance_writer => false
22
21
 
23
- key_values = permitted_attributes.map do |a|
24
- [a, params[a]] if params.key?(a)
25
- end
26
- .compact
22
+ def index(&block)
23
+ yield if block_given?
27
24
 
28
- self.records ||= resource_class
29
- self.records = records.where(Hash[key_values])
25
+ key_values = permitted_attributes.map do |a|
26
+ [a, params[a]] if params.key?(a)
27
+ end
28
+ .compact
30
29
 
31
- respond_to do |format|
32
- format.json(&render_json(records))
33
- end
34
- end
30
+ self.records ||= resource_class
31
+ self.records = records.where(Hash[key_values])
35
32
 
36
- def show
37
- super do |format|
38
- format.json(&render_json)
33
+ respond_to do |format|
34
+ format.json(&render_json(records))
35
+ end
39
36
  end
40
- end
41
37
 
42
- def update
43
- super do |format|
44
- format.json(&render_json)
38
+ def show
39
+ super do |format|
40
+ format.json(&render_json)
41
+ end
45
42
  end
46
- end
47
43
 
48
- def create
49
- create! do |success, failure|
50
- success.json do
51
- headers['Location'] = resource_url(record.id)
52
- render_json(status: 201).call
44
+ def update
45
+ super do |format|
46
+ format.json(&render_json)
53
47
  end
54
- failure.json(&render_json)
55
48
  end
56
- end
57
49
 
58
- def options
59
- head(:ok) if request.request_method == 'OPTIONS'
60
- end
50
+ def create
51
+ create! do |success, failure|
52
+ success.json do
53
+ headers['Location'] = resource_url(record.id)
54
+ render_json(status: 201).call
55
+ end
56
+ failure.json(&render_json)
57
+ end
58
+ end
61
59
 
62
- protected
60
+ def options
61
+ head(:ok) if request.request_method == 'OPTIONS'
62
+ end
63
63
 
64
- def render_json(options = {})
65
- proc do
66
- if options.is_a?(Hash)
67
- records = nil
68
- else
69
- records = options
70
- options = {}
64
+ protected
65
+
66
+ def render_json(options = {})
67
+ proc do
68
+ if options.is_a?(Hash)
69
+ records = nil
70
+ else
71
+ records = options
72
+ options = {}
73
+ end
74
+ rendering = {
75
+ json: (records || record),
76
+ methods: [:id] + permitted_attributes,
77
+ include: includes
78
+ }
79
+ .merge(options)
80
+
81
+ render rendering
71
82
  end
72
- rendering = {
73
- json: (records || record),
74
- methods: [:id] + permitted_attributes,
75
- include: includes
76
- }
77
- .merge(options)
78
-
79
- render rendering
80
83
  end
81
- end
82
84
 
83
- def self.model_name
84
- name.gsub('Api::', '').gsub('Controller', '').singularize
85
- end
85
+ def self.model_name
86
+ name.gsub('Api::', '').gsub('Controller', '').singularize
87
+ end
86
88
 
87
- # Override this to specify the :include option of rendering json.
88
- def includes
89
- {}
90
- end
89
+ # Override this to specify the :include option of rendering json.
90
+ def includes
91
+ {}
92
+ end
91
93
 
92
- def records
93
- instance_variable_get("@#{self.class.model_name.underscore.pluralize}")
94
- end
94
+ def records
95
+ instance_variable_get("@#{self.class.model_name.underscore.pluralize}")
96
+ end
95
97
 
96
- def records=(r)
97
- instance_variable_set("@#{self.class.model_name.underscore.pluralize}", r)
98
- end
98
+ def records=(r)
99
+ instance_variable_set("@#{self.class.model_name.underscore.pluralize}", r)
100
+ end
99
101
 
100
- def record
101
- instance_variable_get("@#{self.class.model_name.underscore}")
102
- end
102
+ def record
103
+ instance_variable_get("@#{self.class.model_name.underscore}")
104
+ end
103
105
 
104
- def allow_origin
105
- headers['Access-Control-Allow-Origin'] = '*'
106
- headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, PATCH, DELETE'
107
- headers['Access-Control-Allow-Headers'] = 'X-Requested-With'
108
- headers['Access-Control-Allow-Credentials'] = 'true'
109
- end
106
+ def allow_origin
107
+ headers['Access-Control-Allow-Origin'] = '*'
108
+ headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, PATCH, DELETE'
109
+ headers['Access-Control-Allow-Headers'] = 'X-Requested-With'
110
+ headers['Access-Control-Allow-Credentials'] = 'true'
111
+ end
110
112
 
111
- def permitted_attributes
112
- resource_class.column_names
113
+ def permitted_attributes
114
+ resource_class.column_names
115
+ end
113
116
  end
114
117
  end
115
118
  end
@@ -1,5 +1,5 @@
1
1
  module Softwear
2
2
  module Lib
3
- VERSION = "1.3.1"
3
+ VERSION = "1.3.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: softwear-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Baillie