Mailinglist Archive: yast-devel (233 mails)

< Previous Next >
[yast-devel] Webyast: ActiveSource
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Tue, 13 Oct 2009 09:40:28 +0200
  • Message-id: <200910130940.29086.jreidinger@xxxxxxx>
I look on Friday on validations for our rest-service. I little play with code
and it is not so easy to correctly define validation which is called in model
context. I spend some time to google solution and there is
ActiveSupport::Callbacks, whichhas required functionality.
For correctly usage of Callbacks it is needed to call it on certain place in
model code. I also find that ActiveResource and ActiveRecord contain
interesting shortcuts and helpers, so I get idea that I should create general
ActiveSource, for such models. This ActiveSource provide all things which is
common for ActiveRecord and ActiveRecord such as save, find, create, load and
filters like after_save, before_validation and others. What developer need to
use this support is only provide method store (called from save, handle
storing to source - in our case DBus), load (read from source - also DBUS) and
optional initialize which should initialize by some defaults. It should also
contain some automatic to_xml and to_json (at least to_json in our code is not
DRY and to_xml should be also generated automatic).
So if developer use ActiveSource code looks like this.

class NtpSync < ActiveSource::Core
validates_inclusion_of :sync, [true,false]
before_filter :save { yapi_perm_check "ntp.synchronize" }

def load
@sync = false

def store
if @sync
raise unless YastService.Call

return true #if false, then save also return false

and usage in controller:
NtpController < ApplicationController

before_filter :login_required

def show
ntp = Ntp.find

respond_to do |format|
format.html { render :xml => ntp.actions.to_xml(:root =>
#return xml only
format.xml { render :xml => ntp.actions.to_xml(:root =>
format.json { render :json => ntp.actions.to_json }


def update
root = params["ntp"]
if root == nil || root == {}
raise :ntp => "Missing"

Ntp.create root

def create

What do you think about the idea? Any comments, suggestions? Should I start
with it?

Josef Reidinger
YaST team
maintainer of perl-Bootloader, YaST2-Repair, webyast modules language and
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups