Class: TRMNLP::Paths
- Inherits:
-
Object
- Object
- TRMNLP::Paths
- Defined in:
- lib/trmnlp/paths.rb
Constant Summary collapse
- TRANSFORM_EXTENSIONS =
File extension → transform language identifier.
{ '.py' => 'python', '.rb' => 'ruby', '.php' => 'php', '.js' => 'node' }.freeze
Instance Attribute Summary collapse
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
Instance Method Summary collapse
- #app_config ⇒ Object
- #app_config_dir ⇒ Object
- #build_dir ⇒ Object
- #cache_dir ⇒ Object
- #create_build_dir ⇒ Object
- #create_cache_dir ⇒ Object
-
#expand(path) ⇒ Object
--- utilities ---.
-
#gem_dir ⇒ Object
--- trmnlp library ---.
-
#initialize(root_dir) ⇒ Paths
constructor
A new instance of Paths.
-
#oauth_tokens ⇒ Object
OAuth tokens are keyed per project root so working on two OAuth plugins does not clobber a shared token file.
- #plugin_config ⇒ Object
- #render_template ⇒ Object
- #shared_template ⇒ Object
-
#src_dir ⇒ Object
--- directories ---.
- #src_files ⇒ Object
- #template(view) ⇒ Object
- #templates_dir ⇒ Object
-
#transform_file ⇒ Object
Locate src/transform.py,rb,php,js.
-
#trmnlp_config ⇒ Object
--- files ---.
- #user_data ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(root_dir) ⇒ Paths
Returns a new instance of Paths.
10 11 12 13 |
# File 'lib/trmnlp/paths.rb', line 10 def initialize(root_dir) @root_dir = Pathname.new(root_dir) @xdg = XDG.new end |
Instance Attribute Details
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
8 9 10 |
# File 'lib/trmnlp/paths.rb', line 8 def root_dir @root_dir end |
Instance Method Details
#app_config ⇒ Object
45 |
# File 'lib/trmnlp/paths.rb', line 45 def app_config = app_config_dir.join('config.yml') |
#app_config_dir ⇒ Object
28 |
# File 'lib/trmnlp/paths.rb', line 28 def app_config_dir = xdg.config_home.join('trmnlp') |
#build_dir ⇒ Object
25 |
# File 'lib/trmnlp/paths.rb', line 25 def build_dir = root_dir.join('_build') |
#cache_dir ⇒ Object
30 |
# File 'lib/trmnlp/paths.rb', line 30 def cache_dir = xdg.cache_home.join('trmnl') |
#create_build_dir ⇒ Object
26 |
# File 'lib/trmnlp/paths.rb', line 26 def create_build_dir = build_dir.mkpath |
#create_cache_dir ⇒ Object
31 |
# File 'lib/trmnlp/paths.rb', line 31 def create_cache_dir = cache_dir.mkpath |
#expand(path) ⇒ Object
--- utilities ---
77 |
# File 'lib/trmnlp/paths.rb', line 77 def (path) = Pathname.new(path).(root_dir) |
#gem_dir ⇒ Object
--- trmnlp library ---
17 |
# File 'lib/trmnlp/paths.rb', line 17 def gem_dir = Pathname.new(__dir__).join('..', '..'). |
#oauth_tokens ⇒ Object
OAuth tokens are keyed per project root so working on two OAuth plugins does not clobber a shared token file.
51 |
# File 'lib/trmnlp/paths.rb', line 51 def oauth_tokens = cache_dir.join('oauth', "#{Digest::SHA256.hexdigest(root_dir.to_s)[0, 16]}.json") |
#plugin_config ⇒ Object
39 |
# File 'lib/trmnlp/paths.rb', line 39 def plugin_config = src_dir.join('settings.yml') |
#render_template ⇒ Object
53 |
# File 'lib/trmnlp/paths.rb', line 53 def render_template = Pathname.new(__dir__).join('..', '..', 'web', 'views', 'render_html.erb') |
#shared_template ⇒ Object
43 |
# File 'lib/trmnlp/paths.rb', line 43 def shared_template = template('shared') |
#src_dir ⇒ Object
--- directories ---
23 |
# File 'lib/trmnlp/paths.rb', line 23 def src_dir = root_dir.join('src') |
#src_files ⇒ Object
55 |
# File 'lib/trmnlp/paths.rb', line 55 def src_files = src_dir.glob('*').select(&:file?) |
#template(view) ⇒ Object
41 |
# File 'lib/trmnlp/paths.rb', line 41 def template(view) = src_dir.join("#{view}.liquid") |
#templates_dir ⇒ Object
19 |
# File 'lib/trmnlp/paths.rb', line 19 def templates_dir = gem_dir.join('templates') |
#transform_file ⇒ Object
Locate src/transform.py,rb,php,js. Returns [Pathname, language] or [nil, nil] if no transform file exists.
67 68 69 70 71 72 73 |
# File 'lib/trmnlp/paths.rb', line 67 def transform_file TRANSFORM_EXTENSIONS.each do |ext, language| candidate = src_dir.join("transform#{ext}") return [candidate, language] if candidate.exist? end [nil, nil] end |
#trmnlp_config ⇒ Object
--- files ---
37 |
# File 'lib/trmnlp/paths.rb', line 37 def trmnlp_config = root_dir.join('.trmnlp.yml') |
#user_data ⇒ Object
47 |
# File 'lib/trmnlp/paths.rb', line 47 def user_data = cache_dir.join('data.json') |
#valid? ⇒ Boolean
33 |
# File 'lib/trmnlp/paths.rb', line 33 def valid? = trmnlp_config.exist? |