<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <div class="moz-forward-container">That looks nice. As everything in
      Rails with basic CRUD. I've tried some real-world example though,
      here are my notes:<br>
      <div class="moz-cite-prefix"> <br>
        I tried to use ActiveResource to bind candlepin consumer model<br>
        <br>
        I had to fix the monkey patch for replacing the (.json) suffixes
        first, then<br>
        <br>
        consumer = Candlepin::Consumer.first<br>
        consumer.releaseVer # good, returns
        Candlepin::Consumer::ReleaseVer (note we haven't defined this
        class nowhere), I can access the releaseVer value, although it's
        not really Ruby convention to use camelCase for method names<br>
        consumer.releaseVer.releaseVer # => ""<br>
        consumer.releaseVer.releaseVer = "6Server"<br>
        consumer.save # 404, after some googling found out I have to use
        set_primary_key method (not documented btw. but we're used to
        it)<br>
        conusmer.save # second time, "getting NoMethodError: undefined
        method `strip' for nil:NilClass"<br>
        #fixed in newer version of ActiveResource, in 3.0.10 monkey
        patch needed<br>
        <br>
        consumer.save # 500 from candlepin:
        "org.codehaus.jackson.map.exc.UnrecognizedPropertyException"<br>
        # why? because candlepin expects releaseVer to be a string (not
        a Hash)<br>
        # so I tried this<br>
        consumer.releaseVer="6Server"<br>
        consumer.save # => true<br>
        # we updated now<br>
        <br>
        consumer.reload<br>
        consumer.name = "test2"<br>
        consumer.save # getting the same error with releaseVer issue<br>
        # nothing but a hack can fix this<br>
        # also if you wanted to see the request params in the logging,
        you would need to monkey patch<br>
        # while searching for a solution, I've also learned that support
        for singleton resources were introduced quite late [1]<br>
        <br>
        Personally, it was very frustrating morning. And I don't want to
        go through this exercise on daily basis. I'm somehow still
        missing the pros of this solution. One of the criticism of the
        previous one was that we list the attributes in the client code.
        But it turns out it doesn't work without it in activeresource
        for us neither. But with the previous solution the list of
        params was at least in sync with the documentation.<br>
        <br>
        I haven't found any resource that would say that ActiveResource
        deals with caching. Calling Candlepin::Consumer.find(uuid) twice
        in a row calls into Candlepin twice.<br>
        <br>
        On the other hand, it seems that almost any customization in
        ActiveResource needs a monkey patch = really fragile.<br>
        <br>
        And for the last year I can not think of any issue connected
        directly to the code in `lib/resources/` (a.k.a explicit
        bindings) that would not happened with ActiveResource. It would
        be really nice if writing unit tests was easier, but I don't see
        how ActiveResource would help us with this.<br>
        <br>
        Another issue I  have with ActiveResource are all this implicit
        things that make the code harder to maintain and understand
        (explaining the meta-programming is always the hardest part in
        our Ruby course at Uni). Imaging you're a user of the client
        library and see something like this:<br>
        <br>
        class Foreman::User < Resources::Foreman::Base<br>
        end<br>
        <br>
        And let's assume you have no deep understanding of the Rails
        philosophy, let's say Katello or Foreman user (typical sysdamin)
        that wants to script something or fix a bug and send the patch
        back. It's not obvious that you can call. <br>
        <br>
        users = Foreman::User.all<br>
        user = Foreman::User.find(id)<br>
        user.name = "New Name"<br>
        user.save<br>
        user.find(another_id)<br>
        user.destroy<br>
        <br>
        So the next thing to do is to write documentation to the client
        library.<br>
        <br>
        [1] - <a moz-do-not-send="true" class="moz-txt-link-freetext"
          href="https://github.com/rails/activeresource/pull/4">https://github.com/rails/activeresource/pull/4</a><br>
        <br>
        -- Ivan<br>
        <br>
        On 09/17/2012 08:04 PM, Dmitri Dolguikh wrote:<br>
      </div>
      <blockquote cite="mid:5057662A.5010800@redhat.com" type="cite">
        <meta http-equiv="Context-Type" content="text/html;
          charset=ISO-8859-1">
        Hey everybody,<br>
        <br>
        I finished the spike on using ActiveResource as a replacement
        for RestClient, only for communication with Foreman, and only to
        orchestrate user creation/deletion in Foreman. See the results
        at [1].<br>
        <br>
        Some post-spike thoughts/observations:<br>
         - I monkey-patched ActiveResource to support OAuth, but the
        same can be achieved by subclassing ActiveResource::Base, which
        is the way to go.<br>
         - The amount of custom-code is *very* minimal and it's mostly
        to support OAuth.<br>
         - Not a fan of custom to_json, we could either use resource's
        schema (there are some drawbacks), or try using rabl [2] (like
        foreman folks do)<br>
         - Should we decide to adopt this, we can eventually move both
        candlepin and pulp to use ActiveResource. I think it will be
        possible to drop our lazy_attributes in the process with some
        work, if we adopt rails caching.<br>
        <br>
        <br>
        Comments, concerns?<br>
        -d<br>
        <br>
        <br>
        [1] <a moz-do-not-send="true"
          href="https://github.com/witlessbird/katello/tree/foreman-ar-spike">https://github.com/witlessbird/katello/tree/foreman-ar-spike</a><br>
        [2] <a moz-do-not-send="true"
          href="https://github.com/nesquena/rabl">https://github.com/nesquena/rabl</a>
        <br>
        <fieldset class="mimeAttachmentHeader"></fieldset>
        <br>
        <pre wrap="">_______________________________________________
katello-devel mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:katello-devel@redhat.com">katello-devel@redhat.com</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://www.redhat.com/mailman/listinfo/katello-devel">https://www.redhat.com/mailman/listinfo/katello-devel</a></pre>
      </blockquote>
      <br>
      <br>
      <pre class="moz-signature" cols="72">-- 
Ivan</pre>
      <br>
      <br>
    </div>
    <br>
  </body>
</html>