Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

splitting up the dsl block #76

Closed
imajes opened this issue May 14, 2012 · 4 comments
Closed

splitting up the dsl block #76

imajes opened this issue May 14, 2012 · 4 comments

Comments

@imajes
Copy link
Contributor

imajes commented May 14, 2012

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!

@kulesa
Copy link

kulesa commented May 15, 2012

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"

@imajes
Copy link
Contributor Author

imajes commented May 15, 2012

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

@kulesa
Copy link

kulesa commented May 15, 2012

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

@imajes
Copy link
Contributor Author

imajes commented May 15, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants