Class: Ritsu::SrcFile

Inherits:
Object
  • Object
show all
Includes:
Utility, Utility::InstanceSet
Defined in:
lib/ritsu/src_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utility

platform

Methods included from Utility::InstanceSet

included, #initialize_instance

Constructor Details

#initialize(src_path, owner) ⇒ SrcFile

Returns a new instance of SrcFile.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ritsu/src_file.rb', line 18

def initialize(src_path, owner)
  if !(self.class.is_valid_src_path?(src_path))
    raise ArgumentError.new("'#{src_path}' is not a valid source path")
  end

  @src_path = src_path
  @owner = owner
  
  SrcFile.instances << self
  @owner.src_files << self
end

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



12
13
14
# File 'lib/ritsu/src_file.rb', line 12

def owner
  @owner
end

#src_pathObject (readonly)

Returns the value of attribute src_path.



11
12
13
# File 'lib/ritsu/src_file.rb', line 11

def src_path
  @src_path
end

Class Method Details

.find_by_src_path(src_path) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/ritsu/src_file.rb', line 71

def self.find_by_src_path(src_path)
  instances.each do |instance|
    if instance.src_path == src_path
      return instance
    end
  end
  nil
end

.is_valid_src_path?(p) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ritsu/src_file.rb', line 14

def self.is_valid_src_path?(p)
  p =~ /^[A-Za-z0-9_.][A-Za-z0-9_.\-\/]*$/
end

.validate_instance(instance) ⇒ Object



34
35
36
37
38
# File 'lib/ritsu/src_file.rb', line 34

def self.validate_instance(instance)
  if instances.select { |x| x.src_path == instance.src_path }.length > 0
    raise ArgumentError.new("source file with path '#{instance.src_path}' already exists")
  end
end

Instance Method Details

#abs_pathObject



44
45
46
# File 'lib/ritsu/src_file.rb', line 44

def abs_path
  File.expand_path(project.project_dir + "/src/" + src_path)
end

#base_nameObject



30
31
32
# File 'lib/ritsu/src_file.rb', line 30

def base_name
  File.basename(src_path)
end

#createObject



48
49
50
# File 'lib/ritsu/src_file.rb', line 48

def create
  FileRobot.create_file(abs_path, "\n")
end

#include_in_source_files?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/ritsu/src_file.rb', line 67

def include_in_source_files?
  return true
end

#projectObject



40
41
42
# File 'lib/ritsu/src_file.rb', line 40

def project
  owner.project
end

#removeObject



63
64
65
# File 'lib/ritsu/src_file.rb', line 63

def remove
  FileRobot.remove_file(abs_path)
end

#updateObject



52
53
54
55
56
57
58
# File 'lib/ritsu/src_file.rb', line 52

def update
  if !File.exists?(abs_path)
    create
  else
    update_content
  end
end

#update_contentObject



60
61
# File 'lib/ritsu/src_file.rb', line 60

def update_content
end