Class: Logaling::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/logaling/project.rb

Direct Known Subclasses

FileBasedProject

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relative_path, repository = nil) ⇒ Project

Returns a new instance of Project.



47
48
49
50
# File 'lib/logaling/project.rb', line 47

def initialize(relative_path, repository=nil)
  @path = relative_path
  @repository = repository
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



45
46
47
# File 'lib/logaling/project.rb', line 45

def path
  @path
end

#repositoryObject (readonly)

Returns the value of attribute repository.



45
46
47
# File 'lib/logaling/project.rb', line 45

def repository
  @repository
end

Class Method Details

.find_dotfile(base_dir = Dir.pwd) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/logaling/project.rb', line 19

def find_dotfile(base_dir=Dir.pwd)
  searched_path = []
  dir = base_dir
  loop do
    path = File.join(dir, '.logaling')
    if File.exist?(path)
      return path
    else
      unless Pathname.new(dir).root?
        searched_path << dir
        dir = File.dirname(dir)
      else
        raise Logaling::ProjectNotFound, "Can't found .logaling in #{searched_path}"
      end
    end
  end
end

.find_path(source_path) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/logaling/project.rb', line 37

def find_path(source_path)
  if source_path =~ /(.+\/projects\/[^\/]+).+/
    $1
  else
    source_path
  end
end

Instance Method Details

#glossariesObject



75
76
77
78
79
80
81
# File 'lib/logaling/project.rb', line 75

def glossaries
  glossaries = all_glossary_source_path.map do |source_path|
    name, source_language, target_language, type = File.basename(source_path).split(/\./)
    glossary(source_language, target_language)
  end
  glossaries.uniq{|glossary| glossary.to_s }
end

#glossary(source_language, target_language) ⇒ Object



56
57
58
# File 'lib/logaling/project.rb', line 56

def glossary(source_language, target_language)
  Logaling::Glossary.new(name, source_language, target_language, self)
end

#glossary_db_pathObject



71
72
73
# File 'lib/logaling/project.rb', line 71

def glossary_db_path
  @repository.logaling_db_home
end

#glossary_source_pathObject Also known as: source_directory_path



60
61
62
# File 'lib/logaling/project.rb', line 60

def glossary_source_path
  File.join(@repository.expand_path(@path), "glossary")
end

#glossary_sourcesObject



83
84
85
86
87
88
89
# File 'lib/logaling/project.rb', line 83

def glossary_sources
  all_glossary_source_path.map do |source_path_full|
    name, source_language, target_language, type = File.basename(source_path_full).split(/\./)
    source_path = @repository.relative_path(source_path_full)
    GlossarySource.create(source_path, glossary(source_language, target_language))
  end
end

#has_glossary?(source_language, target_language) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/logaling/project.rb', line 91

def has_glossary?(source_language, target_language)
  glossaries.any? {|glossary| glossary.to_s == [name, source_language, target_language].join('.') }
end

#imported?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/logaling/project.rb', line 95

def imported?
  false
end

#nameObject



52
53
54
# File 'lib/logaling/project.rb', line 52

def name
  File.basename(@path)
end

#normal_project?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/logaling/project.rb', line 103

def normal_project?
  true
end

#personal?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/logaling/project.rb', line 99

def personal?
  false
end

#relative_path(glossary_source_file_name) ⇒ Object

relative_path_from_logaling_home みたいな名前でGlossarySourceにある方が良いかも…



66
67
68
69
# File 'lib/logaling/project.rb', line 66

def relative_path(glossary_source_file_name)
  source_path = File.join(source_directory_path, glossary_source_file_name)
  @repository.relative_path(source_path)
end

#same?(project) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/logaling/project.rb', line 111

def same?(project)
  name == project.name
end

#typeObject



107
108
109
# File 'lib/logaling/project.rb', line 107

def type
  self.class.to_s.sub('Logaling::', '')
end