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

Defining configuration outside of the ActiveRecord model #101

Closed
tboyko opened this issue Jun 28, 2016 · 3 comments
Closed

Defining configuration outside of the ActiveRecord model #101

tboyko opened this issue Jun 28, 2016 · 3 comments

Comments

@tboyko
Copy link

tboyko commented Jun 28, 2016

Does comma have pre-existing support for defining the comma config outside of the ActiveRecord model? For instance, is there an easy way to create an app/serializers folder for this config? I'd prefer to keep it separate if possible, and want to avoid using an include if there's already a way to do this.

Thanks!

@eitoball
Copy link
Contributor

No. Interesting idea. May I ask why would you do so? 

You could do by monkey patching to_comma method. Maybe like...

module Simple
  def self.included(m)
    m.comma :simple do
      name
      desrciption
    end
  end
end

module DynamicCommaDefinition
  def to_comma(style = :default)
     self.class.include(style.to_s.constantize)
  ensure
    super
  end
end
Object.prepend(DynamicCommaDefinition)

@tboyko
Copy link
Author

tboyko commented Jun 29, 2016

The purpose would be to keep the active record model class lean. It's a
habit I've developed from using gems like Draper:
https://github.com/drapergem/draper

On Tue, Jun 28, 2016 at 6:20 PM, Eito Katagiri notifications@github.com
wrote:

No. Interesting idea. May I ask why would you do so?

You could do by monkey patching to_comma method. Maybe like...

module Simple
def self.included(m)
m.comma :simple do
name
desrciption
end
endend
module DynamicCommaDefinition
def to_comma(style = :default)
self.class.include(style.to_s.constantize)
ensure
super
endendObject.prepend(DynamicCommaDefinition)


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#101 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AA7LZJc7az1f7mqyZu1rBKvh8ikE2V_4ks5qQchpgaJpZM4JAmnb
.

@eitoball
Copy link
Contributor

The purpose would be to keep the active record model class lean.

I see. Thank you.

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

2 participants