Class: Rtasklib::Taskrc
- Inherits:
-
Object
- Object
- Rtasklib::Taskrc
- Defined in:
- lib/rtasklib/taskrc.rb
Overview
A class that wraps a single Virtus domain model with a number of creation and manipulation methods
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#get_model_attr_value(attr) ⇒ Object
Gets the current value of a given attr in the config object.
-
#initialize(rc, type = :array) ⇒ Taskrc
constructor
Generate a dynamic Virtus model, with the attributes defined by the input.
-
#model_to_rc ⇒ Array<String>
Serialize all attrs of the model to the taskrc format.
-
#model_to_s ⇒ String
Serialize all attrs model back to the taskrc format and reduce them to a string that can be passed directly to Execute.
-
#part_of_model_to_rc(*attrs) ⇒ Array<String>
Serialize the given attrs model back to the taskrc format.
-
#part_of_model_to_s(*attrs) ⇒ String
Serialize the given attrs model back to the taskrc format and reduce them to a string that can be passed directly to Execute.
-
#set_model_attr_value(attr, value) ⇒ undefined
Modifies the value of a given attr in the config object.
Constructor Details
#initialize(rc, type = :array) ⇒ Taskrc
Generate a dynamic Virtus model, with the attributes defined by the input
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rtasklib/taskrc.rb', line 18 def initialize rc, type=:array @config = Models::TaskrcModel.new().extend(Virtus.model) case type when :array mappable_to_model(rc) when :hash hash_to_model(rc) when :path if path_exist?(rc) mappable_to_model(File.open(rc)) else raise RuntimeError.new("rc path does not exist on the file system") end else raise TypeError.new("no implicit conversion to Hash, String, or Pathname") end end |
Instance Attribute Details
#config ⇒ Object
10 11 12 |
# File 'lib/rtasklib/taskrc.rb', line 10 def config @config end |
Instance Method Details
#get_model_attr_value(attr) ⇒ Object
Gets the current value of a given attr in the config object
162 163 164 |
# File 'lib/rtasklib/taskrc.rb', line 162 def get_model_attr_value attr config.send("#{attr.to_s}".to_sym) end |
#model_to_rc ⇒ Array<String>
Serialize all attrs of the model to the taskrc format
101 102 103 |
# File 'lib/rtasklib/taskrc.rb', line 101 def model_to_rc part_of_model_to_rc(*config.attributes.keys) end |
#model_to_s ⇒ String
Serialize all attrs model back to the taskrc format and reduce them to a string that can be passed directly to Execute
120 121 122 |
# File 'lib/rtasklib/taskrc.rb', line 120 def model_to_s model_to_rc().join(" ") end |
#part_of_model_to_rc(*attrs) ⇒ Array<String>
Serialize the given attrs model back to the taskrc format
89 90 91 92 93 94 95 |
# File 'lib/rtasklib/taskrc.rb', line 89 def part_of_model_to_rc *attrs attrs.map do |attr| value = get_model_attr_value attr hash_attr = get_rc_attr_from_hash attr.to_s attr = "rc.#{hash_attr}=#{value}" end end |
#part_of_model_to_s(*attrs) ⇒ String
Serialize the given attrs model back to the taskrc format and reduce them to a string that can be passed directly to Execute
111 112 113 |
# File 'lib/rtasklib/taskrc.rb', line 111 def part_of_model_to_s *attrs part_of_model_to_rc(*attrs).join(" ") end |
#set_model_attr_value(attr, value) ⇒ undefined
Modifies the value of a given attr in the config object
153 154 155 |
# File 'lib/rtasklib/taskrc.rb', line 153 def set_model_attr_value attr, value config.send("#{attr}=".to_sym, value) end |