Module: CatchNotes::CRUDMethods
- Included in:
- Base
- Defined in:
- lib/catch_notes/module/crud_methods.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(klass) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #destroy ⇒ Object
- #destroy! ⇒ Object
- #initialize(attributes) ⇒ Object
- #new_record? ⇒ Boolean
- #save ⇒ Object
- #save! ⇒ Object
Class Method Details
.included(klass) ⇒ Object
:nodoc:
11 12 13 |
# File 'lib/catch_notes/module/crud_methods.rb', line 11 def self.included(klass) #:nodoc: klass.extend ClassMethods end |
Instance Method Details
#destroy ⇒ Object
58 59 60 61 62 |
# File 'lib/catch_notes/module/crud_methods.rb', line 58 def destroy destroy! rescue false end |
#destroy! ⇒ Object
52 53 54 55 56 |
# File 'lib/catch_notes/module/crud_methods.rb', line 52 def destroy! raise CatchNotes::NotFound if new_record? # can't delete an unsaved note res = self.class.send(:delete, "/notes/#{self.id}") self.class.send(:ok?, res) end |
#initialize(attributes) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/catch_notes/module/crud_methods.rb', line 15 def initialize(attributes) @attr = self.class.send :stringify_keys, attributes @id = @attr['id'] @created_at = @attr['created_at'] @modified_at = @attr['modified_at'] @source = @attr['source'] @source_url = @attr['source_url'] @children = @attr['children'] @text = @attr['text'] @summary = @attr['summary'] = @attr['tags'] @reminder_at = @attr['reminder_at'] @location = @attr['location'] unless @attr['user'].nil? @user_name = @attr['user']['user_name'] @user_id = @attr['user']['id'] end end |
#new_record? ⇒ Boolean
64 65 66 67 |
# File 'lib/catch_notes/module/crud_methods.rb', line 64 def new_record? i = self.send :id i.nil? end |
#save ⇒ Object
46 47 48 49 50 |
# File 'lib/catch_notes/module/crud_methods.rb', line 46 def save save! rescue false end |
#save! ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/catch_notes/module/crud_methods.rb', line 34 def save! res = if new_record? self.class.send(:post, "/notes", :body => post_body) else self.class.send(:post, "/notes/#{self.id}", :body => post_body) end if self.class.send(:ok?, res) rebuild res.parsed_response['notes'].first end true end |