ruby - Extending a model's class methods via a gem -
i'm trying write gem allow me call class methods on rails models. far, have following:
mygem/models/active_record_extension.rb
module activerecordextension extend activesupport::concern module classmethods def foo "foo" end end end # include extension activerecord::base.send(:include, activerecordextension)
i'm requiring file follows:
require "mygem/version" require "mygem/models/active_record_extension" require "mygem/railtie" if defined? rails module mygem # code goes here... end
my gemspec file including necessary files:
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.files = dir["{lib}/**/*.rb"] spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| file.basename(f) } spec.require_paths = ["lib"] spec.add_development_dependency "bundler", "~> 1.9" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "rails", "~> 4.2"
i've tried various variations on reason or cannot seem able call .foo
on given model. getting nameerror: uninitialized constant activerecordextension::activesupport. going incorrectly?
thanks!
Comments
Post a Comment