Class: SRBC

Inherits:
Object
  • Object
show all
Includes:
SRBC_cli, SrbcCommand
Defined in:
lib/srbc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SRBC_cli

#run

Methods included from SrbcCommand

#run_file, #run_program, #srbc_command

Constructor Details

#initialize(executor) ⇒ SRBC



11
12
13
14
15
16
17
# File 'lib/srbc.rb', line 11

def initialize(executor)
  @ext = []
  @gem_root = Gem.loaded_specs['srbc'].full_gem_path
  @executor = executor
  @settings ={}
  @lunched = true
end

Instance Attribute Details

#lunchedObject

Returns the value of attribute lunched.



6
7
8
# File 'lib/srbc.rb', line 6

def lunched
  @lunched
end

#settingsObject

Returns the value of attribute settings.



6
7
8
# File 'lib/srbc.rb', line 6

def settings
  @settings
end

Instance Method Details

#get_file_list(name) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/srbc.rb', line 48

def get_file_list (name)
  file_name = name.split(" ")[0]
  args = name.split(" ")[1..name.split(" ").length-1].join" "
  file_list ={}

  #get file list each extension specified in settings.yml
  @ext.each do |extension|
    file = Dir.glob extension

    #delete files not compare with typed file name
    file.delete_if {|f| f !~ /^#{file_name}/}
    file.each do |file_nme|
      file_list = file_list.merge Hash[file_nme, args]
    end
    end

  file_list
end

#read_settingsObject

try read settings, if not exsist crate settings file



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

def read_settings
    @settings =  YAML::load_file "#{@gem_root}/settings.yml"
end

#save_settingsObject



36
37
38
39
40
# File 'lib/srbc.rb', line 36

def save_settings
  File.open("#{@gem_root}/settings.yml", 'w') do |file|
    file.write @settings.to_yaml
  end
end

#set_settings(executor, extension) ⇒ Object

write extension to file/ return - extension array



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

def set_settings(executor, extension)
  if extension =~ /^\*\..*$/ && extension !~ /^\*\.$/
  @ext ||= []
  #сheck added extension early or not
  unless @ext.include? extension
    @ext << extension
  else
    puts 'Extension already added'
  end
    @settings[executor] = @ext
    save_settings
  else
  puts 'Wrong format! You muts type "@add *.extension"'
  end
end