Class: Specify::BranchParser
- Inherits:
-
Object
- Object
- Specify::BranchParser
- Defined in:
- lib/specify/branch_parser.rb
Overview
BranchParsers parse the information required to set a Specify::Service::ViewLoade#target for upload of .views.xml files from a string that follows the convention Database/CollectionName/level.
This can be the name of a git branch of a repository residing in a folder denoting the hostname.
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
The name of the collection.
-
#config ⇒ Object
readonly
A Specify::Configuration::HostConfig.
-
#database ⇒ Object
readonly
The name of a Specify database.
-
#host ⇒ Object
readonly
The name of a MySQL/MariaDB host.
-
#user ⇒ Object
readonly
The name of a Specify user (an existing Specify::Model::User#name).
Class Method Summary collapse
-
.current_branch(config) ⇒ Object
Creates a new instance of BranchParser for the current Git HEAD.
Instance Method Summary collapse
-
#initialize(view_file_path, name, config = nil) ⇒ BranchParser
constructor
Returns a new BranchParser with
view_file_pathandname. -
#level ⇒ Object
Returns the level to a Specify::Service::ViewLoader will upload.
-
#to_h ⇒ Object
Returns the attributes of
selfas a hash.
Constructor Details
#initialize(view_file_path, name, config = nil) ⇒ BranchParser
Returns a new BranchParser with view_file_path and name.
view_file_path: the directory path of the .vews.xml file (that path must be mapped to a host name in the config).
name: a String with a branch name conforming to the convention Database/CollectionName/level.
config: a database configuration YAML file.
50 51 52 53 54 55 56 |
# File 'lib/specify/branch_parser.rb', line 50 def initialize(view_file_path, name, config = nil) @config = Configuration::HostConfig.new(config) @database, collection, @level, @user = *name.split('/') raise ArgumentError, BRANCH_ERROR + name unless collection && level @host = @config.resolve_host view_file_path @collection = normalize_name collection end |
Instance Attribute Details
#collection ⇒ Object (readonly)
The name of the collection. Must be an existing Specify::Model::Collection#name.
13 14 15 |
# File 'lib/specify/branch_parser.rb', line 13 def collection @collection end |
#config ⇒ Object (readonly)
A Specify::Configuration::HostConfig.
16 17 18 |
# File 'lib/specify/branch_parser.rb', line 16 def config @config end |
#database ⇒ Object (readonly)
The name of a Specify database.
19 20 21 |
# File 'lib/specify/branch_parser.rb', line 19 def database @database end |
#host ⇒ Object (readonly)
The name of a MySQL/MariaDB host.
22 23 24 |
# File 'lib/specify/branch_parser.rb', line 22 def host @host end |
#user ⇒ Object (readonly)
The name of a Specify user (an existing Specify::Model::User#name).
25 26 27 |
# File 'lib/specify/branch_parser.rb', line 25 def user @user end |
Class Method Details
.current_branch(config) ⇒ Object
Creates a new instance of BranchParser for the current Git HEAD.
config: a database configuration YAML file.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/specify/branch_parser.rb', line 30 def self.current_branch(config) stdout_str, stderr_str, status = Open3.capture3(GIT_CURRENT_BRANCH) unless status.exitstatus.zero? STDERR.puts "There was an error running #{GIT_CURRENT_BRANCH}" STDERR.puts stderr_str exit 1 end branch = stdout_str.chomp new(Dir.pwd, branch, config) end |
Instance Method Details
#level ⇒ Object
Returns the level to a Specify::Service::ViewLoader will upload.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/specify/branch_parser.rb', line 67 def level case @level when 'collection', 'discipline' @level.to_sym when 'user' { user: @user } else { user_type: @level.downcase.to_sym } end end |
#to_h ⇒ Object
Returns the attributes of self as a hash.
59 60 61 62 63 64 |
# File 'lib/specify/branch_parser.rb', line 59 def to_h { host: host, database: database, collection: collection, level: level } end |