Class: Peto::Master
- Inherits:
-
Object
- Object
- Peto::Master
- Defined in:
- lib/peto/master.rb
Instance Attribute Summary collapse
-
#contract ⇒ Object
readonly
Returns the value of attribute contract.
Instance Method Summary collapse
- #generate(output_dir = nil) ⇒ Object
- #load(filename) ⇒ Object
- #parse ⇒ Object
- #write(filepath, content) ⇒ Object
Instance Attribute Details
#contract ⇒ Object (readonly)
Returns the value of attribute contract.
17 18 19 |
# File 'lib/peto/master.rb', line 17 def contract @contract end |
Instance Method Details
#generate(output_dir = nil) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/peto/master.rb', line 25 def generate(output_dir=nil) parse.each do |name, content| filepath = File.join(output_dir||File::dirname(@filename), "#{name}.rb") write(filepath, content) end end |
#load(filename) ⇒ Object
13 14 15 16 |
# File 'lib/peto/master.rb', line 13 def load(filename) @filename = filename @contract = YAML.load(IO.read(Pathname(filename))) end |
#parse ⇒ Object
19 20 21 22 23 |
# File 'lib/peto/master.rb', line 19 def parse (@contract["types"]||{}).inject({}) {|result, type| result.merge!(Generator.new(@contract).generate_class(TEMPLATE_DIR + "/rb_classes.erb", type)) }.merge!(Generator.new(@contract).generate_procedure(TEMPLATE_DIR + "/rb_procedures.erb")) end |
#write(filepath, content) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/peto/master.rb', line 32 def write(filepath, content) print " " if File.exist?(filepath) if File.read(filepath) == content print "identical".blue.bold else print " update".white.bold end else print " create".green.bold end print " " open(filepath, "w") do |file| file.write(content) end puts filepath end |