Class: BoPeep::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/bopeep.rb

Defined Under Namespace

Classes: Interpolations, Template

Constant Summary collapse

REMOTE_DIRECTORY =
Pathname.new("$HOME").join("bopeep", "scripts")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script_name, context, defaults_path: nil) ⇒ Script

Returns a new instance of Script.



2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
# File 'lib/bopeep.rb', line 2311

def initialize(script_name, context, defaults_path: nil)
  command_name = Command::Name.from_relative_script_path(script_name)
  @name = command_name.script
  @context = context

  local_path = Pathname.new(@name)

  # FIXME: search parent directories for a defaults script
  defaults_path ||= File.join(local_path.dirname, "_defaults")
  @defaults = Template.find(defaults_path, fail_if_missing: false)

  @template = Template.find(local_path.to_s)

  @remote_path = REMOTE_DIRECTORY.join(local_path)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



2307
2308
2309
# File 'lib/bopeep.rb', line 2307

def content
  @content
end

#nameObject (readonly)

Returns the value of attribute name.



2308
2309
2310
# File 'lib/bopeep.rb', line 2308

def name
  @name
end

#remote_pathObject (readonly)

Returns the value of attribute remote_path.



2309
2310
2311
# File 'lib/bopeep.rb', line 2309

def remote_path
  @remote_path
end

Instance Method Details

#install_directoryObject



2335
2336
2337
# File 'lib/bopeep.rb', line 2335

def install_directory
  @remote_path.dirname
end

#install_pathObject



2339
2340
2341
# File 'lib/bopeep.rb', line 2339

def install_path
  @remote_path.relative_path_from Pathname.new("$HOME")
end

#to_sObject



2343
2344
2345
# File 'lib/bopeep.rb', line 2343

def to_s
  name.dup
end