Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Commit

Permalink
インスタンス向けカラムマッパはインスタンス参照前だとalias_methodが正常に動作しないので別の方法で実装
Browse files Browse the repository at this point in the history
  • Loading branch information
YOSHIDA Hiroki committed Jul 3, 2014
1 parent 40b525f commit beb4e9e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/comable/columns_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,17 @@ def changed

def define_getter_method(column_name)
target_column_name = mapped_comable_column_name(column_name)
eigenclass.send(:alias_method, column_name, target_column_name)
define_singleton_method(column_name) { send target_column_name }
end

def define_setter_method(column_name)
target_column_name = mapped_comable_column_name(column_name)
eigenclass.send(:alias_method, "#{column_name}=", "#{target_column_name}=")
define_singleton_method("#{column_name}=") { |value| send "#{target_column_name}=", value }
end

def define_predicate_method(column_name)
target_column_name = mapped_comable_column_name(column_name)
eigenclass.send(:alias_method, "#{column_name}?", "#{target_column_name}?")
define_singleton_method("#{column_name}?") { send "#{target_column_name}?" }
end
end

Expand Down Expand Up @@ -243,7 +243,7 @@ def initialize(*args, &block)
current_scope = self.class.scoped
end
comable_values = current_scope.try(:comable_values) || {}
comable!(comable_values[:type]) if self.respond_to?(:comable) && comable_values[:flag]
comable!(comable_values[:type]) if comable_values[:flag]
super
end
end
Expand Down

0 comments on commit beb4e9e

Please sign in to comment.