Class: MrMurano::SyncUpDown::Item
- Inherits:
-
Object
- Object
- MrMurano::SyncUpDown::Item
- Includes:
- Comparable
- Defined in:
- lib/MrMurano/SyncUpDown-Item.rb
Overview
This is one item that can be synced.
Instance Attribute Summary collapse
-
#diff ⇒ String
If requested, the diff output.
-
#dup_count ⇒ Integer
Positive if multiple conflicting files found for same item.
-
#header ⇒ String
The (optional) #ITEM <method> <path> :script header.
-
#id ⇒ Object
Read-only platform UUID, used to uniquely identify items.
-
#line_beg ⇒ Integer
The line in #local_path where this #script starts.
-
#line_end ⇒ Integer
The line in #local_path where this #script ends.
-
#local_path ⇒ Pathname
Where this item lives.
-
#name ⇒ String
The name of this item.
-
#script ⇒ String
The Lua code for this item.
-
#selected ⇒ Boolean
When filtering, did this item pass.
-
#synckey ⇒ String
The constructed name used to match local items to remote items.
-
#synctype ⇒ String
The syncable type.
-
#updated_at ⇒ String
The updated_at time from the server is used to detect changes.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#[](key) ⇒ Object
Get attribute as if this was a Hash.
-
#[]=(key, value) ⇒ Object
Set attribute as if this was a Hash.
-
#delete(key) ⇒ Object
Delete a key.
-
#each_pair {|key, value| ... } ⇒ Item
Calls block once for each non-nil key.
-
#initialize(hash = {}) ⇒ Item
constructor
Initialize a new Item with a few, or all, attributes.
- #location_friendly(show_type: false, full_path: false) ⇒ Object
- #location_path_and_line(full_path: false) ⇒ Object
-
#merge(item) ⇒ Item
A new Item containing our plus items.
-
#merge!(item) ⇒ Item
Adds the contents of item to self.
-
#reject {|key, value| ... } ⇒ Item
A new Item with keys deleted where block is true.
-
#reject! {|key, value| ... } ⇒ Item
Delete items in self that block returns true.
-
#reject_ephemeral ⇒ Object
Scrub local, non-BizAPI/Pegasus attrs from Item (before uploading).
-
#to_h ⇒ Hash{Symbol=>Object}
A hash that represents this Item.
Constructor Details
#initialize(hash = {}) ⇒ Item
Initialize a new Item with a few, or all, attributes.
55 56 57 58 59 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 55 def initialize(hash={}) hash.each_pair do |key, val| self[key] = val end end |
Instance Attribute Details
#diff ⇒ String
Returns If requested, the diff output.
35 36 37 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 35 def diff @diff end |
#dup_count ⇒ Integer
Returns Positive if multiple conflicting files found for same item.
45 46 47 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 45 def dup_count @dup_count end |
#header ⇒ String
Returns The (optional) #ITEM <method> <path> :script header.
33 34 35 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 33 def header @header end |
#id ⇒ Object
Read-only platform UUID, used to uniquely identify items. See also writable :alias property available on some items.
25 26 27 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 25 def id @id end |
#line_beg ⇒ Integer
Returns The line in #local_path where this #script starts.
29 30 31 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 29 def line_beg @line_beg end |
#line_end ⇒ Integer
Returns The line in #local_path where this #script ends.
31 32 33 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 31 def line_end @line_end end |
#local_path ⇒ Pathname
Returns Where this item lives.
22 23 24 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 22 def local_path @local_path end |
#name ⇒ String
Returns The name of this item.
20 21 22 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 20 def name @name end |
#script ⇒ String
Returns The Lua code for this item. (not all items use this.).
27 28 29 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 27 def script @script end |
#selected ⇒ Boolean
Returns When filtering, did this item pass.
37 38 39 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 37 def selected @selected end |
#synckey ⇒ String
Returns The constructed name used to match local items to remote items.
39 40 41 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 39 def synckey @synckey end |
#synctype ⇒ String
Returns The syncable type.
41 42 43 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 41 def synctype @synctype end |
#updated_at ⇒ String
Returns The updated_at time from the server is used to detect changes.
43 44 45 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 43 def updated_at @updated_at end |
Instance Method Details
#<=>(other) ⇒ Object
185 186 187 188 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 185 def <=>(other) # rubocop:disable Style/RedundantSelf: Redundant self detected. self.to_h <=> other.to_h end |
#[](key) ⇒ Object
Get attribute as if this was a Hash
76 77 78 79 80 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 76 def [](key) public_send(key.to_sym) rescue NoMethodError nil end |
#[]=(key, value) ⇒ Object
Set attribute as if this was a Hash
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 85 def []=(key, value) public_send("#{key}=", value) rescue StandardError => err # DEVS: (lb): This isn't an error so much as whatever Item class this # is is missing some members (perhaps they were added recently to the # service, and the CLI has yet to be updated). if $cfg['tool.developer'] MrMurano::Verbose.error( "Unable to set key: #{key} / value: #{value} / err: #{err} / self: #{inspect}" ) end end |
#delete(key) ⇒ Object
Delete a key
101 102 103 104 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 101 def delete(key) inst = as_inst(key) remove_instance_variable(inst) if instance_variable_defined?(inst) end |
#each_pair {|key, value| ... } ⇒ Item
Calls block once for each non-nil key
130 131 132 133 134 135 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 130 def each_pair instance_variables.each do |key| yield as_sym(key), instance_variable_get(key) end self end |
#location_friendly(show_type: false, full_path: false) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 190 def location_friendly(show_type: false, full_path: false) desc = location_path_and_line(full_path: full_path) desc += ' [phantom]' if defined?(@phantom) && @phantom return desc unless show_type unless @pp_desc.to_s.empty? || (@pp_desc == @synckey) desc += " (#{@pp_desc})" end # NOTE: This path is the endpoint path. desc += " [#{@method} #{@path}]" if (@method && @path) desc end |
#location_path_and_line(full_path: false) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 202 def location_path_and_line(full_path: false) if !defined?(@local_path) || @local_path.nil? @synckey else desc = @local_path desc = desc.relative_path_from(Pathname.pwd) unless full_path desc = desc.to_s if defined?(@line_beg) && !@line_beg.nil? && @line_beg > 0 desc = "#{desc}:#{@line_beg}" end if defined?(@line_end) && !@line_end.nil? && @line_end > 0 desc = "#{desc}-#{@line_end}" end desc end end |
#merge(item) ⇒ Item
A new Item containing our plus items.
122 123 124 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 122 def merge(item) dup.merge!(item) end |
#merge!(item) ⇒ Item
Adds the contents of item to self.
114 115 116 117 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 114 def merge!(item) item.each_pair { |k, v| self[k] = v } self end |
#reject {|key, value| ... } ⇒ Item
A new Item with keys deleted where block is true
155 156 157 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 155 def reject(&block) dup.reject!(&block) end |
#reject! {|key, value| ... } ⇒ Item
Delete items in self that block returns true.
142 143 144 145 146 147 148 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 142 def reject!(&_block) instance_variables.each do |key| drop = yield as_sym(key), instance_variable_get(key) delete(key) if drop end self end |
#reject_ephemeral ⇒ Object
Scrub local, non-BizAPI/Pegasus attrs from Item (before uploading).
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 160 def reject_ephemeral reject do |attr_key, _| [ # Writeable platform properties: # :name, # :script, # Read-only platform properties: :id, :updated_at, # Local-only attrs: :diff, :dup_count, :header, :line_beg, :line_end, :local_path, :selected, :synckey, :synctype, ].include? attr_key end end |
#to_h ⇒ Hash{Symbol=>Object}
Returns A hash that represents this Item.
107 108 109 |
# File 'lib/MrMurano/SyncUpDown-Item.rb', line 107 def to_h Hash[instance_variables.sort.map { |k| [as_sym(k), instance_variable_get(k)] }] end |