Class: Roma::Mkconfig::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/roma/tools/mkconfig.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/roma/tools/mkconfig.rb', line 28

def initialize
  flag = false
  @all = YAML.load <<-YAML
  menu:
    name:
    path_name: menu
    message: Please select by number.
    choice:
      - Select storage
      - Select plugin
      - Calculate File Descriptor
      - Save
    next:
      - storage
      - plugin
      - language
      - save

  storage:
    name: selected_storage
    path_name: storage
    message: Which storage will you use?
    choice:
      - Ruby Hash
      - Tokyo Cabinet
      - Groonga
    default: 1
    next:
      - menu
      - memory
      - memory
  memory:
    name: memory_size_GB
    path_name:
    float_flg: on
    message: How big memory size in 1 server? Please measure in GB.
    default: 0.6
    next: process
  process:
    name: process_num
    path_name:
    message: How many run ROMA process per machine?
    default: 2
    next: server
  server:
    name: server_num
    path_name:
    message: How many machine run as ROMA server?
    default: 1
    next: data
  data:
    name: data_num
    path_name:
    message: How many data will you store?
    default: 10000
    next: menu

  plugin:
    name: selected_plugin
    path_name: plugin
    message: Please select which plugin will you use.(plugin_storage.rb is essential unless you make alternative plugin.)
    choice:
      #{
        list = load_path(PLUGIN_DIR) << "Select all plugins"
        list.delete("plugin_storage.rb")
        list.unshift("plugin_storage.rb")
        list
      }
    default: 1
    next:
      #{
        r = Array.new
        load_path(PLUGIN_DIR).count.times{ r << "continue" }
        r << "menu"
        r
      }
    store_type: Array
  continue:
    name:
    path_name: 
    message: Will you use other plugin?
    choice:
      - Select more
      - No more
    default: 2
    next:
      - plugin
      - check_plugin
  check_plugin:
    name:
    path_name: 
    message: ROMA requires plugin_storage.rb or substitute plugin.Will you continue without plugin_storage.rb?
    choice:
      - Add plugin_storage.rb
      - Not necessary
    default: 2
    next:
      - add_plugin
      - menu

  language:
    name: client_language
    path_name:
    message: Please select programming language of client by number.
    choice:
      - Ruby
      - Java
      - PHP
    default: 3
    next:
      - fd_server
      - fd_server
      - fd_server
  fd_server:
    name: server_num
    path_name: FileDescriptor
    message: How many machine run as ROMA server?
    default: 1
    next: fd_client
  fd_client:
    name: client_num 
    path_name:
    message: How many machine run as ROMA client?
    default: 1
    next: menu

  save: END

  YAML
end

Instance Attribute Details

#allObject

Returns the value of attribute all.



26
27
28
# File 'lib/roma/tools/mkconfig.rb', line 26

def all
  @all
end

#flagObject

Returns the value of attribute flag.



26
27
28
# File 'lib/roma/tools/mkconfig.rb', line 26

def flag
  @flag
end

Instance Method Details

#[](s) ⇒ Object



163
164
165
# File 'lib/roma/tools/mkconfig.rb', line 163

def [](s)
  all[s]
end

#keysObject



159
160
161
# File 'lib/roma/tools/mkconfig.rb', line 159

def keys
  all.keys
end

#load_path(path) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
# File 'lib/roma/tools/mkconfig.rb', line 167

def load_path(path)
  ret = Array.new
  files = Dir::entries(path)
  files.delete("plugin_stub.rb") if files.include?("plugin_stub.rb")

  files.each do |file|
    ret << file if File::ftype(File.join(path, file)) == "file"
  end

  ret
end

#next(key, input) ⇒ Object



190
191
192
193
194
195
196
197
198
# File 'lib/roma/tools/mkconfig.rb', line 190

def next (key, input)
  target = all[key]["next"]

  if target.class == Array
    return target[input.to_i - 1]
  else
    return target
  end
end


179
180
181
182
183
184
185
186
187
188
# File 'lib/roma/tools/mkconfig.rb', line 179

def print_question(key)
  target = all[key]
  #print question
  print "#{target["message"]}\n"
  if target.key?("choice")
    target["choice"].each_with_index do |k, i|
      print "[#{i + 1}] #{k}\n"
    end
  end
end