Module: EvernoteOAuth::StoreAttachable

Included in:
Evernote::EDAM::NoteStore::NoteList, Evernote::EDAM::NoteStore::SyncChunk
Defined in:
lib/evernote_oauth/store_attachable.rb

Instance Method Summary collapse

Instance Method Details

#attach_note_store(*field_symbols) ⇒ Object



7
8
9
# File 'lib/evernote_oauth/store_attachable.rb', line 7

def attach_note_store(*field_symbols)
  attach_store('note', *field_symbols)
end

#attach_store(type, *field_symbols) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/evernote_oauth/store_attachable.rb', line 11

def attach_store(type, *field_symbols)
  field_symbols.each do |fs|
    define_method(fs) do
      original = "@#{fs}".to_sym
      target = "@#{fs}_with_#{type}_stores".to_sym
      with_stores = (
        instance_variable_get(target) ||
        begin
          store_name = "#{type}_store"
          if respond_to?(store_name.to_sym)
            store = eval(store_name)
            [instance_variable_get(original)].flatten.each{|n|
              n.define_singleton_method(store_name.to_sym){store}
            }
          end
          instance_variable_get(original)
        end
      )
      instance_variable_set(target, with_stores)
    end
  end
end

#attach_user_store(*field_symbols) ⇒ Object



3
4
5
# File 'lib/evernote_oauth/store_attachable.rb', line 3

def attach_user_store(*field_symbols)
  attach_store('user', *field_symbols)
end