Mailinglist Archive: yast-devel (233 mails)

< Previous Next >
Re: [yast-devel] Webyast: ActiveSource
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Tue, 13 Oct 2009 11:40:02 +0200
  • Message-id: <200910131140.02199.jreidinger@xxxxxxx>
Josef Reidinger write:
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?

Klaus currently say in validation task, that there should be existing
solution. I find some and write some comments:

act_without_database -
It is pure hack, which is not nice and quite confusing

ActiveModel :
That's exactly what I need. It is abstraction of ActiveResource and
ActiveRecord functionality. I prefer to use it as base and add our own
functionlity in some Base class (as ActiveModel is only mixins). Where I see
problems is that it is not packaged, test-suite is not in good condition and I
doesn't see much support if something goes wrong (maybe I am wrong, but it is
not "officially" supported).
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 >