Skip to content

Instantly share code, notes, and snippets.

#! /bin/sh
if [ $# -eq 0 ]; then
echo "tell me your plugin name"
exit 1
fi
# set your language
LANG="ja"
class ActiveSupport::TestCase
self.fixture_path = File.dirname(__FILE__) + '/fixtures'
end
@pinzolo
pinzolo / get_extended_modules.rb
Last active December 20, 2015 01:49
クラスがモジュールを extend したかどうかを取得する
module Foo
end
class Bar
extend Foo
end
Bar.included_modules.include?(Foo)
Bar.include?(Foo)
# => false
# Adds the app/{controllers,helpers,models} directories of the plugin to the autoload path
Dir.glob File.expand_path(File.join(p.directory, 'app', '{controllers,helpers,models}')) do |dir|
ActiveSupport::Dependencies.autoload_paths += [dir]
end
# Adds the app/{controllers,helpers,models} directories of the plugin to the autoload path
Dir.glob File.expand_path(File.join(p.directory, 'app', '{controllers,helpers,models}')) do |dir|
ActiveSupport::Dependencies.autoload_paths += [dir]
end
@pinzolo
pinzolo / add_plugin_load_path_in_init.rb
Last active December 20, 2015 12:28
Redmine はプラグインの app/{controllers,models,helpers} しか自動的にロードしてくれないので、その他のディレクトリをロードさせる
Redmine::Plugin.register :hoge do
# other plugin settings
# simple
ActiveSupport::Dependencies.autoload_paths += [File.dirname(__FILE__) + "/app/forms"]
# multiple
Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), "app", "{forms,services}"))) do |dir|
ActiveSupport::Dependencies.autoload_paths += [dir]
end
@pinzolo
pinzolo / missing_method_auto_define.rb
Created August 16, 2013 02:12
auto define method in method_missing
# coding: utf-8
module TestModule
def method_missing(name, *args)
puts name
self.class.class_eval do
define_method name do |*params|
self.sub(params)
end
end
self.__send__(name, *args)
@pinzolo
pinzolo / exec_redmine_plugin_test_on_windows7.bat
Created August 21, 2013 02:07
Windows7上でRedmineのプラグインを開発しているときに、sqlite3 のデータファイルに対して permission denied のエラーが出た場合の対処法。 rails_envを空にするのがポイントだろう。
set rails_env=
copy plugins\<plugin_name>\test\fixtures\*.yml test\fixtures
bundle exec rake redmine:plugins:test
label = "foo bar"
data = label.match(/foo (?<name>.+)\z/)
p data[:name]
# => bar
@pinzolo
pinzolo / coprime.rb
Created November 8, 2013 12:11
互いに素かどうか
def coprime?(x, y)
max = x > y ? Math.sqrt(y) : Math.sqrt(x)
2.upto(max) do |n|
return false if x % n == 0 && y % n == 0
end
true
end