Top Level Namespace

Defined Under Namespace

Classes: CMDKeywordsFactory, Scene

Instance Method Summary collapse

Instance Method Details

#get_scene(scenes, name) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/domain/scene.rb', line 12

def get_scene(scenes, name) Scene
    for scene in scenes
        scene_name = scene["name"]
        if scene_name == name
            return Scene.new(scene_name, scene["place"], scene["props"], scene["actions"])
        end
    end
end

#osObject



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/infra/os.rb', line 1

def os
  @os ||= (
    host_os = RbConfig::CONFIG['host_os']
    case host_os
    when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
      :windows
    when /darwin|mac os/
      :macosx
    when /linux/
      :linux
    when /solaris|bsd/
      :unix
    else
      raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
    end
  )
end

#run(scene_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
# File 'lib/main.rb', line 6

def run(scene_name)
    if scene_name == "-v"
        puts "0.0.3"
        return
    end

    os = os()
    cmd_keywords = CMDKeywordsFactory.get_cmd_keywords(os)
    if cmd_keywords == nil 
        puts "暂不支持 #{os} 操作系统"
        return
    end
    cd = cmd_keywords[:cd]
    cp = cmd_keywords[:cp]
    rm = cmd_keywords[:rm]
    join = cmd_keywords[:and]

    dir_pwd = Dir.pwd
    filepath = File.join(dir_pwd, 'playbook.toml')
    playbook = TOML.load_file(filepath)
    scenes = playbook["scenes"]
    
    scene = get_scene(scenes, scene_name)
    if !scene.is_a?(Scene)
        puts "没有名称为#{scene_name}的场景"
    else
        place = scene.place
        place = (place.start_with? "~") ? dir_pwd + place[1..-1] : place
        goToPlace = "#{cd} #{place}"
        actions = scene.actions
        commands = Array.new
        props = scene.props
        if props.nil?
            commands.push(goToPlace).concat(actions)
        else
            placeProps = Array.new
            cleanProps = Array.new
            for prop in props
                placeProps.push("#{cp} #{File.join(dir_pwd, prop)} #{place}/#{prop}")
                cleanProps.push("#{rm} #{prop}")
            end
            commands.push(placeProps, goToPlace).concat(actions).push(cleanProps)
        end
        act = commands.join(" #{join} ")
        system act
    end
end