Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 293083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:14:21+00:00 2026-05-12T06:14:21+00:00

I’m writing my first rails plugin and could use a little help. In a

  • 0

I’m writing my first rails plugin and could use a little help. In a very simplified way, I’d like to do allow the developer to specify a value which I can count through a rake task. I’m thinking of something like this…

class User < ActiveRecord::Base
    monitor "Users", count
    monitor "Active Users", count("activated_at != NULL")
end
  1. I guess monitor needs to be a class method of ActiveRecord::Base but how/where do I specify it in my plugin?
  2. The argument to the monitor function shouldn’t be the value but a block of code to execute. I’m not quite sure of the best way to specify this and keep the syntax simple. Perhaps it’ll have to be monitor "Active Users", {count "activated_at != NULL"}?
  3. I’d prefer if the developer didn’t have to specify User.count, just count, i.e. it would pick up the Class automatically (and the blocks will be called on the class not the instance). If this isn’t possible, I guess there’s no reason to put the monitor statements into the model (see #5).
  4. The actual counting of these values (i.e., execution of the blocks) will be done by a rake task offline. What should the monitor function do to make these blocks available to the rake task? Store them in a class variable?
  5. Perhaps the monitor statements don’t need to be specified in the model at all. Maybe it clutters it up so I’d welcome any alternative places to put them.

I’m just sketching out my ideas at the moment and trying to figure out what is/isn’t possible in Ruby. Any help appreciated.

Update: I’ll try to be clearer on the plugin’s purpose. I want the developer to be able to define metrics which should be monitored by the rake task. The rake task will iterate over those metrics and write the values to a file (I’ve simplified this a bit). The rake task will be very simple, something like rake monitors:update (i.e., no params required)

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:14:21+00:00Added an answer on May 12, 2026 at 6:14 am

    Thanks for all your help, however I went with a different approach (extracted below).

    Instead of specifying the attributes in the models, I used an approach seen in the whenever gem. I placed a ruby file “dashboard.rb” in my config directory:

    dashboard "Users", User.count
    dashboard "Activated Users", User.count('activated_at')
    

    My lib consists of two functions:

      def self.dashboard(name, attribute)
          puts "** dailydashboard: #{name} = #{attribute.to_s}"
      end
    
      def self.update(file)
        eval File.read(file)
      end
    

    Basically, my rake task calls update, which loads dashboard.rb and evaluates it and repeatedly calls the dashboard function, which outputs this:

    ** dailydashboard: Users = 2
    ** dailydashboard: Activated Users = 1
    

    Sorry for going around the houses a little bit. For background/offline things this seems like a very simple approach and does what I need. Thanks for your help though!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.