ruby on rails - How do I use the parser gem to extract this code snippet I want? -
i stumbled across this parser gem.
what want extract specific method long file.
one example has_many
method rails:
def has_many(name, scope = nil, options = {}, &extension) reflection = builder::hasmany.build(self, name, scope, options, &extension) reflection.add_reflection self, name, reflection end
the issue is, need able extract version of same method (from earlier time), more verbose , complex. version looks this:
def has_many(association_id, options = {}) validate_options([ :foreign_key, :class_name, :exclusively_dependent, :dependent, :conditions, :order, :finder_sql ], options.keys) association_name, association_class_name, association_class_primary_key_name = associate_identification(association_id, options[:class_name], options[:foreign_key]) require_association_class(association_class_name) if options[:dependent] , options[:exclusively_dependent] raise argumenterror, ':dependent , :exclusively_dependent mutually exclusive options. may specify 1 or other.' # ' ruby-mode elsif options[:dependent] module_eval "before_destroy '#{association_name}.each { |o| o.destroy }'" elsif options[:exclusively_dependent] module_eval "before_destroy { |record| #{association_class_name}.delete_all(%(#{association_class_primary_key_name} = '\#{record.id}')) }" end define_method(association_name) |*params| force_reload = params.first unless params.empty? association = instance_variable_get("@#{association_name}") if association.nil? association = hasmanyassociation.new(self, association_name, association_class_name, association_class_primary_key_name, options) instance_variable_set("@#{association_name}", association) end association.reload if force_reload association end # deprecated api deprecated_collection_count_method(association_name) deprecated_add_association_relation(association_name) deprecated_remove_association_relation(association_name) deprecated_has_collection_method(association_name) deprecated_find_in_collection_method(association_name) deprecated_find_all_in_collection_method(association_name) deprecated_create_method(association_name) deprecated_build_method(association_name) end
so how extract both of methods, using gem?
the readme gem not friendly complete parsing-noobs.
Comments
Post a Comment