I can access to module pluggins_list method through e.g. @page.plugins.pluggins_list, but if I'm trying to get Plugginable methods or variables in Plugin model by e.g. @page.page_elements.first.get_pluggin I got nil or undefined. How to make module pluggins accessable outside and also that they can be available in each Plugin instance?
Edit, better example:
[3] pry(#<Plugin>)> plg = Plugin.new(name: "nutella")
=> #<Plugin id: nil, element_type: "Plugin", name: "nutella", page_id: nil>
[4] pry(#<Plugin>)> plg.get_pluggin
[5] pry(#<Plugin>)> plg.pluggins
=> nil
[6] pry(#<Plugin>)> pluggin_by_name(name)
NoMethodError: undefined method `find' for nil:NilClass
Current code:
module Plugginable
extend ActiveSupport::Concern
attr_accessor :pluggins
included do
@pluggins = [{name: "dupa"},{name: "hello"}]
end
module ClassMethods
def pluggins_list
@pluggins
end
end
def pluggin_by_name(name)
@pluggins.find {|plg| plg.name === name.downcase }
end
module InstanceMethods
end
end
class Plugin < PageElement
include Plugginable
def get_pluggin
binding.pry
# pluggin_by_name(name)
end
end
Aucun commentaire:
Enregistrer un commentaire