Class: Readme

Inherits:
Object
  • Object
show all
Defined in:
lib/teuton/readme/dsl.rb,
lib/teuton/readme/readme.rb

Overview

Readme

readme, target, goto, run
expect,
gett, set, unique, log

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script_path, config_path) ⇒ Readme

Returns a new instance of Readme.



39
40
41
42
43
44
45
46
47
48
# File 'lib/teuton/readme/readme.rb', line 39

def initialize(script_path, config_path)
  # script_path Path to main rb file (start.rb)
  # config_path Path to main config file (config.yaml)
  @path = {}
  @path[:script] = script_path
  @path[:dirname] = File.dirname(script_path)
  @path[:filename] = File.basename(script_path, ".rb")
  @path[:config] = config_path
  reset
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

If a method call is missing, then delegate to concept parent. def method_missing(method, args = {})



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/teuton/readme/dsl.rb', line 88

def method_missing(method, *args, &block)
  m = method.to_s
  if m[0] == "_"
    instance_eval("get(:#{m[1, m.size - 1]})", __FILE__, __LINE__)
  # elsif not Application.instance.macros[m].nil?
  elsif not Project.value[:macros][m].nil?
    puts "macro exec: #{m}"
    code = ""
    args[0].keys.each { |key| code += "set(:#{key}, '#{args[0][key]}')\n" }
    puts code
    # instance_eval(code)
    # Application.instance.macros[m].call
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



37
38
39
# File 'lib/teuton/readme/readme.rb', line 37

def data
  @data
end

#resultObject (readonly)

Creates README.md file from RB script file



36
37
38
# File 'lib/teuton/readme/readme.rb', line 36

def result
  @result
end

Instance Method Details

#expect(_cond, _args = {}) ⇒ Object Also known as: expect_any, expect_first, expect_last, expect_none, expect_one



64
65
66
67
# File 'lib/teuton/readme/dsl.rb', line 64

def expect(_cond, _args = {})
  @current[:actions] << @action
  result.reset
end

#get(value) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/teuton/readme/dsl.rb', line 74

def get(value)
  unless @config[:global][value].nil?
    @global_params[value] = @config[:global][value]
    return @config[:global][value]
  end

  return value.to_s.upcase if @setted_params.include? value

  @cases_params << value
  value.to_s.upcase
end

#gett(value) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/teuton/readme/dsl.rb', line 107

def gett(value)
  a = get(value)
  return "[#{value}](\#required-params)" if @cases_params.include? value
  return "[#{value}](\#created-params)" if @setted_params[value]

  "[#{a}](\#global-params)" if @global_params.include? value
end

#goto(host = :localhost, args = {}) ⇒ Object



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
# File 'lib/teuton/readme/dsl.rb', line 27

def goto(host = :localhost, args = {})
  unless host == :localhost
    b = {}
    a = "#{host}_ip".to_sym
    if @config[:global][a].nil? && !@setted_params.include?(a)
      @cases_params << a
    end
    b[:ip] = @config[:global][a] if @config[:global][a]
    b[:ip] = @setted_params[a] if @setted_params[a]

    a = "#{host}_username".to_sym
    if @config[:global][a].nil? && !@setted_params.include?(a)
      @cases_params << a
    end
    b[:username] = @config[:global][a] if @config[:global][a]
    b[:username] = @setted_params[a] if @setted_params[a]

    a = "#{host}_password".to_sym
    if @config[:global][a].nil? && !@setted_params.include?(a)
      @cases_params << a
    end
    b[:password] = @config[:global][a] if @config[:global][a]
    b[:password] = @setted_params[a] if @setted_params[a]

    @required_hosts[host.to_s] = b
  end
  @action[:host] = host
  @action[:exec] = args[:exec] || "noexec"
end

#log(text = "", type = :info) ⇒ Object



123
124
125
# File 'lib/teuton/readme/dsl.rb', line 123

def log(text = "", type = :info)
  @data[:logs] << "[#{type}]: " + text.to_s
end

#readme(text) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/teuton/readme/dsl.rb', line 8

def readme(text)
  if @action[:target].nil?
    # It's a group readme
    @current[:readme] << text
  else
    # It's a target readme
    @action[:readme] << text
  end
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/teuton/readme/dsl.rb', line 103

def respond_to_missing?(method_name, include_private = false)
  true
end

#run(command, args = {}) ⇒ Object



57
58
59
60
61
62
# File 'lib/teuton/readme/dsl.rb', line 57

def run(command, args = {})
  args[:exec] = command
  host = :localhost
  host = args[:on] if args[:on]
  goto(host, args)
end

#set(key, value) ⇒ Object



115
116
117
# File 'lib/teuton/readme/dsl.rb', line 115

def set(key, value)
  @setted_params[key] = value
end

#showObject



50
51
52
53
54
55
# File 'lib/teuton/readme/readme.rb', line 50

def show
  process_content
  show_head
  show_content
  show_tail
end

#target(desc, args = {}) ⇒ Object Also known as: goal



18
19
20
21
22
23
24
# File 'lib/teuton/readme/dsl.rb', line 18

def target(desc, args = {})
  previous_host = @action[:host]
  @action = {target: desc, host: previous_host, readme: []}
  weight = 1.0
  weight = args[:weight].to_f if args[:weight]
  @action[:weight] = weight
end

#unique(_key, _value) ⇒ Object



119
120
121
# File 'lib/teuton/readme/dsl.rb', line 119

def unique(_key, _value)
  # don't do nothing
end