Can't read Build.yml file

Hi,

I want to read the build.yml in my controller file. When i am doing require 'yaml' in my controller file it's giving an error stating no such file to load.

Can anyone help me out in how to read build.yml file in my controller file.

Thanks in advance

Mohit Raheja

Andraž Stošić
I've read documentation http:

I've read documentation http://docs.rhomobile.com/rhodes/extensions and it seems that rhodes ruby implementation doesn't include "yaml" module like standard ruby.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mohit Raheja
I have read the document and

I have read the document and also tried the same thing but still the problem persists.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Pietro Francesc...
Hi Mojit,the build.yml it's

Hi Mojit,

the build.yml it's the "build time configuration" for a Rhodes/RhoElements application, so it's not available into the deployed native application setup package.

the Runtime configuration file is RhoConfig.txt and this file is in the setup package and it's options are available using the RhoConfig API:

http://docs.rhomobile.com/rhodesapi/rhoconfig-api

What are you trying to achieve reading the build.yml file?

BTW, if Yaml gem is not available, you can use XML or (preferred) JSON files to have an additional setup, like shown in the RhoElements tutorial to read a products.txt file:

http://docs.rhomobile.com/rhoelements/rhoelements-tutorial#preloading-the-product-catalog

Best regards

Pietro

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


DecisionPoint K...
I believe you will have to

I believe you will have to load the YAML extension in build.yml before require "yaml" works.

That said, it sounds like you want to be able to read build.yml as a configuration file. This won't be possible once you've built for a device, as build.yml's settings are used for compilation only. If you want a configuration file, I would suggest you use rhoconfig.txt, which works extremely well for reading/writing from within your application. You can access any key like this:

Rho::RhoConfig.myapp_server_url

And set it in the rhoconfig.txt like so:

myapp_server_url = 'http://production.myapp.com/'

You can also change variables at runtime:

Rho::RhoConfig.myapp_user_theme = "purple"

I would not suggest changing RhoMobile-supplied options this way, though, as I don't know when it reloads these things. I also would suggest prefixing any variable name with a short name of your app, to avoid any conflicts with RhoMobile options today or in the future.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mohit Raheja
Actually I want to load the

Actually I want to load the yml file because it returns a hash. I will be able to access it as a object.

It seems i have to do this with the help of Rhoconfig file.

Thanks for your support

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


DecisionPoint K...
My suggestion for this, then,

My suggestion for this, then, would be to use ::JSON.generate to write it to a rhoconfig.txt attribute and then Rho::JSON.parse to read it from a rhoconfig.txt attribute.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Andraž Stošić
Hi,my advice is to move code

Hi,

my advice is to move code that loads YAML file in application.rb under initialize method since this will be loaded on application start up and will be available trough all application life-cycle. Start by adding this line of code on the top of "application.rb" under require ''rho/rhoapplication'

require 'yaml'

than under "initialize" method require settings file and assign it's content to global variable

APP_CONFIG = YAML.load_file("path/to/config/build.yml")

if all goes well you will be able to assess build.yml parameters like this:

APP_CONFIG['parameter_name']

p.s. If you'll add custom parameters to build.yaml I recomend using seperate file for example config.yaml.


Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mohit Raheja
Hi Andraz,I have tried what u

Hi Andraz,

I have tried what u have suggested, but when i am adding the lines in initialize method my application is not starting up. Its showing only the splash screen.

Don't have an idea what's going on behind?

Thanks

Mohit Raheja

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Andraž Stošić
Can you copy the log file?

Can you copy the log file?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mohit Raheja
I have attached my log file.

I have attached my log file. I think the issue is with requiring the yaml file.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Andraž Stošić
Can you please copy

Can you please copy application.rb  code also.

Thanks.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mohit Raheja
Hi Andraz,Along with this,

Hi Andraz,

Along with this, can you please tell me whether do we have to do some other stuff also to require the yaml file?

require 'rho/rhoapplication'

require 'yaml'

class AppApplication < Rho::RhoApplication

  def initialize

    # Tab items are loaded left->right, @tabs[0] is leftmost tab in the tab-bar

    # Super must be called *after* settings @tabs!

    @tabs = nil

    #To remove default toolbar uncomment next line:

    #@@toolbar = nil

    super

    file = File.join(Rho::RhoApplication::get_base_app_path,"/build.yml")

    $val = YAML.load_file(file)

    # Uncomment to set sync notification callback to /app/Settings/sync_notify.

    # SyncEngine::set_objectnotify_url("/app/Settings/sync_notify")

    SyncEngine.set_notification(-1, "/app/Settings/sync_notify", '')

  end

end

Thanks

Mohit Raheja

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Andraž Stošić
Instead of $val = YAML.load

Instead of $val = YAML.load(file) use syntax i've posted APP_CONFIG = YAML.load_file(file).

p.s. Maybe this is problem with rhomobile and 'yaml' libary but the syntax i've posted works on other ruby apps with no problem.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mohit Raheja
Yeah Andraz i have checked it

Yeah Andraz i have checked it on ruby its working fine, but in Rho its giving issues.

I think the problem is with requiring the yaml file in rhodes framework.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Andraž Stošić
It seems so. Well someone

It seems so. Well someone from Motorola should check this issue.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mohit Raheja
Yeah Andraz and thanks for

Yeah Andraz and thanks for your help.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Andraž Stošić
You are welcome. I'll try to

You are welcome. I'll try to play around on my development PC to see if I can find solution.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments