Module: SurveyGizmo::Resource
- Extended by:
- ActiveSupport::Concern
- Included in:
- API::Option, API::Page, API::Question, API::Response, API::Survey
- Defined in:
- lib/survey_gizmo/resource.rb
Defined Under Namespace
Modules: ClassMethods Classes: Response
Class Method Summary collapse
-
.descendants ⇒ Set
Every class that includes SurveyGizmo::Resource.
Instance Method Summary collapse
-
#destroy ⇒ Boolean
Deleted the Resource from Survey Gizmo.
-
#errors ⇒ Array
Any errors returned by Survey Gizmo.
-
#new? ⇒ Boolean
private
The state of the current Resource.
-
#reload ⇒ self, false
fetch resource from SurveyGizmo and reload the attributes.
-
#save ⇒ Boolean
Save the instance to Survey Gizmo.
-
#to_param_options ⇒ Hash
Sets the hash that will be used to interpolate values in routes.
-
#update(attributes = {}) ⇒ Boolean
Updates attributes and saves this Resource instance.
Class Method Details
.descendants ⇒ Set
Returns Every class that includes SurveyGizmo::Resource.
15 16 17 |
# File 'lib/survey_gizmo/resource.rb', line 15 def self.descendants @descendants ||= Set.new end |
Instance Method Details
#destroy ⇒ Boolean
Deleted the Resource from Survey Gizmo
162 163 164 165 166 167 |
# File 'lib/survey_gizmo/resource.rb', line 162 def destroy return false if new? || destroyed? handle_response SurveyGizmo.delete(handle_route(:delete)) do _response.ok? ? destroyed! : false end end |
#errors ⇒ Array
Any errors returned by Survey Gizmo
204 205 206 |
# File 'lib/survey_gizmo/resource.rb', line 204 def errors @errors ||= [] end |
#new? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The state of the current Resource
171 172 173 |
# File 'lib/survey_gizmo/resource.rb', line 171 def new? @_state.nil? end |
#reload ⇒ self, false
fetch resource from SurveyGizmo and reload the attributes
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/survey_gizmo/resource.rb', line 149 def reload handle_response SurveyGizmo.get(handle_route(:get)) do if _response.ok? self.attributes = _response.data clean! else false end end end |
#save ⇒ Boolean
Save the instance to Survey Gizmo
136 137 138 139 140 141 142 143 144 |
# File 'lib/survey_gizmo/resource.rb', line 136 def save if new? _create else handle_response SurveyGizmo.post(handle_route(:update), :query => self.attributes_without_blanks) do _response.ok? ? saved! : false end end end |
#to_param_options ⇒ Hash
Sets the hash that will be used to interpolate values in routes. It needs to be defined per model.
198 199 200 |
# File 'lib/survey_gizmo/resource.rb', line 198 def raise "Define #to_param_options in #{self.class.name}" end |
#update(attributes = {}) ⇒ Boolean
Updates attributes and saves this Resource instance
127 128 129 130 |
# File 'lib/survey_gizmo/resource.rb', line 127 def update(attributes = {}) self.attributes = attributes self.save end |