right_now 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a566156485512651cffed05ab55379f0cab3b025fdc07f209341eea69dd53352
4
- data.tar.gz: c7699767b0dd24e0e119ea29ccf0fa2f2d94669330e7f0c146fa7c02b6c0f1f2
3
+ metadata.gz: 9672f2dfe1aee87cf20bcbc37973cd3be192e20badcb783a10482a0adca83e9e
4
+ data.tar.gz: cc242d32c118d9799317c2e22f073457a57726173210a540807c2c0e0c40ee5f
5
5
  SHA512:
6
- metadata.gz: a17606397b14a73843e9942a339646b8d2698e405a69c846f5ede2b0a92c523311d8b053a3b55e2dd6a60a560908dfcf70ea06bc0bb0d9b0b43757eada5e8b9a
7
- data.tar.gz: 53e202722d68b59fa46088fcce2395dcda200a909135bae509dfc7af8886204dd1b3d0d00424cc0e877f8b0ed41f573a8c1bb6715e602a74e0dc395cab4d866e
6
+ metadata.gz: eed74c0185cd60875e0735f480b213ab659cce12c4017053131fc97a60bd35e66e6991989830ea9ec7851bb67472eb7bea2d21a9dcf7af044ac6b74ee86edb9d
7
+ data.tar.gz: 98d28b5e625aa7d450b27ac82a7c1915d110baa91d465aedb0ec90cc44bde45694dd52a974a931393e2267f050dc0bd5b290494402b2f1c607a8f10c4475a68f
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/right_now.svg)](https://badge.fury.io/rb/right_now)
2
+
1
3
  # rightnow
2
4
 
3
5
  Rails-aware code resolver.
data/exe/my_gem ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/my_gem"
5
+
6
+ exit(MyGem::CLI.start(ARGV) || 0)
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/notifications"
4
+ require "active_support/cache"
5
+ require "fileutils"
6
+
7
+ module MyGem
8
+ module Cache
9
+ module_function
10
+
11
+ def build(paths)
12
+ FileUtils.mkdir_p(paths.cache_dir)
13
+ ActiveSupport::Cache::FileStore.new(paths.cache_dir)
14
+ end
15
+ end
16
+ end
data/lib/my_gem/cli.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ module MyGem
6
+ class CLI < Thor
7
+ class << self
8
+ def exit_on_failure?
9
+ true
10
+ end
11
+ end
12
+
13
+ map "run" => "execute"
14
+
15
+ desc "execute TASK_NAME [TASK_ARGS...]", "Run a Rake task through the CLI"
16
+ def execute(task_name, *task_args)
17
+ Runner.new.call(task_name, *task_args)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module MyGem
6
+ class Context
7
+ class << self
8
+ def current
9
+ Thread.current[:my_gem_context]
10
+ end
11
+
12
+ def current=(context)
13
+ Thread.current[:my_gem_context] = context
14
+ end
15
+
16
+ def with(context)
17
+ previous = current
18
+ self.current = context
19
+ yield context
20
+ ensure
21
+ self.current = previous
22
+ end
23
+
24
+ def build(env: ENV)
25
+ new(env: env.to_h, paths: XDG.paths(env: env))
26
+ end
27
+ end
28
+
29
+ attr_reader :env, :paths, :config, :cache
30
+
31
+ def initialize(env:, paths:)
32
+ @env = env.dup.freeze
33
+ @paths = paths
34
+ @config = load_config
35
+ @cache = MyGem::Cache.build(paths)
36
+ end
37
+
38
+ def config_path
39
+ paths.config_file
40
+ end
41
+
42
+ def data_path(*segments)
43
+ File.join(paths.data_dir, *segments)
44
+ end
45
+
46
+ private
47
+
48
+ def load_config
49
+ return {} unless File.exist?(paths.config_file)
50
+
51
+ config = YAML.safe_load(File.read(paths.config_file), aliases: true)
52
+ config.is_a?(Hash) ? config : {}
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+
5
+ module MyGem
6
+ class Runner
7
+ DEFAULT_NAMESPACE = "my_gem"
8
+
9
+ def initialize(context: Context.build)
10
+ @context = context
11
+ TaskLoader.load!
12
+ end
13
+
14
+ def call(task_name, *task_args)
15
+ resolved_task_name = resolve_task_name(task_name)
16
+
17
+ Context.with(context) do
18
+ reenable_tasks
19
+ Rake::Task[resolved_task_name].invoke(context, *task_args)
20
+ end
21
+
22
+ 0
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :context
28
+
29
+ def resolve_task_name(task_name)
30
+ task_name = task_name.to_s
31
+ return task_name if task_name.include?(":")
32
+ return task_name if Rake::Task.task_defined?(task_name)
33
+
34
+ "#{DEFAULT_NAMESPACE}:#{task_name}"
35
+ end
36
+
37
+ def reenable_tasks
38
+ Rake::Task.tasks.each(&:reenable)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyGem
4
+ class TaskLoader
5
+ def self.load!(task_dir: default_task_dir)
6
+ @loaded ||= false
7
+ return if @loaded
8
+
9
+ Dir.glob(File.join(task_dir, "*.rake")).sort.each do |task_file|
10
+ load task_file
11
+ end
12
+
13
+ @loaded = true
14
+ end
15
+
16
+ def self.default_task_dir
17
+ File.expand_path("../../tasks", __dir__)
18
+ end
19
+ private_class_method :default_task_dir
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyGem
4
+ VERSION = "0.1.0"
5
+ end
data/lib/my_gem/xdg.rb ADDED
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyGem
4
+ module XDG
5
+ Paths = Struct.new(
6
+ :config_home,
7
+ :cache_home,
8
+ :data_home,
9
+ :app_dir,
10
+ :config_file,
11
+ :cache_dir,
12
+ :data_dir,
13
+ keyword_init: true
14
+ )
15
+
16
+ module_function
17
+
18
+ def paths(env: ENV)
19
+ config_home = home_path(env, "XDG_CONFIG_HOME", ".config")
20
+ cache_home = home_path(env, "XDG_CACHE_HOME", ".cache")
21
+ data_home = home_path(env, "XDG_DATA_HOME", ".local/share")
22
+ app_dir = File.join(config_home, "my_gem")
23
+
24
+ Paths.new(
25
+ config_home: config_home,
26
+ cache_home: cache_home,
27
+ data_home: data_home,
28
+ app_dir: app_dir,
29
+ config_file: File.join(app_dir, "config.yml"),
30
+ cache_dir: File.join(cache_home, "my_gem"),
31
+ data_dir: File.join(data_home, "my_gem")
32
+ )
33
+ end
34
+
35
+ def config_file(env: ENV)
36
+ paths(env: env).config_file
37
+ end
38
+
39
+ def cache_dir(env: ENV)
40
+ paths(env: env).cache_dir
41
+ end
42
+
43
+ def data_dir(env: ENV)
44
+ paths(env: env).data_dir
45
+ end
46
+
47
+ def app_dir(env: ENV)
48
+ paths(env: env).app_dir
49
+ end
50
+
51
+ def home_path(env, key, fallback)
52
+ value = env[key]
53
+ return value unless value.nil? || value.empty?
54
+
55
+ File.join(Dir.home, fallback)
56
+ end
57
+ private_class_method :home_path
58
+ end
59
+ end
data/lib/my_gem.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "my_gem/version"
4
+ require_relative "my_gem/xdg"
5
+ require_relative "my_gem/cache"
6
+ require_relative "my_gem/context"
7
+ require_relative "my_gem/task_loader"
8
+ require_relative "my_gem/runner"
9
+ require_relative "my_gem/cli"
data/lib/rightnow/cli.rb CHANGED
@@ -6,6 +6,11 @@ require "shellwords"
6
6
  module RightNow
7
7
  class CLI
8
8
  def self.start(argv = ARGV)
9
+ if version_flag?(argv)
10
+ puts RightNow::VERSION
11
+ return 0
12
+ end
13
+
9
14
  new(argv).run
10
15
  end
11
16
 
@@ -43,6 +48,10 @@ module RightNow
43
48
 
44
49
  attr_reader :query, :resolver
45
50
 
51
+ def self.version_flag?(argv)
52
+ argv.include?("--version") || argv.include?("-v")
53
+ end
54
+
46
55
  def handle_empty_query
47
56
  if query.json
48
57
  puts JSON.pretty_generate([])
@@ -1,3 +1,3 @@
1
1
  module RightNow
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/right_now.gemspec CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |spec|
5
5
  spec.version = RightNow::VERSION
6
6
  spec.summary = "Rails-aware file resolver"
7
7
  spec.description = "rn resolves a user query to the most likely existing file in a Rails project."
8
- spec.authors = ["SEAHAL"]
8
+ spec.authors = ["SEAHALGEM"]
9
9
  spec.homepage = "https://github.com/seahal/right_now"
10
10
  spec.license = "MIT"
11
11
  spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_now
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - SEAHAL
7
+ - SEAHALGEM
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
@@ -19,8 +19,17 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - LICENSE
21
21
  - README.md
22
+ - exe/my_gem
22
23
  - exe/rn
23
24
  - exe/rni
25
+ - lib/my_gem.rb
26
+ - lib/my_gem/cache.rb
27
+ - lib/my_gem/cli.rb
28
+ - lib/my_gem/context.rb
29
+ - lib/my_gem/runner.rb
30
+ - lib/my_gem/task_loader.rb
31
+ - lib/my_gem/version.rb
32
+ - lib/my_gem/xdg.rb
24
33
  - lib/rightnow.rb
25
34
  - lib/rightnow/cli.rb
26
35
  - lib/rightnow/query.rb