Sha256: 97de9bfe1aa7818ed673d1aec6a7918a99d508d3411a9efcdacb31c98d7389d0

Contents?: true

Size: 760 Bytes

Versions: 7

Compression:

Stored size: 760 Bytes

Contents

module EvernoteOAuth
  module StoreAttachable
    def attach_user_store(*field_symbols)
      attach_store('user', *field_symbols)
    end

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

    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"
	      store = eval(store_name)
	      [instance_variable_get(original)].flatten.each{|n|
		n.define_singleton_method(store_name.to_sym){store}
	      }
	    end
	  )
	  instance_variable_set(target, with_stores)
	end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
evernote_oauth-0.1.8 lib/evernote_oauth/store_attachable.rb
evernote_oauth-0.1.7 lib/evernote_oauth/store_attachable.rb
evernote_oauth-0.1.6 lib/evernote_oauth/store_attachable.rb
evernote_oauth-0.1.5 lib/evernote_oauth/store_attachable.rb
evernote_oauth-0.1.4 lib/evernote_oauth/store_attachable.rb
evernote_oauth-0.1.3 lib/evernote_oauth/store_attachable.rb
evernote_oauth-0.1.2 lib/evernote_oauth/store_attachable.rb