Class: TextInjector
- Inherits:
-
Object
- Object
- TextInjector
- Defined in:
- lib/text_injector.rb
Instance Method Summary collapse
-
#content(text = nil) ⇒ Object
both setter and getter for the dsl.
- #identifier(id = nil) ⇒ Object
-
#initialize(options = {}) ⇒ TextInjector
constructor
A new instance of TextInjector.
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TextInjector
Returns a new instance of TextInjector.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/text_injector.rb', line 2 def initialize(={}) @options = @options[:file] ||= raise "required :file option missing" @identifier ||= (@options[:identifier] || default_identifier) @content ||= @options[:content] if @options[:update] && !File.exists?(@options[:file]) warn("[fail] Can't find file: #{@options[:file]}") exit(1) end if @options[:update] && @options[:write] warn("[fail] Can't update AND write. choose one.") exit(1) end end |
Instance Method Details
#content(text = nil) ⇒ Object
both setter and getter for the dsl
21 22 23 |
# File 'lib/text_injector.rb', line 21 def content(text = nil) text.nil? ? @content : @content = text end |
#identifier(id = nil) ⇒ Object
24 25 26 |
# File 'lib/text_injector.rb', line 24 def identifier(id = nil) id.nil? ? @identifier : @identifier = id end |
#run ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/text_injector.rb', line 28 def run if @options[:update] write_file(updated_file) elsif @options[:write] write_file(marked_content) else puts marked_content exit end end |