Class: VersionControl::Filter

Inherits:
Object
  • Object
show all
Defined in:
app/models/version_control/filter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Filter

Returns a new instance of Filter.



5
6
7
8
9
10
11
# File 'app/models/version_control/filter.rb', line 5

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.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def author
  @author
end

#branchObject

Returns the value of attribute branch.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def branch
  @branch
end

#commits_countObject (readonly)

Returns the value of attribute commits_count.



3
4
5
# File 'app/models/version_control/filter.rb', line 3

def commits_count
  @commits_count
end

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'app/models/version_control/filter.rb', line 3

def errors
  @errors
end

#filter_mergesObject

Returns the value of attribute filter_merges.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def filter_merges
  @filter_merges
end

#first_revisionObject (readonly)

Returns the value of attribute first_revision.



3
4
5
# File 'app/models/version_control/filter.rb', line 3

def first_revision
  @first_revision
end

#fromObject

Returns the value of attribute from.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def from
  @from
end

#idObject

Returns the value of attribute id.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def id
  @id
end

#last_revisionObject (readonly)

Returns the value of attribute last_revision.



3
4
5
# File 'app/models/version_control/filter.rb', line 3

def last_revision
  @last_revision
end

#loggerObject

Returns the value of attribute logger.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def logger
  @logger
end

#messageObject

Returns the value of attribute message.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def message
  @message
end

#pathObject

Returns the value of attribute path.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def path
  @path
end

#previous_revisionObject (readonly)

Returns the value of attribute previous_revision.



3
4
5
# File 'app/models/version_control/filter.rb', line 3

def previous_revision
  @previous_revision
end

#previous_revision_by_fileObject (readonly)

Returns the value of attribute previous_revision_by_file.



3
4
5
# File 'app/models/version_control/filter.rb', line 3

def previous_revision_by_file
  @previous_revision_by_file
end

#project_slugObject

Returns the value of attribute project_slug.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def project_slug
  @project_slug
end

#repositoryObject

Returns the value of attribute repository.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def repository
  @repository
end

#storyObject

Returns the value of attribute story.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def story
  @story
end

#tasksObject

Returns the value of attribute tasks.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def tasks
  @tasks
end

#toObject

Returns the value of attribute to.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def to
  @to
end

#workspaceObject

Returns the value of attribute workspace.



2
3
4
# File 'app/models/version_control/filter.rb', line 2

def workspace
  @workspace
end

Class Method Details

.create(attributes = {}) ⇒ Object



13
14
15
16
17
18
19
# File 'app/models/version_control/filter.rb', line 13

def self.create(attributes = {})
  resource = new(attributes)
  
  resource.files_by_category if resource.valid?
  
  resource
end

Instance Method Details

#files_by_categoryObject



27
28
29
30
31
32
33
34
35
36
37
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
# File 'app/models/version_control/filter.rb', line 27

def files_by_category
  return {} unless valid?
  
  return @files_by_category if @files_by_category
  
  @files_by_category = { 
    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: [] }
  }

  catch(:done) do
    commits do |page|
      page.each do |commit| 
        add_commit_to_files(commit) if commit_attributes_match_criteria?(commit)
      end
    end 
  end
  
  @files_by_category.each {|category, setting| @files_by_category.delete(category) unless setting[:files].try(:any?) }
  
  #get_previous_revision_for_files
  
  @files_by_category
rescue Grit::NoSuchPathError
  @errors ||= {}
  @errors['base'] = 'Repository not found.'
end

#files_countObject



66
# File 'app/models/version_control/filter.rb', line 66

def files_count; @previous_revision_by_file.keys.length; end

#repository_pathObject



21
# File 'app/models/version_control/filter.rb', line 21

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

#usersObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/version_control/filter.rb', line 68

def users
  return @users if @users
  
  @users = []
  
  if files_by_category.is_a? Hash
    files_by_category.each do |category, setting|
      next if setting[:files].blank?
      
      @users += setting[:files].values.flatten.map{|commit| commit[:author]}.uniq
    end
    
    @users.uniq!
  end
  
  @users.none? ? repository_users : @users
end

#valid?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/models/version_control/filter.rb', line 23

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