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
- #new_record? ⇒ Boolean
- #save ⇒ Object
- #save! ⇒ Object
Class Method Details
.included(klass) ⇒ Object
125 126 127 |
# File 'lib/catch_notes/base.rb', line 125 def self.included(klass) klass.extend ClassMethods end |
Instance Method Details
#destroy ⇒ Object
172 173 174 175 176 |
# File 'lib/catch_notes/base.rb', line 172 def destroy destroy! rescue false end |
#destroy! ⇒ Object
166 167 168 169 170 |
# File 'lib/catch_notes/base.rb', line 166 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
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/catch_notes/base.rb', line 129 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'] @tags = @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
178 179 180 181 |
# File 'lib/catch_notes/base.rb', line 178 def new_record? i = self.send :id i.nil? end |
#save ⇒ Object
160 161 162 163 164 |
# File 'lib/catch_notes/base.rb', line 160 def save save! rescue false end |
#save! ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/catch_notes/base.rb', line 148 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 |