Additional support of documentation.

Issue #6 resolved
Amrut Jadhav created an issue

I have added some additional support for documentation in gem. I had problem in sending pull request, so I am sending changes in the following code. New regex for matching fields, validations, associations

r = re.search("(?P<indent>^\s*)(?P<field>field)\s*:.*$",line_for_selection)
      if not r == None:
        self.handle_field(edit,r)
      r = re.search("(?P<indent>^\s*)(?P<association>has_many|has_one|belongs_to|has_and_belongs_to_many|embeds_one|embeds_many)\s*:.*$",line_for_selection)
      if not r == None:
        self.handle_association(edit,r)
      r = re.search("(?P<indent>^\s*)(?P<validation>validate|validates_presence_of|validates|validates_absence_of|validates_inclusion_of)\s*:.*$",line_for_selection)
      if not r == None:
        self.handle_validation(edit,r)

Corresponding methods to add documentation

  def handle_field(self,edit,r):
    self.indent = r.group("indent")
    self.lines = []
    self.lines.append("# Fields")
    self.run_command(edit,self.concat())

  def handle_association(self,edit,r):
    self.indent = r.group("indent")
    self.lines = []
    self.lines.append("# Associations")
    self.run_command(edit,self.concat())

  def handle_validation(self,edit,r):
    self.indent = r.group("indent")
    self.lines = []
    self.lines.append("# Validations")
    self.run_command(edit,self.concat())

Test it and merge into main branch. They are small changes but they affects a lot :)

Note: I also attached updated yardgen.py file

Comments (11)

  1. Fred Appelman repo owner

    The regular expression

          r = re.search("(?P<indent>^\s*)(?P<validation>validate|validates_presence_of|validates|validates_absence_of|validates_inclusion_of)\s*:.*$",line_for_selection)
    

    seems to be a bit off. It has validates_presence_of twice. I am not so involved in Rails, but should this just be validate_presence_of instead?

  2. Amrut Jadhav reporter

    No. Rails don't have validation such as

    validate_presence_of
    

    Above mentioned validations supported in the rails.

  3. Fred Appelman repo owner

    So do you agree the regex should become:

    r = re.search("(?P<indent>^\s*)(?P<validation>validates_presence_of|validates|validates_inclusion_of)\s*:.*$",line_for_selection)
    
  4. Log in to comment