dry - Regarding concerns in Rails 4 (multiple engines) -
update!
i have sorted out issue concerns, although appreciate classmethods suggestion, seems improve code quality.
the issue concern (and dumb mistake) removed concern , combined 1 , concern did not exist. concerns hence appear working, still wondering if there way abstract helpers out not duplicated. right have lot of lines of duplicated helper methods i'd remove if possible.
original questioni have rails application building scratch. since scope of going large, splitting functionality separate engines create lot more maintainable in long term.
that said, haven't worked in pattern before , couple things tripping me up.
the biggest issue coming across this:
there helpers , concerns have defined maintain code dry possible, cannot share these concerns in production environment (which halfway expected).
i not duplicate these concerns in various engines, instead define them in 1 place.
for example, model directory in main app (which contains stuff engines end using) contains next files (as example):
app \ models \ concerns \ mongoidable.rb # contains mongoid include statements , basic set versionable.rb # contains versioning code searchable.rb # contains basic searching code set elasticsearch in basic way etc...
an illustration of concern is:
module mongoidable extend activesupport::concern module classmethods def column_names fields.collect { |field| field[0] } end end included # mongoid documents timestamped , versioned default. # # there isn't much reason why not to. include mongoid::document include mongoid::timestamps include mongoid::userstamp include mongoid::audit::trackable track_history track_create: true, track_delete: true, track_update: true end end when seek include them in models in engines, doesn't work, , have feeling design, wondering if there right way this.
should abstracted gem?
if so, ideas on getting gem set up?
thank much assistance, want maintain code pretty dry since code base of operations going expand.
ruby-on-rails-4 dry rails-engines rails-models
No comments:
Post a Comment