lib/my_feeds/identify.rb in my_feeds-0.0.1 vs lib/my_feeds/identify.rb in my_feeds-0.1.0
- old
+ new
@@ -2,35 +2,42 @@
module Identify
extend ActiveSupport::Concern
included do
before_save :save_feed_identify
- class_attribute :feed_polymorphic_name
- self.feed_polymorphic_name = self == Feed ? :source : default_feed_polymorphic_name
- delegate :default_feed_polymorphic_name, :polymorphic_identify_column, :polymorphic_id_column, :polymorphic_type_column, to: :"self.class"
+ self.feed_polymorphic = self == Feed ? :source : default_feed_polymorphic
+ delegate :default_feed_polymorphic, :polymorphic_identify_column, :polymorphic_id_column, :polymorphic_type_column, to: :"self.class"
end
- protected
- def save_feed_identify
- instance_eval %Q{self.#{polymorphic_identify_column} = "#\{#{polymorphic_id_column}.to_s\}@#\{#{polymorphic_type_column}.to_s.underscore\}"}
- end
-
- private
module ClassMethods
- def default_feed_polymorphic_name
+ def feed_polymorphic
+ @_feed_polymorphic
+ end
+
+ def feed_polymorphic= polymorphic
+ @_feed_polymorphic = polymorphic
+ class_eval %Q{
+ def save_feed_identify
+ self.#{polymorphic_identify_column} = "#\{#{polymorphic_id_column}.to_s\}@#\{#{polymorphic_type_column}.to_s.underscore\}"
+ end
+ protected :save_feed_identify
+ }
+ end
+
+ def default_feed_polymorphic
self.to_s.underscore
end
def polymorphic_identify_column
- :"#{feed_polymorphic_name}_identify"
+ :"#{feed_polymorphic}_identify"
end
def polymorphic_id_column
- :"#{feed_polymorphic_name}_id"
+ :"#{feed_polymorphic}_id"
end
def polymorphic_type_column
- :"#{feed_polymorphic_name}_type"
+ :"#{feed_polymorphic}_type"
end
end
end
end