8. Rhodes
O que é?
É um framework open-source, permite aos
desenvolvedores criar aplicações nativas para telefones
móveis com a portabilidade de tecnologias web tais como
XHTML, CSS, JavaScript e do poder do Ruby
Instalação:
$ gem install rhodes
$ rhodes-setup
11. Rhodes
index.erb.html
Este é o arquivo de início, desta forma
<nome_aplicacao>/app/. A partir de agora todo o
código é um pouco semelhante a escrever um
RubyOnRails aplicação.
12. Running the Application Rhodes
Executando:
$ cd applicatonTest
$ rake run:iphone
Rodando para outros Devises:
$ rake run:iphone
$ rake run:android
$ rake run:bb
19. RhoSync
O que é?
Um framework de sincronização é uma
estrutura composta por um componente de
cliente no dispositivo e um componente de
servidor que roda em qualquer servidor
que podem executar o Ruby.
20. Instalar dependencias RhoSync
$ sudo gem install rhosync
$ wget http://redis.googlecode.com/files/redis-
2.2.7.tar.gz
$ tar xzf redis-2.2.7.tar.gz
$ cd redis-2.2.7
$ cd src; make
$ make install
$ cp ../redis.conf /usr/local/etc
More: www.redis.io
21. Instalar RhoSync
$ rhosync app applicationTest-server
$ cd applicationTest-server/
If you are running first on the Mac or Linux,
you must install dtach:
$ sudo rake dtach:install
22. Rodando a aplicação RhoSync
$ rake redis:start
$ rake rhosync:start
If all went well you should see:
[12:30:15 PM 2011-07-22] Rhosync Server
v2.1.0 started...
23. Definindo Adapters RhoSync
Ligar a um serviço de back-end com
RhoSync requer que você escreva uma
pequena quantidade de código Ruby para a
consulta, criar, atualizar e excluir as
operações de seu backend empresa
particular.
24. Definindo Adapters RhoSync
$ cd /applicationTest
$ rhosync source pessoa
---
Generating with source generator:
[ADDED] sources/pessoa.rb
[ADDED] spec/sources/pessoa_spec.rb
25. pessoa.rb
class Pessoa < SourceAdapter def sync
def initialize(source) # Manipulate @result before it is saved, or save it
super(source) # yourself using the Rhosync::Store interface.
end # By default, super is called below which simply
saves @result
def login super
# TODO: Login to your data source here if necessary end
end
def create(create_hash,blob=nil)
def query # TODO: Create a new record in your backend data
# TODO: Query your backend data source and assign the source
records # If your rhodes rhom object contains image/binary
# to a nested hash structure called @result. For example: data
# @result = { # (has the image_uri attribute), then a blob will be
# "1"=>{"name"=>"Acme","industry"=>"Electronics"}, provided
# "2"=>{"name"=>"Best", "industry"=>"Software"} raise "Please provide some code to create a single
#} record in the backend data source using the
raise SourceAdapterException.new("Please provide some create_hash"
code to read records from the backend data source") End
end
def update(update_hash)
raise "Please provide some code to update a single
record in the backend data source using the
update_hash"
end
26. pessoa.rb
def delete(object_id)
# TODO: write some code here if applicable
# be sure to have a hash key and value for "object"
# for now, we'll say that its OK to not have a delete operation
# raise "Please provide some code to delete a single object in the backend
#application using the hash values in name_value_list"
end
def logoff
# TODO: Logout from the data source if necessary
end
end
27. settings/settings.yml
The generator will modify this file:
#Sources
:sources:
Pessoa:
:poll_interval: 300
31. Atualizar o adaptador de fonte
$ rake rhosync:restart
O objeto será criado imediatamente no
cliente e enviado para o servidor na
próxima sincronização.
32. Autenticação
O arquivo application.rb, editando o metodo de authenticate:
def authenticate(username, password, session)
# ... connect to backend using API and authenticate ...
if success
# save the data for later use in the source adapter
Store.put_value("username:#{username}:token",username)
end
return success
end