Class: Chemlab::CLI::Stubber::PageLibrary
- Inherits:
-
Object
- Object
- Chemlab::CLI::Stubber::PageLibrary
- Defined in:
- lib/chemlab/cli/stubber.rb
Overview
A Class representation of a Page Library
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#generate_stub ⇒ Object
Generate the stub for a given Page Library.
-
#initialize(path) ⇒ PageLibrary
constructor
A new instance of PageLibrary.
Constructor Details
#initialize(path) ⇒ PageLibrary
Returns a new instance of PageLibrary.
43 44 45 |
# File 'lib/chemlab/cli/stubber.rb', line 43 def initialize(path) @path = File.absolute_path(path) end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
41 42 43 |
# File 'lib/chemlab/cli/stubber.rb', line 41 def path @path end |
Instance Method Details
#generate_stub ⇒ Object
Generate the stub for a given Page Library
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/chemlab/cli/stubber.rb', line 48 def generate_stub $stdout.print "- #{@path} :\t" begin load @path library = Stubber.libraries.last # last appended library is this Page Library require 'chemlab/core_ext/string/inflections' stub_path = @path.gsub(@path[@path.rindex('.')..], '.stub.rb') File.open(stub_path, 'w') do |stub| stub.write(ERB.new(File.read(File.("#{__dir__}/stub.erb")), trim_mode: '%<>').result_with_hash({ library: library })) Stubber.libraries.pop end rescue StandardError => e # $stderr.print(e.message) raise e ensure $stdout.print "\tDone.\n" end end |