everything-core 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8aca9092f34828f75505f2d3c36a03bd20845114
4
- data.tar.gz: 7dfbd73bc6f5a5009f5abe169359067bca9b0b29
3
+ metadata.gz: 496abd62729fa5456b73ba7325a331e40ce6ba32
4
+ data.tar.gz: ba227e14bc31850f0e714c44121cf1a44d82b3f6
5
5
  SHA512:
6
- metadata.gz: f7d1b41ee152d93d758cfa0cbe2b082cb07c11d39dfcdc45063bf7f756d669d95d31d8678b5e4c14a13408779f9dfc91ee9aa8f85854c84da6e03d8ea9738cb3
7
- data.tar.gz: 64dd8236c33db109b282af925f74b60acb51045ff30cdf3a80b2c501c489b7a36212c812ee65fbcd2d12b3ce5aa143131505046158fffdedc98fb50bcb07ca5d
6
+ metadata.gz: 2c5a438383b336fceece599184d79f2a3fe4d131ff8ef9d50397dd92710c6d86856c94e03d5263e8e975e608cbb1330c80e768565a510d17fb213587e509155f
7
+ data.tar.gz: 7b05054d7200b1f55e9d1d2562647113774a5a4ee1bd83efd03801b6bf4495fe89ca919a9121a7fe3e7e2e9cc5e9eaa05e068768f70a3089c3b6192bd9f33d3d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.8
4
+
5
+ - Require modules which had been used but not explicitly required
6
+ - Add #raw_markdown=, #save to Content
7
+ - Add #raw_yaml=, #save to Metadata
8
+ - Add #raw_markdown=, #raw_yaml, #raw_yaml=, #save to Piece
9
+
3
10
  ## 0.0.7
4
11
 
5
12
  - Add a piece#name to return the name from the piece's path
data/README.md CHANGED
@@ -67,6 +67,11 @@ piece['categories'] # Returns the value for the `categories` metadata key
67
67
  piece.public? # Convience method to return the value for the boolean `public` metadata key
68
68
  piece.content # Return an instance of the piece's content
69
69
  piece.metadata # Return an instance of the piece's metadata
70
+
71
+ # You can also edit a piece's content and metadata
72
+ piece.raw_markdown = some_markdown # Sets the raw_markdown on the piece's content
73
+ piece.raw_yaml = some_yaml # Sets the raw_yaml on the piece's metadata
74
+ piece.save # Save the piece's content and metadata to disk
70
75
  ```
71
76
 
72
77
 
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
2
+
1
3
  module Everything
2
4
  class Piece
3
5
  class Content
@@ -21,6 +23,16 @@ module Everything
21
23
  @raw_markdown ||= File.read(file_path)
22
24
  end
23
25
 
26
+ def raw_markdown=(value)
27
+ @raw_markdown = value
28
+ end
29
+
30
+ def save
31
+ FileUtils.mkdir_p(piece_path)
32
+
33
+ File.write(file_path, @raw_markdown)
34
+ end
35
+
24
36
  private
25
37
  attr_reader :piece_path
26
38
 
@@ -1,3 +1,4 @@
1
+ require 'fileutils'
1
2
  require 'yaml'
2
3
 
3
4
  module Everything
@@ -17,6 +18,16 @@ module Everything
17
18
  @raw_yaml ||= YAML.load_file(file_path)
18
19
  end
19
20
 
21
+ def raw_yaml=(value)
22
+ @raw_yaml = value
23
+ end
24
+
25
+ def save
26
+ FileUtils.mkdir_p(piece_path)
27
+
28
+ File.write(file_path, @raw_yaml)
29
+ end
30
+
20
31
  def_delegators :raw_yaml, :[]
21
32
 
22
33
  private
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  module Everything
2
4
  class Piece
3
5
  extend Forwardable
@@ -12,7 +14,7 @@ module Everything
12
14
  @content ||= Content.new(full_path)
13
15
  end
14
16
 
15
- def_delegators :content, :body, :raw_markdown, :title
17
+ def_delegators :content, :body, :raw_markdown, :raw_markdown=, :title
16
18
 
17
19
  def metadata
18
20
  @metadata ||= Metadata.new(full_path)
@@ -22,9 +24,16 @@ module Everything
22
24
  metadata['public']
23
25
  end
24
26
 
27
+ def_delegators :metadata, :raw_yaml, :raw_yaml=
28
+
25
29
  def name
26
30
  File.basename(full_path)
27
31
  end
32
+
33
+ def save
34
+ content.save
35
+ metadata.save
36
+ end
28
37
  end
29
38
  end
30
39
 
@@ -1,3 +1,3 @@
1
1
  module Everything
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -86,12 +86,105 @@ MD
86
86
  .to receive(:read)
87
87
  .and_call_original
88
88
 
89
- content.raw_markdown
90
- content.raw_markdown
89
+ 2.times { content.raw_markdown }
91
90
 
92
91
  expect(File)
93
92
  .to have_received(:read)
94
93
  .exactly(:once)
95
94
  end
96
95
  end
96
+
97
+ describe '#raw_markdown=' do
98
+ include_context 'with tmp piece on disk'
99
+
100
+ let(:new_raw_markdown) do
101
+ <<MD
102
+ # New Markdown
103
+
104
+ This is a completely new bit of markdown.
105
+ MD
106
+ end
107
+
108
+ it 'sets the raw_markdown value' do
109
+ content.raw_markdown = new_raw_markdown
110
+
111
+ expect(content.raw_markdown).to eq(new_raw_markdown)
112
+ end
113
+ end
114
+
115
+ describe '#save' do
116
+ let(:tmp_dir) do
117
+ Dir.tmpdir
118
+ end
119
+
120
+ let(:tmp_piece_path) do
121
+ File.join(tmp_dir, 'a-test-piece')
122
+ end
123
+
124
+ before do
125
+ content.raw_markdown = "# Ship Shape"
126
+ end
127
+
128
+ after do
129
+ FileUtils.remove_entry(tmp_piece_path)
130
+ end
131
+
132
+ context 'when the piece directory does not exist' do
133
+ it 'creates the folder' do
134
+ expect(Dir.exist?(tmp_piece_path)).to eq(false)
135
+
136
+ content.save
137
+
138
+ expect(Dir.exist?(tmp_piece_path)).to eq(true)
139
+ end
140
+
141
+ it 'creates the content markdown file' do
142
+ expect(File.exist?(content.file_path)).to eq(false)
143
+
144
+ content.save
145
+
146
+ expect(File.exist?(content.file_path)).to eq(true)
147
+ end
148
+
149
+ it 'writes the markdown to the file' do
150
+ content.save
151
+
152
+ expect(File.read(content.file_path)).to eq('# Ship Shape')
153
+ end
154
+ end
155
+
156
+ context 'when the piece directory exists' do
157
+ before do
158
+ FileUtils.mkdir_p(tmp_piece_path)
159
+ end
160
+
161
+ context 'when the content file does not exist' do
162
+ it 'creates the content markdown file' do
163
+ expect(File.exist?(content.file_path)).to eq(false)
164
+
165
+ content.save
166
+
167
+ expect(File.exist?(content.file_path)).to eq(true)
168
+ end
169
+
170
+ it 'writes the markdown to the file' do
171
+ content.save
172
+
173
+ expect(File.read(content.file_path)).to eq('# Ship Shape')
174
+ end
175
+ end
176
+
177
+ context 'when the content file already exists' do
178
+ before do
179
+ File.write(content.file_path, '# Rolly Polly')
180
+ end
181
+
182
+ it 'overwrites the file with the correct markdown' do
183
+ content.save
184
+
185
+ expect(File.read(content.file_path)).to eq('# Ship Shape')
186
+ end
187
+ end
188
+ end
189
+ end
97
190
  end
@@ -89,4 +89,110 @@ YAML
89
89
  .exactly(:once)
90
90
  end
91
91
  end
92
+
93
+ describe '#raw_yaml=' do
94
+ include_context 'with tmp piece on disk'
95
+
96
+ let(:new_raw_yaml) do
97
+ <<YAML
98
+ ---
99
+ public: true
100
+ other: okay
101
+ YAML
102
+ end
103
+
104
+ it 'sets the raw_yaml value' do
105
+ metadata.raw_yaml = new_raw_yaml
106
+
107
+ expect(metadata.raw_yaml).to eq(new_raw_yaml)
108
+ end
109
+ end
110
+
111
+ describe '#save' do
112
+ let(:tmp_dir) do
113
+ Dir.tmpdir
114
+ end
115
+
116
+ let(:tmp_piece_path) do
117
+ File.join(tmp_dir, 'fake-piece-here')
118
+ end
119
+
120
+ before do
121
+ metadata.raw_yaml = <<YAML
122
+ ---
123
+ favorite_color: blue
124
+ YAML
125
+ end
126
+
127
+ after do
128
+ FileUtils.remove_entry(tmp_piece_path)
129
+ end
130
+
131
+ context 'when the piece directory does not exist' do
132
+ it 'creates the folder' do
133
+ expect(Dir.exist?(tmp_piece_path)).to eq(false)
134
+
135
+ metadata.save
136
+
137
+ expect(Dir.exist?(tmp_piece_path)).to eq(true)
138
+ end
139
+
140
+ it 'creates the metadata yaml file' do
141
+ expect(File.exist?(metadata.file_path)).to eq(false)
142
+
143
+ metadata.save
144
+
145
+ expect(File.exist?(metadata.file_path)).to eq(true)
146
+ end
147
+
148
+ it 'writes the yaml to the file' do
149
+ metadata.save
150
+
151
+ expect(File.read(metadata.file_path)).to eq(<<YAML)
152
+ ---
153
+ favorite_color: blue
154
+ YAML
155
+ end
156
+ end
157
+
158
+ context 'when the piece directory exists' do
159
+ before do
160
+ FileUtils.mkdir_p(tmp_piece_path)
161
+ end
162
+
163
+ context 'when the metadata file does not exist' do
164
+ it 'creates the metadata yaml file' do
165
+ expect(File.exist?(metadata.file_path)).to eq(false)
166
+
167
+ metadata.save
168
+
169
+ expect(File.exist?(metadata.file_path)).to eq(true)
170
+ end
171
+
172
+ it 'writes the yaml to the file' do
173
+ metadata.save
174
+
175
+ expect(File.read(metadata.file_path)).to eq(<<YAML)
176
+ ---
177
+ favorite_color: blue
178
+ YAML
179
+ end
180
+ end
181
+
182
+ context 'when the metadata file already exists' do
183
+ before do
184
+ File.write(metadata.file_path, "---\nwho: knows")
185
+ end
186
+
187
+ it 'overwrites the file with the correct yaml' do
188
+ metadata.save
189
+
190
+ expect(File.read(metadata.file_path)).to eq(<<YAML)
191
+ ---
192
+ favorite_color: blue
193
+ YAML
194
+ end
195
+ end
196
+ end
197
+ end
92
198
  end
@@ -5,6 +5,7 @@ describe Everything::Piece do
5
5
  let(:piece) do
6
6
  described_class.new(given_full_path)
7
7
  end
8
+
8
9
  shared_context 'with content double' do
9
10
  let(:content_double) do
10
11
  instance_double(Everything::Piece::Content)
@@ -17,6 +18,18 @@ describe Everything::Piece do
17
18
  end
18
19
  end
19
20
 
21
+ shared_context 'with metadata double' do
22
+ let(:metadata_double) do
23
+ instance_double(Everything::Piece::Metadata)
24
+ end
25
+
26
+ before do
27
+ allow(Everything::Piece::Metadata)
28
+ .to receive(:new)
29
+ .and_return(metadata_double)
30
+ end
31
+ end
32
+
20
33
  describe '#body' do
21
34
  include_context 'with content double'
22
35
 
@@ -104,6 +117,20 @@ describe Everything::Piece do
104
117
  end
105
118
  end
106
119
 
120
+ describe '#raw_markdown=' do
121
+ include_context 'with content double'
122
+
123
+ it 'delegates to the content' do
124
+ allow(content_double).to receive(:raw_markdown=)
125
+
126
+ piece.raw_markdown=("# Test markdown")
127
+
128
+ expect(content_double)
129
+ .to have_received(:raw_markdown=)
130
+ .with("# Test markdown")
131
+ end
132
+ end
133
+
107
134
  describe '#title' do
108
135
  include_context 'with content double'
109
136
 
@@ -115,4 +142,54 @@ describe Everything::Piece do
115
142
  expect(content_double).to have_received(:title)
116
143
  end
117
144
  end
145
+
146
+ describe '#raw_yaml' do
147
+ include_context 'with metadata double'
148
+
149
+ it 'delegates to the metadata' do
150
+ allow(metadata_double).to receive(:raw_yaml)
151
+
152
+ piece.raw_yaml
153
+
154
+ expect(metadata_double).to have_received(:raw_yaml)
155
+ end
156
+ end
157
+
158
+ describe '#raw_yaml=' do
159
+ include_context 'with metadata double'
160
+
161
+ it 'delegates to the metadata' do
162
+ allow(metadata_double).to receive(:raw_yaml=)
163
+
164
+ piece.raw_yaml=("---\nanything: works")
165
+
166
+ expect(metadata_double)
167
+ .to have_received(:raw_yaml=)
168
+ .with("---\nanything: works")
169
+ end
170
+ end
171
+
172
+ describe '#save' do
173
+ include_context 'with content double'
174
+ include_context 'with metadata double'
175
+
176
+ before do
177
+ allow(content_double).to receive(:save)
178
+ allow(metadata_double).to receive(:save)
179
+ end
180
+
181
+ it 'calls save on the content' do
182
+ piece.save
183
+
184
+ expect(content_double)
185
+ .to have_received(:save)
186
+ end
187
+
188
+ it 'calls save on the metadata' do
189
+ piece.save
190
+
191
+ expect(metadata_double)
192
+ .to have_received(:save)
193
+ end
194
+ end
118
195
  end
@@ -1,3 +1,6 @@
1
+ require 'tmpdir'
2
+ require 'fileutils'
3
+
1
4
  RSpec.shared_context 'with tmp piece on disk' do
2
5
  let!(:tmp_piece_path) do
3
6
  Dir.mktmpdir
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everything-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Tolle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.4.5.1
135
+ rubygems_version: 2.5.1
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Library for working with your `everything` repository.