Class: CommitFilter::Model

Inherits:
Object
  • Object
show all
Defined in:
app/models/commit_filter/model.rb

Constant Summary collapse

HASHTAG_REGEX =
/(?:\s|^)(#(?!([0-9]?:\d+|\w+?_|_\w+?)(?:\s|$))([a-z0-9\-_]+))/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Model

Returns a new instance of Model.



24
25
26
27
28
29
30
# File 'app/models/commit_filter/model.rb', line 24

def initialize(attributes = {})
  @commits_count, @previous_revision_by_file = 0, {}
  
  initialize_attributes(attributes)
  
  self
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



4
5
6
# File 'app/models/commit_filter/model.rb', line 4

def author
  @author
end

#branchObject

Returns the value of attribute branch.



4
5
6
# File 'app/models/commit_filter/model.rb', line 4

def branch
  @branch
end

#commits_countObject (readonly)

Returns the value of attribute commits_count.



7
8
9
# File 'app/models/commit_filter/model.rb', line 7

def commits_count
  @commits_count
end

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'app/models/commit_filter/model.rb', line 7

def errors
  @errors
end

#first_revisionObject (readonly)

Returns the value of attribute first_revision.



7
8
9
# File 'app/models/commit_filter/model.rb', line 7

def first_revision
  @first_revision
end

#fromObject

Returns the value of attribute from.



4
5
6
# File 'app/models/commit_filter/model.rb', line 4

def from
  @from
end

#group_by_rails_file_categoryObject

Returns the value of attribute group_by_rails_file_category.



6
7
8
# File 'app/models/commit_filter/model.rb', line 6

def group_by_rails_file_category
  @group_by_rails_file_category
end

#hashtagObject

Returns the value of attribute hashtag.



4
5
6
# File 'app/models/commit_filter/model.rb', line 4

def hashtag
  @hashtag
end

#hide_merge_commitsObject

Returns the value of attribute hide_merge_commits.



5
6
7
# File 'app/models/commit_filter/model.rb', line 5

def hide_merge_commits
  @hide_merge_commits
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'app/models/commit_filter/model.rb', line 4

def id
  @id
end

#issue_urlObject

Returns the value of attribute issue_url.



5
6
7
# File 'app/models/commit_filter/model.rb', line 5

def issue_url
  @issue_url
end

#last_revisionObject (readonly)

Returns the value of attribute last_revision.



7
8
9
# File 'app/models/commit_filter/model.rb', line 7

def last_revision
  @last_revision
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'app/models/commit_filter/model.rb', line 5

def logger
  @logger
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'app/models/commit_filter/model.rb', line 5

def message
  @message
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'app/models/commit_filter/model.rb', line 4

def path
  @path
end

#previous_revisionObject (readonly)

Returns the value of attribute previous_revision.



7
8
9
# File 'app/models/commit_filter/model.rb', line 7

def previous_revision
  @previous_revision
end

#previous_revision_by_fileObject (readonly)

Returns the value of attribute previous_revision_by_file.



7
8
9
# File 'app/models/commit_filter/model.rb', line 7

def previous_revision_by_file
  @previous_revision_by_file
end

#project_slugObject

Returns the value of attribute project_slug.



4
5
6
# File 'app/models/commit_filter/model.rb', line 4

def project_slug
  @project_slug
end

#repositoryObject

Returns the value of attribute repository.



4
5
6
# File 'app/models/commit_filter/model.rb', line 4

def repository
  @repository
end

#repository_hostObject

Returns the value of attribute repository_host.



6
7
8
# File 'app/models/commit_filter/model.rb', line 6

def repository_host
  @repository_host
end

#repository_providerObject

Returns the value of attribute repository_provider.



5
6
7
# File 'app/models/commit_filter/model.rb', line 5

def repository_provider
  @repository_provider
end

#storyObject

Returns the value of attribute story.



5
6
7
# File 'app/models/commit_filter/model.rb', line 5

def story
  @story
end

#tasksObject

Returns the value of attribute tasks.



5
6
7
# File 'app/models/commit_filter/model.rb', line 5

def tasks
  @tasks
end

#toObject

Returns the value of attribute to.



4
5
6
# File 'app/models/commit_filter/model.rb', line 4

def to
  @to
end

#user_or_organizationObject

Returns the value of attribute user_or_organization.



5
6
7
# File 'app/models/commit_filter/model.rb', line 5

def user_or_organization
  @user_or_organization
end

#workspaceObject

Returns the value of attribute workspace.



4
5
6
# File 'app/models/commit_filter/model.rb', line 4

def workspace
  @workspace
end

Class Method Details

.create(attributes = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/commit_filter/model.rb', line 9

def self.create(attributes = {})
  resource = new(attributes)
  
  if resource.valid?
    begin
      resource.commits_by_file
    rescue Grit::Git::GitTimeout
      @errors ||= {}
      @errors['base'] = I18n.t('commit_filter.filters.create.errors.too_many_git_timeouts')
    end
  end
  
  resource
end

Instance Method Details

#commits_by_fileObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/commit_filter/model.rb', line 38

def commits_by_file
  return {} unless valid?
  
  return @files if @files
  
  if group_by_rails_file_category
    @files = { 
      library: { paths: [/^lib\//, /^app\/mailers\//] }, 
      model: { paths: [/^app\/models\//, /^db\//] }, 
      controller: { paths: [/^app\/controllers\//] }, 
      javascript: { paths: [/^app\/assets\/javascripts\//] },
      view: { 
        paths: [
          /^app\/assets\/stylesheets\//, /^app\/views\//, /^app\/helpers\//, /^app\/presenters\//,
          /^public\//
        ] 
      },
      tests: { paths: [/^spec\//, /^features\//] },
      configuration: { paths: [/^config\//] },
      misc: { paths: [] }
    }
  else
    @files = {}
  end
  
  catch(:done) do
    commits do |page|
      page.each do |commit| 
        add_commit_to_files(commit) if commit_attributes_match_criteria?(commit)
      end
    end 
  end
  
  if group_by_rails_file_category
    @files.each {|category, setting| @files.delete(category) unless setting[:files].try(:any?) }
  end
  
  @files
rescue Grit::NoSuchPathError
  @errors ||= {}
  @errors['base'] = I18n.t('commit_filter.filters.create.errors.repository_not_found')
end

#files_countObject



81
# File 'app/models/commit_filter/model.rb', line 81

def files_count; @previous_revision_by_file.keys.length; end

#repository_pathObject



32
# File 'app/models/commit_filter/model.rb', line 32

def repository_path; self.workspace.to_s + '/' + self.repository.to_s; end

#valid?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/commit_filter/model.rb', line 34

def valid?
  @valid = _valid? ? true : false
end