history 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.ruby CHANGED
@@ -54,7 +54,7 @@ title: History
54
54
  created: '2010-02-19'
55
55
  organization: Rubyworks
56
56
  summary: HISTORY and CHANGELOG parser
57
- version: 0.2.0
57
+ version: 0.3.0
58
58
  description: ! 'History is a HISTORY file parser. It can parse common HISTORY file
59
59
  layouts
60
60
 
@@ -63,4 +63,4 @@ description: ! 'History is a HISTORY file parser. It can parse common HISTORY fi
63
63
  a number of things, in particular it can be used to generate tag messages
64
64
 
65
65
  and add pre-release change lists to release announcements.'
66
- date: '2012-05-25'
66
+ date: '2012-05-27'
data/DEMO.md CHANGED
@@ -68,7 +68,7 @@ The initializer takes the root directory for the project
68
68
  and looks for a file called +HISTORY+, optionally ending
69
69
  in an extension such as +.txt+ or +.rdoc+, etc.
70
70
 
71
- history = History.find('tmp/example')
71
+ history = History.at('tmp/example')
72
72
 
73
73
  Now we should have an enumeration of each release entry in
74
74
  the HISTORY file.
data/HISTORY.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # RELEASE HISTORY
2
2
 
3
+ ## 0.3.0 / 2012-05-27
4
+
5
+ New release makes the constructor interface more flexible, in part
6
+ by making use of the Pathname library.
7
+
8
+ Changes:
9
+
10
+ * Improves constructor interface.
11
+
12
+
3
13
  ## 0.2.0 / 2012-05-25
4
14
 
5
15
  This the first usable release. There's actual code now ;)
@@ -61,7 +61,7 @@ The initializer takes the root directory for the project
61
61
  and looks for a file called +HISTORY+, optionally ending
62
62
  in an extension such as +.txt+ or +.rdoc+, etc.
63
63
 
64
- history = History.find('tmp/example')
64
+ history = History.at('tmp/example')
65
65
 
66
66
  Now we should have an enumeration of each release entry in
67
67
  the HISTORY file.
@@ -1,4 +1,4 @@
1
- #require 'history/core_ext'
1
+ require 'pathname'
2
2
  require 'history/release'
3
3
 
4
4
  # The History class is a HISTORY file parser. It parses HISTORY files
@@ -38,25 +38,40 @@ class History
38
38
  # Convenience constant for `File::FNM_CASEFOLD`.
39
39
  CASEFOLD = File::FNM_CASEFOLD
40
40
 
41
- #
42
- def self.parse(text, opts={})
43
- opts[:text] = text
44
- new(opts[:file], opts)
41
+ # Parse history from given text.
42
+ def self.parse(text)
43
+ new(text.to_s)
45
44
  end
46
45
 
47
- def self.text(text, opts={})
48
- parse(text, opts)
46
+ # Read and parse history from given file.
47
+ def self.read(file)
48
+ new(Pathname.new(file))
49
49
  end
50
50
 
51
- #
52
- def self.file(file)
53
- new(file)
51
+ # Lookup history file given a project root directory.
52
+ # If a history file is not present, assume a default
53
+ # file name of `HISTORY`.
54
+ def self.at(root=Dir.pwd)
55
+ if file = Dir.glob(File.join(root, DEFAULT_FILE), CASEFOLD).first
56
+ new(Pathname.new(file))
57
+ else
58
+ file = File.join(root, 'HISTORY')
59
+ new(:file=>file)
60
+ end
54
61
  end
55
62
 
56
- #
63
+ # Alias for #at.
57
64
  def self.find(root=Dir.pwd)
58
- file = Dir.glob(File.join(root, DEFAULT_FILE), CASEFOLD).first
59
- new(file)
65
+ at(root)
66
+ end
67
+
68
+ # Does a HISTORY file exist?
69
+ def self.exist?(path=Dir.pwd)
70
+ if File.directory?(path)
71
+ Dir.glob(File.join(path, DEFAULT_FILE), CASEFOLD).first
72
+ else
73
+ File.exist?(path) ? path : false
74
+ end
60
75
  end
61
76
 
62
77
  # HISTORY file's path.
@@ -69,46 +84,50 @@ class History
69
84
  attr :releases
70
85
 
71
86
  # New History.
72
- def initialize(file=nil, opts={})
73
- if Hash === file
87
+ def initialize(io=nil, opts={})
88
+ if Hash === io
74
89
  opts = file
75
- file = nil
90
+ io = nil
76
91
  end
77
92
 
78
- @file = file
79
- @text = opts[:text]
93
+ @releases = []
80
94
 
81
- if @file
82
- # if file is given but no text, raise error if file not found
83
- raise "file not found" unless File.exist?(@file) unless @text
95
+ case io
96
+ when String
97
+ parse(io)
98
+ when Pathname
99
+ @file = io
100
+ parse(io.read)
101
+ when File
102
+ @file = io.path
103
+ parse(io.read)
84
104
  else
85
- @file = Dir.glob(DEFAULT_FILE, CASEFOLD).first || 'HISTORY'
105
+ parse(io.read)
86
106
  end
87
107
 
88
- unless @text
89
- @text = File.read(@file) if File.exist?(@file)
90
- end
108
+ @file = opts[:file] if opts.key?(:file)
109
+ end
91
110
 
92
- parse
111
+ # Does history file exist?
112
+ def exist?
113
+ File.file?(@file)
93
114
  end
94
115
 
95
- # Read and parse the Histoy file.
96
- def parse
97
- @releases = []
98
- entry = nil
99
-
100
- if text
101
- text.each_line do |line|
102
- if HEADER_RE =~ line
103
- @releases << Release.new(entry) if entry
104
- entry = line
105
- else
106
- next unless entry
107
- entry << line
108
- end
116
+ # Parse History text.
117
+ def parse(text)
118
+ return unless text
119
+ releases, entry = [], nil
120
+ text.each_line do |line|
121
+ if HEADER_RE =~ line
122
+ releases << Release.new(entry) if entry
123
+ entry = line
124
+ else
125
+ next unless entry
126
+ entry << line
109
127
  end
110
- @releases << Release.new(entry)
111
128
  end
129
+ releases << Release.new(entry)
130
+ @releases = releases
112
131
  end
113
132
 
114
133
  # Lookup release by version.
@@ -116,7 +135,7 @@ class History
116
135
  releases.find{ |r| r.version == version }
117
136
  end
118
137
 
119
- # Returns first entry in releases list.
138
+ # Returns first entry in release list.
120
139
  def release
121
140
  releases.first
122
141
  end
@@ -54,7 +54,7 @@ title: History
54
54
  created: '2010-02-19'
55
55
  organization: Rubyworks
56
56
  summary: HISTORY and CHANGELOG parser
57
- version: 0.2.0
57
+ version: 0.3.0
58
58
  description: ! 'History is a HISTORY file parser. It can parse common HISTORY file
59
59
  layouts
60
60
 
@@ -63,4 +63,4 @@ description: ! 'History is a HISTORY file parser. It can parse common HISTORY fi
63
63
  a number of things, in particular it can be used to generate tag messages
64
64
 
65
65
  and add pre-release change lists to release announcements.'
66
- date: '2012-05-25'
66
+ date: '2012-05-27'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-25 00:00:00.000000000 Z
12
+ date: 2012-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: detroit
16
- requirement: &16961460 !ruby/object:Gem::Requirement
16
+ requirement: &16873300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *16961460
24
+ version_requirements: *16873300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: qed
27
- requirement: &16983160 !ruby/object:Gem::Requirement
27
+ requirement: &16871960 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *16983160
35
+ version_requirements: *16871960
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ae
38
- requirement: &16979640 !ruby/object:Gem::Requirement
38
+ requirement: &16868240 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *16979640
46
+ version_requirements: *16868240
47
47
  description: ! 'History is a HISTORY file parser. It can parse common HISTORY file
48
48
  layouts
49
49