everything-core 0.0.8 → 0.0.13

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
- SHA1:
3
- metadata.gz: 496abd62729fa5456b73ba7325a331e40ce6ba32
4
- data.tar.gz: ba227e14bc31850f0e714c44121cf1a44d82b3f6
2
+ SHA256:
3
+ metadata.gz: bae9b9a7c10aa14d43dbf312ba25c0a2dec325000f8bc75bda0150aefc00fbd1
4
+ data.tar.gz: d9ac581faf22de423daf8fc3cd990f9b81bad9679e03439e701cdaa3d4515f67
5
5
  SHA512:
6
- metadata.gz: 2c5a438383b336fceece599184d79f2a3fe4d131ff8ef9d50397dd92710c6d86856c94e03d5263e8e975e608cbb1330c80e768565a510d17fb213587e509155f
7
- data.tar.gz: 7b05054d7200b1f55e9d1d2562647113774a5a4ee1bd83efd03801b6bf4495fe89ca919a9121a7fe3e7e2e9cc5e9eaa05e068768f70a3089c3b6192bd9f33d3d
6
+ metadata.gz: 5bdd8c94ac5d55fcbdc6b075a4e22a8343f67e8e55ab2391d92161896e413387612ba855c0287091129abdd2b39d75224dcef4512b6345d5a75640bd2993fcf8
7
+ data.tar.gz: 2bef7eba4b4ce2498df87d852c675de6b4a532a8ac34c4f2546721ba917a501169311068a893a403d15471ae99c4781d649db549794c75842e848984aa238fcf
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ cache: bundler
2
3
  rvm:
3
- - 2.2.3
4
- before_install: gem install bundler -v 1.11.2
4
+ - 2.7.1
5
+ before_install: gem install bundler
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.13
4
+
5
+ - **BREAKING CHANGE**: Make Everything.path an instance of Pathname
6
+ - Add #absolute_dir, #absolute_path, #dir, #file_name, #path to Everything::Piece
7
+ - Memoize Everything::Piece#name
8
+ - Add #absolute_dir, #absolute_path, #dir, #path to Everything::Piece::Content
9
+ - Add #absolute_dir, #absolute_path, #dir, #path to Everything::Piece::Metadata
10
+ - Deprecate #file_path on Everything::Piece::Content and Everything::Piece::Metadata
11
+ - Use Pathname convenience methods when working with files and paths internally
12
+
13
+ ## 0.0.12
14
+
15
+ - Add an Everything logger
16
+ - Add a Debug logger
17
+ - Add a Verbose logger
18
+ - Add an Error logger
19
+ - Add a LogIt module to make logging easy
20
+
21
+ ## 0.0.11
22
+
23
+ - Update changelog for 0.0.10 changes
24
+ - Update travis settings to use ruby 2.7.1 and bundler 2
25
+
26
+ ## 0.0.10
27
+
28
+ - Upgrade to Bundler v2
29
+
30
+ ## 0.0.9
31
+
32
+ - Make Content#file_name a public method
33
+
3
34
  ## 0.0.8
4
35
 
5
36
  - Require modules which had been used but not explicitly required
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
+ ruby '2.7.1'
2
3
 
3
4
  # The gem's dependencies are specified in `everything-core.gemspec`.
4
5
  gemspec
data/README.md CHANGED
@@ -22,7 +22,7 @@ Must define these environment variables:
22
22
  Add this line to your application's Gemfile:
23
23
 
24
24
  ```ruby
25
- gem install everything-core
25
+ gem 'everything-core', require: 'everything'
26
26
  ```
27
27
 
28
28
  And then execute:
@@ -34,6 +34,24 @@ Or install it yourself as:
34
34
  $ gem install everything-core
35
35
 
36
36
 
37
+ ## Requiring
38
+
39
+ You can require it yourself in your code:
40
+
41
+ ```
42
+ require 'everything'
43
+ ```
44
+
45
+ Or, if you use Bundler and list the gem in your Gemfile, you can require all the
46
+ gems from your Gemfile:
47
+
48
+ ```ruby
49
+ require 'rubygems'
50
+ require 'bundler/setup'
51
+ Bundler.require(:default)
52
+ ```
53
+
54
+
37
55
  ## Usage
38
56
 
39
57
  This assumes you have a `EVERYTHING_PATH` environment variable either set in
@@ -42,7 +60,7 @@ your shell or in dotenv's `.env` file.
42
60
  For example, let's assume you have the following folder and file under your
43
61
  everything path
44
62
 
45
- ```
63
+ ```ruby
46
64
  your-piece-here/index.md
47
65
 
48
66
  # Your Piece Here
@@ -54,10 +72,10 @@ The rest of the body of your file...
54
72
  To use the piece from IRB, you could do the following to get the piece's title
55
73
  and content.
56
74
 
57
- ```
75
+ ```ruby
58
76
  require 'everything'
59
77
 
60
- piece_path = File.join(Everything.path, 'your-piece-here')
78
+ piece_path = Everything.path.join('your-piece-here')
61
79
  piece = Everything::Piece.new(piece_path)
62
80
 
63
81
  piece.name # => 'your-piece-here'
@@ -67,8 +85,11 @@ piece['categories'] # Returns the value for the `categories` metadata key
67
85
  piece.public? # Convience method to return the value for the boolean `public` metadata key
68
86
  piece.content # Return an instance of the piece's content
69
87
  piece.metadata # Return an instance of the piece's metadata
88
+ ```
70
89
 
71
- # You can also edit a piece's content and metadata
90
+ You can also edit a piece's content and metadata
91
+
92
+ ```ruby
72
93
  piece.raw_markdown = some_markdown # Sets the raw_markdown on the piece's content
73
94
  piece.raw_yaml = some_yaml # Sets the raw_yaml on the piece's metadata
74
95
  piece.save # Save the piece's content and metadata to disk
@@ -81,10 +102,22 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
81
102
  `rake spec` to run the tests. You can also run `bin/console` for an interactive
82
103
  prompt that will allow you to experiment.
83
104
 
84
- To install this gem onto your local machine, run `bundle exec rake install`. To
85
- release a new version, update the version number in `version.rb`, and then run
86
- `bundle exec rake release`, which will create a git tag for the version, push
87
- git commits and tags, and push the `.gem` file to
105
+ To install this gem onto your local machine, run `rake install`.
106
+
107
+ To release a new version,
108
+ - check out a new branch
109
+ - make your code changes
110
+ - update the version number in `lib/everything/version.rb`
111
+ - update the `CHANGELOG.md` with what changed.
112
+ - commit your code changes
113
+ - push new branch to github with `git push -u origin HEAD`
114
+ - create a new PR for this
115
+ - merge in PR to master
116
+ - locally, check out master again
117
+ - git pull
118
+ - create a build with `rake build`
119
+ - run `rake release`, which will create a git tag for the version,
120
+ push git commits and tags, and push the `.gem` file to
88
121
  [rubygems.org](https://rubygems.org).
89
122
 
90
123
 
@@ -11,4 +11,4 @@ require "everything"
11
11
  # Pry.start
12
12
 
13
13
  require "irb"
14
- IRB.start
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -4,5 +4,3 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,7 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'everything/version'
1
+ require_relative 'lib/everything/version'
5
2
 
6
3
  Gem::Specification.new do |spec|
7
4
  spec.name = 'everything-core'
@@ -12,17 +9,27 @@ Gem::Specification.new do |spec|
12
9
  spec.description = %q{Gives you access to pieces within your everything repo.}
13
10
  spec.homepage = 'https://github.com/kyletolle/everything-core'
14
11
  spec.license = 'MIT'
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.1")
15
13
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ['lib']
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
20
25
 
21
26
  spec.add_runtime_dependency 'dotenv', '~> 2.1'
22
- spec.add_runtime_dependency 'fastenv', '= 0.0.2'
27
+ spec.add_runtime_dependency 'fastenv', '= 0.0.3'
23
28
 
24
- spec.add_development_dependency 'bundler', '~> 1.11'
25
- spec.add_development_dependency 'rake', '~> 10.5'
26
- spec.add_development_dependency 'rspec', '~> 3.4'
29
+ spec.add_development_dependency 'bundler', '~> 2.1'
30
+ spec.add_development_dependency 'rake', '>= 13.0.1'
31
+ spec.add_development_dependency 'rspec', '~> 3.9'
32
+ spec.add_development_dependency 'timecop', '~> 0.9'
33
+ spec.add_development_dependency 'fakefs', '~> 1.2.2'
27
34
  end
28
35
 
@@ -1,13 +1,15 @@
1
1
  require 'dotenv'
2
2
  Dotenv.load
3
3
 
4
+ require 'pathname'
4
5
  require 'fastenv'
5
6
  require 'everything/version'
7
+ require 'everything/logger'
6
8
  require 'everything/piece'
7
9
 
8
10
  module Everything
9
11
  def self.path
10
- Fastenv.everything_path
12
+ Pathname.new(Fastenv.everything_path)
11
13
  end
12
14
  end
13
15
 
@@ -0,0 +1,25 @@
1
+ require 'logger'
2
+ require_relative 'logger/base'
3
+ require_relative 'logger/debug'
4
+ require_relative 'logger/error'
5
+ require_relative 'logger/verbose'
6
+ require_relative 'logger/log_it'
7
+
8
+ module Everything
9
+ def self.logger
10
+ @logger ||= default_logger
11
+ end
12
+
13
+ def self.logger=(value)
14
+ @logger = value
15
+ end
16
+
17
+ def self.default_logger
18
+ ::Logger.new(
19
+ $stdout,
20
+ level: ::Logger::ERROR,
21
+ progname: self.class.to_s
22
+ )
23
+ end
24
+ end
25
+
@@ -0,0 +1,17 @@
1
+ module Everything
2
+ class Logger
3
+ class Base < ::Logger
4
+ DATETIME_PROGNAME_MESSAGE_FORMATTER =
5
+ proc { |severity, datetime, progname, msg|
6
+ iso8601_time = datetime.utc.iso8601
7
+ "#{iso8601_time}: #{progname}: #{msg}\n"
8
+ }
9
+
10
+ def initialize(logdev, progname: nil)
11
+ super
12
+ self.formatter = DATETIME_PROGNAME_MESSAGE_FORMATTER
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,7 @@
1
+ module Everything
2
+ class Logger
3
+ class Debug < Everything::Logger::Base
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,11 @@
1
+ module Everything
2
+ class Logger
3
+ class Error < Everything::Logger::Base
4
+ def initialize(logdev, progname: nil)
5
+ super
6
+ self.level = ::Logger::ERROR
7
+ end
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,24 @@
1
+ module Everything
2
+ class Logger
3
+ module LogIt
4
+ def debug_it(message)
5
+ Everything.logger.debug(class_name) { message }
6
+ end
7
+
8
+ def error_it(message)
9
+ Everything.logger.error(class_name) { message }
10
+ end
11
+
12
+ def info_it(message)
13
+ Everything.logger.info(class_name) { message }
14
+ end
15
+
16
+ private
17
+
18
+ def class_name
19
+ self.class.to_s
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,11 @@
1
+ module Everything
2
+ class Logger
3
+ class Verbose < Everything::Logger::Base
4
+ def initialize(logdev, progname: nil)
5
+ super
6
+ self.level = ::Logger::INFO
7
+ end
8
+ end
9
+ end
10
+ end
11
+
@@ -14,7 +14,7 @@ module Everything
14
14
  @content ||= Content.new(full_path)
15
15
  end
16
16
 
17
- def_delegators :content, :body, :raw_markdown, :raw_markdown=, :title
17
+ def_delegators :content, :absolute_dir, :absolute_path, :body, :dir, :file_name, :path, :raw_markdown, :raw_markdown=, :title
18
18
 
19
19
  def metadata
20
20
  @metadata ||= Metadata.new(full_path)
@@ -27,7 +27,7 @@ module Everything
27
27
  def_delegators :metadata, :raw_yaml, :raw_yaml=
28
28
 
29
29
  def name
30
- File.basename(full_path)
30
+ @name ||= File.basename(full_path)
31
31
  end
32
32
 
33
33
  def save
@@ -7,7 +7,26 @@ module Everything
7
7
  @piece_path = piece_path
8
8
  end
9
9
 
10
+ def absolute_dir
11
+ @absolute_dir ||= Everything.path.join(dir)
12
+ end
13
+
14
+ def absolute_path
15
+ @absolute_path ||= absolute_dir.join(file_name)
16
+ end
17
+
18
+ def dir
19
+ @dir ||= calculated_dir
20
+ end
21
+
22
+ def file_name
23
+ 'index.md'
24
+ end
25
+
10
26
  def file_path
27
+ # TODO: Could try a deprecation approach like http://seejohncode.com/2012/01/09/deprecating-methods-in-ruby/
28
+ deprecation_message = "Piece Content's #file_path is deprecated and will be removed soon. Use #absolute_path instead."
29
+ warn deprecation_message
11
30
  @file_path ||= File.join(piece_path, file_name)
12
31
  end
13
32
 
@@ -19,8 +38,12 @@ module Everything
19
38
  partitioned_text.last
20
39
  end
21
40
 
41
+ def path
42
+ @path ||= dir.join(file_name)
43
+ end
44
+
22
45
  def raw_markdown
23
- @raw_markdown ||= File.read(file_path)
46
+ @raw_markdown ||= absolute_path.read
24
47
  end
25
48
 
26
49
  def raw_markdown=(value)
@@ -30,19 +53,21 @@ module Everything
30
53
  def save
31
54
  FileUtils.mkdir_p(piece_path)
32
55
 
33
- File.write(file_path, @raw_markdown)
56
+ absolute_path.write(@raw_markdown)
34
57
  end
35
58
 
36
59
  private
37
60
  attr_reader :piece_path
38
61
 
39
- def file_name
40
- 'index.md'
41
- end
42
-
43
62
  def partitioned_text
44
63
  @partitioned_text ||= raw_markdown.partition("\n\n")
45
64
  end
65
+
66
+ def calculated_dir
67
+ full_pathname = Pathname.new(piece_path)
68
+ _relative_pathname = full_pathname.relative_path_from(Everything.path)
69
+ end
46
70
  end
47
71
  end
48
72
  end
73
+
@@ -6,16 +6,40 @@ module Everything
6
6
  class Metadata
7
7
  extend Forwardable
8
8
 
9
+ # TODO: Need to add some ways in here to save the metadata file once it's
10
+ # been edited.
11
+ # TODO: Also add a #to_s or #inspect methods to render the raw_yaml
12
+ # TODO: Also add a #[]= here that delegates to raw_yaml as well.
13
+
9
14
  def initialize(piece_path)
10
15
  @piece_path = piece_path
11
16
  end
12
17
 
18
+ def absolute_dir
19
+ @absolute_dir ||= Everything.path.join(dir)
20
+ end
21
+
22
+ def absolute_path
23
+ @absolute_path ||= absolute_dir.join(file_name)
24
+ end
25
+
26
+ def dir
27
+ @dir ||= calculated_dir
28
+ end
29
+
13
30
  def file_path
31
+ # TODO: Could try a deprecation approach like http://seejohncode.com/2012/01/09/deprecating-methods-in-ruby/
32
+ deprecation_message = "Piece Metadata's #file_path is deprecated and will be removed soon. Use #absolute_path instead."
33
+ warn deprecation_message
14
34
  @file_path ||= File.join(piece_path, file_name)
15
35
  end
16
36
 
37
+ def path
38
+ @path ||= dir.join(file_name)
39
+ end
40
+
17
41
  def raw_yaml
18
- @raw_yaml ||= YAML.load_file(file_path)
42
+ @raw_yaml ||= YAML.load_file(absolute_path)
19
43
  end
20
44
 
21
45
  def raw_yaml=(value)
@@ -25,7 +49,7 @@ module Everything
25
49
  def save
26
50
  FileUtils.mkdir_p(piece_path)
27
51
 
28
- File.write(file_path, @raw_yaml)
52
+ absolute_path.write(@raw_yaml)
29
53
  end
30
54
 
31
55
  def_delegators :raw_yaml, :[]
@@ -36,6 +60,11 @@ module Everything
36
60
  def file_name
37
61
  'index.yaml'
38
62
  end
63
+
64
+ def calculated_dir
65
+ full_pathname = Pathname.new(piece_path)
66
+ _relative_pathname = full_pathname.relative_path_from(Everything.path)
67
+ end
39
68
  end
40
69
  end
41
70
  end