Class: CommitMsgUrlShortener::Service
- Inherits:
-
Object
- Object
- CommitMsgUrlShortener::Service
- Defined in:
- lib/commit-msg-url-shortener/service.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #apply(commit_msg_filepath) ⇒ Object
-
#initialize(name, &block) ⇒ Service
constructor
A new instance of Service.
Constructor Details
#initialize(name, &block) ⇒ Service
Returns a new instance of Service.
4 5 6 7 |
# File 'lib/commit-msg-url-shortener/service.rb', line 4 def initialize name, &block @name = name @block = block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/commit-msg-url-shortener/service.rb', line 3 def name @name end |
Class Method Details
.define(&block) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/commit-msg-url-shortener/service.rb', line 22 def self.define &block if @@expected.nil? or @@expected.kind_of?(Service) raise "You must load the service script using the Service#fabricate method." end @@expected = Service.new @@expected, &block end |
.fabricate(path) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/commit-msg-url-shortener/service.rb', line 29 def self.fabricate path @@expected = name_of path require path unless @@expected.kind_of? Service puts "Warning! Service #{@@expected.inspect} should call the Service#define method." else @@expected end end |
.name_of(path) ⇒ Object
39 40 41 |
# File 'lib/commit-msg-url-shortener/service.rb', line 39 def self.name_of path File.basename(path).gsub(File.extname(path), '').downcase.strip end |
Instance Method Details
#apply(commit_msg_filepath) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/commit-msg-url-shortener/service.rb', line 9 def apply commit_msg_filepath raise "Cannot find temporary commit message file #{commit_msg_filepath.inspect}" unless File.exist? commit_msg_filepath = File.read(commit_msg_filepath).strip = ServiceHelper.module_exec(, &@block) || '' .strip! if != and .size > 0 File.open(commit_msg_filepath, 'wb') {|file| file.write } else nil end end |