gemhome / fnordmetric

(possible new home for) FnordMetric is a redis/ruby-based realtime Event-Tracking app
0 stars 1 forks source link

splitting up the dsl block #18

Open bf4 opened 10 years ago

bf4 commented 10 years ago

Issue by imajes Monday May 14, 2012 at 19:19 GMT Originally opened as https://github.com/paulasmuth/fnordmetric/issues/76


i love the way you have Fnordmetric.namespace :x do .. end - but is there a way to split this up to different ruby files?

it'd be cool to just include app/metrics/*.rb or something, and that would allow me to break it up by 'tab' in the app. Right now my metrics files run to 100s - 1000s of lines, and this makes debugging and such a bit nastier than it has to.

thanks!

bf4 commented 10 years ago

Comment by kulesa Tuesday May 15, 2012 at 13:27 GMT


I split DSL code between files like this:

# somewhere in initializer
def define_namespace(namespace)
  FnordMetric.namespace namespace do
    instance_eval(File.read(Rails.root.join("app/metrics", "#{namespace}.rb")))
  end
end

define_namespace(:user)
define_namespace(:performance)

Then just put content of namespace blocks in files in app/metrics:

# app/metrics/user.rb
gauge :sign_ups, :tick => 1.day.to_i, :title => "Sign ups"
bf4 commented 10 years ago

Comment by imajes Tuesday May 15, 2012 at 15:04 GMT


That worked? I did something similar but it had only the effect of overwriting the namespace with the last file it found. :(

bf4 commented 10 years ago

Comment by kulesa Tuesday May 15, 2012 at 15:19 GMT


Yes, it works, I have configured have two namespaces like this.

bf4 commented 10 years ago

Comment by imajes Tuesday May 15, 2012 at 16:26 GMT


Ah I see it. i don't, however, want to split the namespace. maybe i will for the future i guess.