Module: CatchNotes::Base::CRUDMethods
- Included in:
- CatchNotes::Base
- Defined in:
- lib/catch_notes/base.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
- #destroy! ⇒ Object
- #initialize(attributes) ⇒ Object
- #save ⇒ Object
- #save! ⇒ Object
Class Method Details
.included(klass) ⇒ Object
87 88 89 |
# File 'lib/catch_notes/base.rb', line 87 def self.included(klass) klass.extend ClassMethods end |
Instance Method Details
#destroy ⇒ Object
134 135 136 137 138 |
# File 'lib/catch_notes/base.rb', line 134 def destroy destroy! rescue false end |
#destroy! ⇒ Object
128 129 130 131 132 |
# File 'lib/catch_notes/base.rb', line 128 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
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/catch_notes/base.rb', line 91 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 |
#save ⇒ Object
122 123 124 125 126 |
# File 'lib/catch_notes/base.rb', line 122 def save save! rescue false end |
#save! ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/catch_notes/base.rb', line 110 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 |