Sha256: 06503ef046757a0ae8e96cb1cde0fc1ffd400725b1ac3b6b2dfa297c96f990e0
Contents?: true
Size: 1.61 KB
Versions: 5
Compression:
Stored size: 1.61 KB
Contents
class Rtml::Instruction < ActiveRecord::Base extend Rtml::Instruction::FollowClassMethods set_table_name 'rtml_instructions' serialize :arguments#, Array belongs_to :source, :polymorphic => true validates_presence_of :source, :name, :x, :y validates_presence_of :widget #has_many :instructions, :as => :source # referencing this seems to raise Rtml is not missing constant Instruction ?? #So I added a migration and an extra key (parent_id) and source_id and source_type aren't used for children. Whatever. #has_many :instructions, :class_name => 'Rtml::Instruction', :foreign_key => 'parent_id', :dependent => :destroy #belongs_to :parent, :foreign_key => 'parent_id', :class_name => 'Rtml::Instruction' # It's because of the namespace. has_many :instructions, :as => :source, :class_name => 'Rtml::Instruction' delegate :gui_configuration, :to => :widget def to_json(options = {}) super(options.merge(:methods => :widget_fields)) end def after_initialize self.arguments ||= Hash.new end def widget return nil unless source source_name = source.kind_of?(Rtml::Document) ? 'document' : source.name Rtml::Widgets.affecting(source_name).each do |widget| return widget if widget.entry_points.include?(name) end nil end def widget_name widget.name end def widget_fields gui_configuration.fields_with_inferences end def follow(source = self.source) raise ArgumentError, "Source is required" unless source src = source.send("#{name}_from_hash", arguments) instructions.each do |instruction| instruction.follow(src) end end end
Version data entries
5 entries across 5 versions & 1 rubygems