code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def to_csv
participant_emails = @share_participants.map {|participant| participant.email}.join(",")
parent_id = ""
parent_name = ""
if is_child?
parent_id = @parent.primary_key
parent_name = @parent.name
end
to_return = [@primary_key, @name, @notes.length, @account.primary_key, @account.name, participant_emails, parent_id, parent_name, "", @uuid]
return to_return
end | #
This method generates an Array containing the information needed for CSV generation | to_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def full_name_with_links(individual_files: false, use_uuid: false, relative_root: to_uri, include_id: false)
builder = Nokogiri::HTML::Builder.new(encoding: "utf-8") do |doc|
current_node = self
parents = Array.new
doc.span {
# Build the list of folders we need to traverse
while current_node.is_child?
current_node = current_node.parent
parents.push current_node
end
# traverse the list, creating a link for each
parents.reverse.each do |parent|
tmp_folder = parent.anchor_link(use_uuid: use_uuid)
if individual_files
tmp_folder = parent.to_uri.join("index.html").relative_path_from(relative_root)
end
options = {href: tmp_folder}
options[:id] = "folder_#{parent.unique_id(use_uuid)}" if include_id
doc.a(options) {
doc.text parent.name
}
doc.text " -> "
end
tmp_folder = anchor_link(use_uuid: use_uuid)
if individual_files
tmp_folder = relative_root.join("index.html").relative_path_from(relative_root)
end
options = {href: tmp_folder}
options[:id] = "folder_#{unique_id(use_uuid)}" if include_id
doc.a(options) {
doc.text @name
}
}
end
return builder.doc.root
end | This method prepares the folder name, as displayed in HTML, with links
to each of its parents via a recursive approach. | full_name_with_links | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def sorted_notes
return @notes if !@retain_order
@notes.sort_by { |note| [note.is_pinned ? 1 : 0, note.modify_time] }.reverse
end | #
This method returns an Array of AppleNote objects in the appropriate order based on current sort settings. | sorted_notes | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def clean_name
@name.tr('/:\\', '_')
end | #
Returns a name with things removed that might allow for poorly placed files | clean_name | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def to_account_root(individual_files=false)
return "../" if !individual_files
return (@parent.to_account_root(individual_files) + "../") if @parent
return "../"
end | This method computes the path to get to the account root folder. It only
has meaning when using the --individual-files switch at runtime. | to_account_root | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def to_path
# If this folder has a parent, we do NOT want to embed the account name every time
if @parent
return @parent.to_path.join(Pathname.new("#{clean_name}"))
end
# If we get here, the folder is a root folder and we DO want to preface it with the account namespace
return Pathname.new("#{@account.clean_name}-#{clean_name}")
end | This method is used to generate the filepath on disk for a folder, if the
--individual-files switch is passed at run time. | to_path | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def to_uri
# If this folder has a parent, we do NOT want to embed the account name every time
if @parent
return @parent.to_uri.join(Pathname.new(CGI.escapeURIComponent(clean_name)))
end
# If we get here, the folder is a root folder and we DO want to preface it with the account namespace
return Pathname.new(CGI.escapeURIComponent("#{@account.clean_name}-#{clean_name}"))
end | This method is used to generate the actual clickable URI to get to a specific folder
if the --individual-files switch is passed at runtime | to_uri | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb | MIT |
def initialize(folder_primary_key, folder_name, folder_account, query)
super(folder_primary_key, folder_name, folder_account)
@query = query
end | #
Creates a new AppleNotesSmartFolder.
Requires the folder's +primary_key+ as an Integer, +name+ as a String,
+account+ as an AppleNotesAccount, and +query+ as a String representing
how this folder selects notes to display. | initialize | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesSmartFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesSmartFolder.rb | MIT |
def to_csv
# Get the parent's CSV and overwrite the query field
to_return = super()
to_return[AppleNotesFolder.csv_smart_folder_query_column] = @query
return to_return
end | #
This method generates an Array containing the information needed for CSV generation | to_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNotesSmartFolder.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesSmartFolder.rb | MIT |
def initialize(file_path, version)
@file_path = file_path
@database = nil
@logger = Logger.new(STDOUT)
@version = version
@notes = Hash.new()
@folders = Hash.new()
@folder_order = Hash.new()
@accounts = Hash.new()
@cloud_kit_participants = Hash.new()
@retain_order = false
@html = nil
@range_start = 0
@range_end = Time.now.to_i
end | #
Creates a new AppleNoteStore. Expects a FilePath +file_path+ to the NoteStore.sqlite
database itself. Uses that to create a SQLite3::Database object to query into it. Immediately
creates an Array to hold the +notes+, an Array to hold the +folders+ and an Array to hold
the +accounts+. Then it calls +rip_accounts+ and +rip_folders+ to populate them. Also
expects an Integer +version+ to know what type it is. | initialize | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def open
return if @database
@database = SQLite3::Database.new(@file_path.to_s, {results_as_hash: true})
end | #
This method opens the AppleNoteStore's database. | open | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def close
@database.close if @database
end | #
This method nicely closes the database handle. | close | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def valid_notes?
return true if @version >= AppleNoteStoreVersion::IOS_LEGACY_VERSION # Easy out if we've already identified the version
# Just because my fingerprinting isn't great yet, adding in a more manual check for the key tables we need
expected_tables = ["ZICCLOUDSYNCINGOBJECT",
"ZICNOTEDATA"]
@database.execute("SELECT name FROM sqlite_master WHERE type='table'") do |row|
expected_tables.delete(row["name"])
end
return (expected_tables.length == 0)
end | #
This method ensures that the SQLite3::Database is a valid iCloud version of Apple Notes. | valid_notes? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_all_objects
open
rip_accounts()
rip_folders()
rip_notes()
puts "Updated AppleNoteStore object with #{@notes.length} AppleNotes in #{@folders.length} folders belonging to #{@accounts.length} accounts."
end | #
This method kicks off the parsing of all the objects | rip_all_objects | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_account_csv
to_return = [AppleNotesAccount.to_csv_headers]
@accounts.each do |key, account|
to_return.push(account.to_csv)
end
to_return
end | #
This method returns an Array of rows to build the +accounts+
CSV object. | get_account_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def add_plain_text_to_database
return if @version < AppleNoteStoreVersion::IOS_VERSION_9 # Fail out if we're prior to the compressed data age
# Warn the user
puts "Adding the ZICNOTEDATA.ZPLAINTEXT and ZICNOTEDATA.ZDECOMPRESSEDDATA columns, this takes a few seconds"
# Add the new ZPLAINTEXT column
@database.execute("ALTER TABLE ZICNOTEDATA ADD COLUMN ZPLAINTEXT TEXT")
@database.execute("ALTER TABLE ZICNOTEDATA ADD COLUMN ZDECOMPRESSEDDATA TEXT")
# Loop over each AppleNote
@notes.each do |key, note|
# Update the database to include the plaintext
@database.execute("UPDATE ZICNOTEDATA " +
"SET ZPLAINTEXT=?, ZDECOMPRESSEDDATA=? " +
"WHERE Z_PK=?",
[note.plaintext, note.decompressed_data, note.primary_key]) if note.plaintext
end
end | #
This method adds the ZPLAINTEXT column to ZICNOTEDATA
and then populates it with each note's plaintext. | add_plain_text_to_database | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_embedded_object_csv
to_return = [AppleNotesEmbeddedObject.to_csv_headers]
# Loop over each AppleNote
@notes.each do |key, note|
# Loop over eac AppleNotesEmbeddedObject
note.all_embedded_objects.each do |embedded_object|
# Get the results of AppleNotesEmbeddedObject.to_csv
embedded_object_csv = embedded_object.to_csv
# Check to see if the first element is an Array
if embedded_object_csv.first.is_a? Array
# If it is, loop over each entry to add it to our results
embedded_object_csv.each do |embedded_array|
to_return.push(embedded_array)
end
else
to_return.push(embedded_object_csv)
end
end
end
to_return
end | #
This method returns an Array of rows to build the
CSV object holding all AppleNotesEmbeddedObject instances in its +notes+. | get_embedded_object_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_folder_csv
to_return = [AppleNotesFolder.to_csv_headers]
@folders.sort_by{|key, folder| key}.each do |key, folder|
to_return.push(folder.to_csv)
end
to_return
end | #
This method returns an Array of rows to build the +folders+
CSV object. | get_folder_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_cloudkit_participants_csv
to_return = [AppleCloudKitShareParticipant.to_csv_headers]
@cloud_kit_participants.each do |key, participant|
to_return.push(participant.to_csv)
end
to_return
end | #
This method returns an Array of rows to build the +cloudkit_participants+
CSV object. | get_cloudkit_participants_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_note_csv
to_return = [AppleNote.to_csv_headers]
@notes.each do |key, note|
to_return.push(note.to_csv)
end
to_return
end | #
This method returns an Array of rows to build the +notes+
CSV object. | get_note_csv | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def cloud_kit_record_known?(record_id)
return false if !@cloud_kit_participants.include?(record_id)
return @cloud_kit_participants[record_id]
end | #
This method takes a String +record_id+ to determine if the particular cloudkit
record is known. It returns an AppleCloudKitParticipant object, or False. | cloud_kit_record_known? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_account_by_user_record_name(user_record_name)
@accounts.each_pair do |account_id, account|
return account if (account.user_record_name == user_record_name)
end
return nil
end | #
This method looks up an AppleNotesAccount based on the given +user_record_name+.
User record nameshould be a String that represents the ZICCLOUDSYNCINGOBJECT.ZUSERRECORDNAME of the account. | get_account_by_user_record_name | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def get_folder_by_uuid(folder_uuid)
@folders.each_value do |folder|
return folder if folder.uuid == folder_uuid
end
return nil
end | #
This method looks up an AppleNotesFolder based on the given +folder_uuid+.
ID should be a String that represents the ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER of the folder. | get_folder_by_uuid | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_accounts()
if @version.modern?
@database.execute("SELECT ZICCLOUDSYNCINGOBJECT.Z_PK " +
"FROM ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICCLOUDSYNCINGOBJECT.ZNAME IS NOT NULL") do |row|
rip_account(row["Z_PK"])
end
end
if @version.legacy?
@database.execute("SELECT ZACCOUNT.Z_PK FROM ZACCOUNT") do |row|
rip_account(row["Z_PK"])
end
end
@accounts.each_pair do |key, account|
@logger.debug("Rip Accounts final array: #{key} corresponds to #{account.name}")
end
end | #
This function identifies all AppleNotesAccount potential
objects in ZICCLOUDSYNCINGOBJECTS and calls +rip_account+ on each. | rip_accounts | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_account(account_id)
@logger.debug("Rip Account: Calling rip_account on Account ID #{account_id}")
# Set the ZSERVERRECORD column to look at
server_record_column = "ZSERVERRECORD"
server_record_column = server_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
# Set the ZSERVERSHARE column to look at
server_share_column = "ZSERVERSHARE"
server_share_column = server_share_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
# Set the ZACCOUNTDATA column to look at
account_data_column = "-1 as ZACCOUNTDATA"
account_data_column = "ZICCLOUDSYNCINGOBJECT.ZACCOUNTDATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_13 # This column appears to show up in iOS 12
@logger.debug("Rip Account: Using server_record_column of #{server_record_column}")
# Set the query
query_string = "SELECT ZICCLOUDSYNCINGOBJECT.ZNAME, ZICCLOUDSYNCINGOBJECT.Z_PK, " +
"ZICCLOUDSYNCINGOBJECT.#{server_record_column}, ZICCLOUDSYNCINGOBJECT.ZCRYPTOITERATIONCOUNT, " +
"ZICCLOUDSYNCINGOBJECT.ZCRYPTOVERIFIER, ZICCLOUDSYNCINGOBJECT.ZCRYPTOSALT, " +
"ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, ZICCLOUDSYNCINGOBJECT.#{server_share_column}, " +
"ZICCLOUDSYNCINGOBJECT.ZUSERRECORDNAME, #{account_data_column}, " +
"ZICCLOUDSYNCINGOBJECT.ZACCOUNTNAMEFORACCOUNTLISTSORTING " +
"FROM ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICCLOUDSYNCINGOBJECT.Z_PK=?"
# Change the query for legacy IOS
if @version.legacy?
query_string = "SELECT ZACCOUNT.ZNAME, ZACCOUNT.Z_PK, " +
"ZACCOUNT.ZACCOUNTIDENTIFIER as ZIDENTIFIER " +
"FROM ZACCOUNT " +
"WHERE ZACCOUNT.Z_PK=?"
end
@logger.debug("Rip Account: Query is #{query_string}")
# Run the query
@database.execute(query_string, account_id) do |row|
# Create account object
tmp_account = AppleNotesAccount.new(row["Z_PK"],
row["ZNAME"],
row["ZIDENTIFIER"])
tmp_account.retain_order = @retain_order
# Handle LocalAccounts that are in odd places
likely_location = @backup.root_folder + tmp_account.account_folder
if tmp_account.identifier == "LocalAccount" and not likely_location.exist?
tmp_account.account_folder = ""
@logger.debug("Rip Account: LocalAccount found with files in the Notes root folder, not an account folder, this is fine.")
end
# Add server-side data, if relevant
tmp_account.user_record_name = row["ZUSERRECORDNAME"] if row["ZUSERRECORDNAME"]
tmp_account.add_cloudkit_server_record_data(row[server_record_column]) if row[server_record_column]
# Set the sort order for the account so we can properly sort things later
tmp_account.sort_order_name = row["ZACCOUNTNAMEFORACCOUNTLISTSORTING"] if row["ZACCOUNTNAMEFORACCOUNTLISTSORTING"]
if(row[server_share_column])
tmp_account.add_cloudkit_sharing_data(row[server_share_column])
# Add any share participants to our overall list
tmp_account.share_participants.each do |participant|
@cloud_kit_participants[participant.record_id] = participant
end
end
# Add cryptographic variables, if relevant
if row["ZCRYPTOVERIFIER"]
tmp_account.add_crypto_variables(row["ZCRYPTOSALT"],
row["ZCRYPTOITERATIONCOUNT"],
row["ZCRYPTOVERIFIER"])
end
# Store the folder structure if we have one
if row["ZACCOUNTDATA"] and row["ZACCOUNTDATA"] > 0
account_data_query_string = "SELECT ZICCLOUDSYNCINGOBJECT.ZMERGEABLEDATA " +
"FROM ZICCLOUDSYNCINGOBJECT " +
"WHERE Z_PK=?"
@database.execute(account_data_query_string, row["ZACCOUNTDATA"]) do |account_data_row|
gzipped_data = account_data_row["ZMERGEABLEDATA"]
# Make sure this exists before we try to unpack it
@logger.debug("Rip Account: row['ZMERGEABLEDATA'] is empty!") if !gzipped_data
if gzipped_data
# Inflate the GZip
zlib_inflater = Zlib::Inflate.new(Zlib::MAX_WBITS + 16)
mergeable_data = zlib_inflater.inflate(gzipped_data)
# Read the protobuff
mergabledata_proto = MergableDataProto.decode(mergeable_data)
# Loop over all the mergeable data object entries to find the list
mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_entry.each do |mergeable_data_object_entry|
# Once you find the list, loop over each entry to...
if mergeable_data_object_entry.list
mergeable_data_object_entry.list.list_entry.each do |list_entry|
# Fetch the folder order, which is an int64 in the protobuf
additional_details_index = list_entry.additional_details.id.object_index
additional_details_object = mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_entry[additional_details_index]
tmp_folder_placement = additional_details_object.unknown_message.unknown_entry.unknown_int2
# Pull out the object index we can find the UUID at
list_index = list_entry.id.object_index
# Use that index to find the UUID's object
tmp_folder_uuid_object = mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_entry[list_index]
# Look inside that object to get the string value that is saved in the custom map
tmp_folder_uuid = tmp_folder_uuid_object.custom_map.map_entry.first.value.string_value
@folder_order[tmp_folder_uuid] = tmp_folder_placement
end
end
end
end
end
end
@logger.debug("Rip Account: Created account #{tmp_account.name}")
@accounts[account_id] = tmp_account
end
end | #
This function takes a specific AppleNotesAccount potential
object in ZICCLOUDSYNCINGOBJECTS, identified by Integer +account_id+, and pulls the needed information to create the object.
If encryption information is present, it adds it with AppleNotesAccount.add_crypto_variables. | rip_account | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_folders()
if @version.modern?
@database.execute("SELECT ZICCLOUDSYNCINGOBJECT.Z_PK " +
"FROM ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICCLOUDSYNCINGOBJECT.ZTITLE2 IS NOT NULL") do |row|
rip_folder(row["Z_PK"])
end
end
# In legacy Notes the "folders" were "stores"
if @version.legacy?
@database.execute("SELECT ZSTORE.Z_PK FROM ZSTORE") do |row|
rip_folder(row["Z_PK"])
end
end
# Loop over all folders to do some clean up
@folders.each_pair do |key, folder|
if folder.is_orphan?
tmp_parent_folder = get_folder(folder.parent_id) if folder.parent_id
tmp_parent_folder = get_folder_by_uuid(folder.parent_uuid) if folder.parent_uuid
@logger.debug("Rip Folder: Identified parent UUID #{folder.parent_uuid} for Folder #{folder.primary_key} (#{folder.name}) in ZSERVERRECORD data")
if tmp_parent_folder
tmp_parent_folder.add_child(folder)
@logger.debug("Rip Folder: Added folder #{folder.primary_key} (#{folder.full_name}) as child to #{tmp_parent_folder.name}")
else
@logger.debug("Rip Folder: Could not find parent folder for Folder #{folder.primary_key}")
end
end
@logger.debug("Rip Folders final array: #{key} corresponds to #{folder.name}")
end
# Sort the folders if we want to retain the order, group each account together
if @retain_order
@folders = @folders.sort_by{|folder_id, folder| [folder.account.sort_order_name, folder.sort_order]}.to_h
# Also organize the child folders nicely
@folders.each do |folder_id, folder|
folder.sort_children
end
end
end | #
This function identifies all AppleNotesFolder potential
objects in ZICCLOUDSYNCINGOBJECTS and calls +rip_folder+ on each. | rip_folders | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_folder(folder_id)
@logger.debug("Rip Folder: Calling rip_folder on Folder ID #{folder_id}")
# Set the ZSERVERRECORD column to look at
server_record_column = "ZSERVERRECORD"
server_record_column = server_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
# Set the ZSERVERSHARE column to look at
server_share_column = "ZSERVERSHARE"
server_share_column = server_share_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
smart_folder_query = "'' as ZSMARTFOLDERQUERYJSON"
smart_folder_query = "ZICCLOUDSYNCINGOBJECT.ZSMARTFOLDERQUERYJSON" if @version >= AppleNoteStoreVersion::IOS_VERSION_15
query_string = "SELECT ZICCLOUDSYNCINGOBJECT.ZTITLE2, ZICCLOUDSYNCINGOBJECT.ZOWNER, " +
"ZICCLOUDSYNCINGOBJECT.#{server_record_column}, ZICCLOUDSYNCINGOBJECT.#{server_share_column}, " +
"ZICCLOUDSYNCINGOBJECT.Z_PK, ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER, " +
"ZICCLOUDSYNCINGOBJECT.ZPARENT, #{smart_folder_query} " +
"FROM ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICCLOUDSYNCINGOBJECT.Z_PK=?"
#Change things up for the legacy version
if @version.legacy?
query_string = "SELECT ZSTORE.Z_PK, ZSTORE.ZNAME as ZTITLE2, " +
"ZSTORE.ZACCOUNT as ZOWNER, '' as ZIDENTIFIER " +
"FROM ZSTORE " +
"WHERE ZSTORE.Z_PK=?"
end
@database.execute(query_string, folder_id) do |row|
tmp_folder = AppleNotesFolder.new(row["Z_PK"],
row["ZTITLE2"],
get_account(row["ZOWNER"]))
# If this is a smart folder, instead build an AppleNotesSmartFolder
if row["ZSMARTFOLDERQUERYJSON"] and row["ZSMARTFOLDERQUERYJSON"].length > 0
tmp_folder = AppleNotesSmartFolder.new(row["Z_PK"],
row["ZTITLE2"],
get_account(row["ZOWNER"]),
row["ZSMARTFOLDERQUERYJSON"])
end
if row["ZIDENTIFIER"]
tmp_folder.uuid = row["ZIDENTIFIER"]
end
# Set whether the folder displays notes in numeric order, or by modification date
tmp_folder.retain_order = @retain_order
tmp_folder.sort_order = @folder_order[row["ZIDENTIFIER"]] if @folder_order[row["ZIDENTIFIER"]]
# Remember folder heirarchy
if row["ZPARENT"]
tmp_parent_folder_id = row["ZPARENT"]
tmp_folder.parent_id = tmp_parent_folder_id
end
# Add server-side data, if relevant
tmp_folder.add_cloudkit_server_record_data(row[server_record_column]) if row[server_record_column]
if(row[server_share_column])
tmp_folder.add_cloudkit_sharing_data(row[server_share_column])
# Add any share participants to our overall list
tmp_folder.share_participants.each do |participant|
@cloud_kit_participants[participant.record_id] = participant
end
end
@logger.debug("Rip Folder: Created folder #{tmp_folder.name}")
# Whether child or not, we add it to the overall tracker so we can look up by folder ID.
# We'll clean up on output by testing to see if a folder has a parent.
@folders[folder_id] = tmp_folder
end
end | #
This function takes a specific AppleNotesFolder potential
object in ZICCLOUDSYNCINGOBJECTS, identified by Integer +folder_id+, and pulls the needed information to create the object.
This used to use ZICCLOUDSYNCINGOBJECT.ZACCOUNT4, but that value also appears to be duplicated in ZOWNER which goes back further. | rip_folder | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_notes()
range_start_core = (@range_start - 978307200)
range_end_core = (@range_end - 978307200)
@logger.debug("Rip Notes: Ripping notes between #{Time.at(range_start)} and #{Time.at(range_end)}")
if @version.modern?
tmp_query = "SELECT ZICNOTEDATA.ZNOTE " +
"FROM ZICNOTEDATA, ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICNOTEDATA.ZDATA NOT NULL AND ZICCLOUDSYNCINGOBJECT.Z_PK=ZICNOTEDATA.ZNOTE AND " +
"ZICCLOUDSYNCINGOBJECT.ZMODIFICATIONDATE1 >= ? AND " +
"ZICCLOUDSYNCINGOBJECT.ZMODIFICATIONDATE1 <= ?"
@database.execute(tmp_query, [range_start_core, range_end_core]) do |row|
begin
self.rip_note(row["ZNOTE"])
rescue StandardError => error
# warn "\033[101m#{e}\033[m"
@logger.error("AppleNoteStore: NoteStore tried to rip Note #{row["ZNOTE"]} but had to rescue error: #{error}")
@logger.error("Backtrace: #{error.backtrace.join("\n\t")}") # if error.is_a? FrozenError
end
end
end
if @version.legacy?
@database.execute("SELECT ZNOTE.Z_PK FROM ZNOTE") do |row|
self.rip_note(row["Z_PK"])
end
end
end | #
This function identifies all AppleNote potential
objects in ZICNOTEDATA and calls +rip_note+ on each. | rip_notes | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def rip_note(note_id)
@logger.debug("Rip Note: Ripping note from Note ID #{note_id}")
# Set the ZSERVERRECORD column to look at
server_record_column = "ZSERVERRECORD"
server_record_column = server_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
# Set the ZSERVERSHARE column to look at
server_share_column = "ZSERVERSHARE"
server_share_column = server_share_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_12 # In iOS 11 this was ZSERVERRECORD, in 12 and later it became ZSERVERRECORDDATA
# Set the ZWIDGETSNIPPET column, blank if earlier than iOS 17
widget_snippet_column = ""
widget_snippet_column = ", ZWIDGETSNIPPET" if @version >= AppleNoteStoreVersion::IOS_VERSION_17
# Set the ZUNAPPLIEDENCRYPTEDRECORD column to look at
unapplied_encrypted_record_column = "ZUNAPPLIEDENCRYPTEDRECORD"
unapplied_encrypted_record_column = unapplied_encrypted_record_column + "DATA" if @version >= AppleNoteStoreVersion::IOS_VERSION_18 # In iOS 17 this was ZUNAPPLIEDENCRYPTEDRECORD, in 18 and later it becomes ZUNAPPLIEDENCRYPTEDRECORDDATA
folder_field = "ZFOLDER"
account_field = "ZACCOUNT7"
note_id_field = "ZNOTE"
creation_date_field = "ZCREATIONDATE1"
# In version 15, what is now in ZACCOUNT7 as of iOS 16 (the account ID) was in ZACCOUNT4
if @version == AppleNoteStoreVersion::IOS_VERSION_15
account_field = "ZACCOUNT4"
end
# In version 13 and 14, what is now in ZACCOUNT4 as of iOS 15 (the account ID) was in ZACCOUNT3
if @version < AppleNoteStoreVersion::IOS_VERSION_15
account_field = "ZACCOUNT3"
end
# In iOS 15 it appears ZCREATIONDATE1 moved to ZCREATIONDATE3 for notes
if @version > AppleNoteStoreVersion::IOS_VERSION_14
creation_date_field = "ZCREATIONDATE3"
end
query_string = "SELECT ZICNOTEDATA.Z_PK, ZICNOTEDATA.ZNOTE, " +
"ZICNOTEDATA.ZCRYPTOINITIALIZATIONVECTOR, ZICNOTEDATA.ZCRYPTOTAG, " +
"ZICNOTEDATA.ZDATA, ZICCLOUDSYNCINGOBJECT.ZCRYPTOVERIFIER, " +
"ZICCLOUDSYNCINGOBJECT.ZCRYPTOSALT, ZICCLOUDSYNCINGOBJECT.ZCRYPTOITERATIONCOUNT, " +
"ZICCLOUDSYNCINGOBJECT.ZCRYPTOWRAPPEDKEY, ZICCLOUDSYNCINGOBJECT.ZISPASSWORDPROTECTED, " +
"ZICCLOUDSYNCINGOBJECT.ZMODIFICATIONDATE1, ZICCLOUDSYNCINGOBJECT.#{creation_date_field}, " +
"ZICCLOUDSYNCINGOBJECT.ZTITLE1, ZICCLOUDSYNCINGOBJECT.#{account_field}, " +
"ZICCLOUDSYNCINGOBJECT.ZACCOUNT2, ZICCLOUDSYNCINGOBJECT.#{folder_field}, " +
"ZICCLOUDSYNCINGOBJECT.#{server_record_column}, ZICCLOUDSYNCINGOBJECT.#{unapplied_encrypted_record_column}, " +
"ZICCLOUDSYNCINGOBJECT.#{server_share_column}, ZICCLOUDSYNCINGOBJECT.ZISPINNED, " +
"ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER #{widget_snippet_column} " +
"FROM ZICNOTEDATA, ZICCLOUDSYNCINGOBJECT " +
"WHERE ZICNOTEDATA.ZNOTE=? AND ZICCLOUDSYNCINGOBJECT.Z_PK=ZICNOTEDATA.ZNOTE"
# In version 12, what is now in ZACCOUNT3 (the account ID) was in ZACCOUNT2
if @version == AppleNoteStoreVersion::IOS_VERSION_12
account_field = "ZACCOUNT2"
end
# In version 11, what is now in ZACCOUNT3 was in ZACCOUNT2 and the ZFOLDER field was in a completely separate table
if @version == AppleNoteStoreVersion::IOS_VERSION_11
query_string = "SELECT ZICNOTEDATA.Z_PK, ZICNOTEDATA.ZNOTE, " +
"ZICNOTEDATA.ZCRYPTOINITIALIZATIONVECTOR, ZICNOTEDATA.ZCRYPTOTAG, " +
"ZICNOTEDATA.ZDATA, ZICCLOUDSYNCINGOBJECT.ZCRYPTOVERIFIER, " +
"ZICCLOUDSYNCINGOBJECT.ZCRYPTOSALT, ZICCLOUDSYNCINGOBJECT.ZCRYPTOITERATIONCOUNT, " +
"ZICCLOUDSYNCINGOBJECT.ZCRYPTOWRAPPEDKEY, ZICCLOUDSYNCINGOBJECT.ZISPASSWORDPROTECTED, " +
"ZICCLOUDSYNCINGOBJECT.ZMODIFICATIONDATE1, ZICCLOUDSYNCINGOBJECT.ZCREATIONDATE1, " +
"ZICCLOUDSYNCINGOBJECT.ZTITLE1, ZICCLOUDSYNCINGOBJECT.ZACCOUNT2, " +
"Z_11NOTES.Z_11FOLDERS, ZICCLOUDSYNCINGOBJECT.#{server_record_column}, " +
"ZICCLOUDSYNCINGOBJECT.#{unapplied_encrypted_record_column}, ZICCLOUDSYNCINGOBJECT.#{server_share_column}, " +
"ZICCLOUDSYNCINGOBJECT.ZISPINNED, ZICCLOUDSYNCINGOBJECT.ZIDENTIFIER " +
"FROM ZICNOTEDATA, ZICCLOUDSYNCINGOBJECT, Z_11NOTES " +
"WHERE ZICNOTEDATA.ZNOTE=? AND ZICCLOUDSYNCINGOBJECT.Z_PK=ZICNOTEDATA.ZNOTE AND Z_11NOTES.Z_8NOTES=ZICNOTEDATA.ZNOTE"
folder_field = "Z_11FOLDERS"
account_field = "ZACCOUNT2"
end
# In the legecy version, everything is different
if @version.legacy?
query_string = "SELECT ZNOTE.Z_PK, ZNOTE.ZCREATIONDATE as ZCREATIONDATE1, " +
"ZNOTE.ZMODIFICATIONDATE as ZMODIFICATIONDATE1, ZNOTE.ZTITLE as ZTITLE1, " +
"ZNOTEBODY.ZCONTENT as ZDATA, ZSTORE.Z_PK as ZFOLDER, ZSTORE.ZACCOUNT, " +
"0 as ZISPINNED " +
"FROM ZNOTE, ZNOTEBODY, ZSTORE " +
"WHERE ZNOTE.Z_PK=? AND ZNOTEBODY.Z_PK=ZNOTE.ZBODY AND ZSTORE.Z_PK=ZNOTE.ZSTORE"
folder_field = "ZFOLDER"
account_field = "ZACCOUNT"
note_id_field = "Z_PK"
end
# Uncomment these lines if we ever think there is weirdness with using the wrong fields for the right version
#@logger.debug("Rip Note: Query string is #{query_string}")
#@logger.debug("Rip Note: account field is #{account_field}")
#@logger.debug("Rip Note: folder field is #{folder_field}")
#@logger.debug("Rip Note: Note ID is #{note_id}")
# Execute the query
@database.execute(query_string, note_id) do |row|
# Create our note
tmp_account_id = row[account_field]
tmp_folder_id = row[folder_field]
@logger.debug("Rip Note: Looking up account for #{tmp_account_id}")
@logger.debug("Rip Note: Looking up folder for #{tmp_folder_id}")
tmp_account = get_account(tmp_account_id)
tmp_folder = get_folder(tmp_folder_id)
@logger.error("Rip Note: Somehow could not find account!") if !tmp_account
@logger.error("Rip Note: Somehow could not find folder!") if !tmp_folder
tmp_note = AppleNote.new(row["Z_PK"],
row[note_id_field],
row["ZTITLE1"],
row["ZDATA"],
row[creation_date_field],
row["ZMODIFICATIONDATE1"],
tmp_account,
tmp_folder)
# Set the note's version
tmp_note.version=(@version)
tmp_note.notestore=(self)
# Set the pinned status
if row["ZISPINNED"] == 1
tmp_note.is_pinned = true
end
# Set the UUID, if it exists
if row["ZIDENTIFIER"]
tmp_note.uuid = row["ZIDENTIFIER"]
end
# Set the widget snippet, if it exists
if row["ZWIDGETSNIPPET"]
tmp_note.widget_snippet = row["ZWIDGETSNIPPET"]
end
tmp_account.add_note(tmp_note) if tmp_account
tmp_folder.add_note(tmp_note) if tmp_folder
# Add server-side data, if relevant
if row[server_record_column]
tmp_note.add_cloudkit_server_record_data(row[server_record_column])
end
if(row[server_share_column])
tmp_note.add_cloudkit_sharing_data(row[server_share_column])
# Add any share participants to our overall list
tmp_note.share_participants.each do |participant|
@cloud_kit_participants[participant.record_id] = participant
end
end
# If this is protected, add the cryptographic variables
if row["ZISPASSWORDPROTECTED"] == 1
# Set values initially from the expected columns
crypto_iv = row["ZCRYPTOINITIALIZATIONVECTOR"]
crypto_tag = row["ZCRYPTOTAG"]
crypto_salt = row["ZCRYPTOSALT"]
crypto_iterations = row["ZCRYPTOITERATIONCOUNT"]
crypto_verifier = row["ZCRYPTOVERIFIER"]
crypto_wrapped_key = row["ZCRYPTOWRAPPEDKEY"]
# Try the initial set of credentials, this is cheap if they are
# missing, decrypt just returns false.
tmp_note.add_cryptographic_settings(crypto_iv,
crypto_tag,
crypto_salt,
crypto_iterations,
crypto_verifier,
crypto_wrapped_key)
# Try each password and see if any generate a decrypt.
found_password = tmp_note.decrypt
# If they aren't there, we need to use the ZUNAPPLIEDENCRYPTEDRECORD
if row[unapplied_encrypted_record_column] and !found_password
keyed_archive = KeyedArchive.new(:data => row[unapplied_encrypted_record_column])
unpacked_top = keyed_archive.unpacked_top()
ns_keys = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.keys"]
ns_values = unpacked_top["root"]["ValueStore"]["RecordValues"]["NS.objects"]
crypto_iv = ns_values[ns_keys.index("CryptoInitializationVector")]
crypto_tag = ns_values[ns_keys.index("CryptoTag")]
crypto_salt = ns_values[ns_keys.index("CryptoSalt")]
crypto_iterations = ns_values[ns_keys.index("CryptoIterationCount")]
crypto_wrapped_key = ns_values[ns_keys.index("CryptoWrappedKey")]
tmp_note.add_cryptographic_settings(crypto_iv,
crypto_tag,
crypto_salt,
crypto_iterations,
crypto_verifier,
crypto_wrapped_key)
# Try each password and see if any generate a decrypt.
found_password = tmp_note.decrypt
end
if !found_password
@logger.debug("Apple Note Store: Note #{tmp_note.note_id} could not be decrypted with our passwords.")
end
end
# Only add the note if we have both a folder and account for it, otherwise things blow up
if tmp_account and tmp_folder
@notes[tmp_note.note_id] = tmp_note
tmp_note.process_note
else
@logger.error("Rip Note: Skipping note #{tmp_note.note_id} due to a missing account.") if !tmp_account
@logger.error("Rip Note: Skipping note #{tmp_note.note_id} due to a missing folder.") if !tmp_folder
if !tmp_account or !tmp_folder
@logger.error("Consider running these sqlite queries to take a look yourself, if ZDATA is NULL, that means you aren't missing anything: ")
@logger.error("\tSELECT Z_PK, #{account_field}, #{folder_field} FROM ZICCLOUDSYNCINGOBJECT WHERE Z_PK=#{tmp_note.primary_key}")
@logger.error("\tSELECT #{note_id_field}, ZDATA FROM ZICNOTEDATA WHERE #{note_id_field}=#{tmp_note.note_id}")
end
puts "Skipping Note ID #{tmp_note.note_id} due to a missing folder or account, check the debug log for more details."
end
end
end | #
This function takes a specific AppleNotesAccount potential
object in ZICCLOUDSYNCINGOBJECTS and ZICNOTEDATA, identified by Integer +account_id+,
and pulls the needed information to create the object. An AppleNote remembers the AppleNotesFolder
and AppleNotesAccount it is part of. If encryption information is present, it adds
it with AppleNotesAccount.add_crypto_variables. | rip_note | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleNoteStore.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb | MIT |
def initialize()
original_filepath = nil # The filepath, as it was originally stored on the phone or Mac
original_filename = nil # The filename, as it was originally stored on the phone or Mac
storage_filepath = nil # The filepath of the file on disk in the backup
end | #
Creates a new AppleStoredFileResilt.
Requires nothing and initiailizes some variables | initialize | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleStoredFileResult.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleStoredFileResult.rb | MIT |
def has_paths?
return (original_filepath and original_filename and storage_filepath)
end | #
Helper function that returns true only if this has
the paths needed for success | has_paths? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleStoredFileResult.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleStoredFileResult.rb | MIT |
def exist?
return storage_filepath.exist?
end | #
Helper function that returns true only if the original filepath exists | exist? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleStoredFileResult.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleStoredFileResult.rb | MIT |
def backup_location
return storage_filepath
end | #
To make it in line with legacy calls to variable names | backup_location | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleStoredFileResult.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleStoredFileResult.rb | MIT |
def filepath
return original_filepath
end | #
To make it in line with legacy calls to variable names | filepath | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleStoredFileResult.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleStoredFileResult.rb | MIT |
def filename
return original_filename
end | #
To make it in line with legacy calls to variable names | filename | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleStoredFileResult.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleStoredFileResult.rb | MIT |
def initialize(uti)
# Set this object's variables
@uti = uti
end | #
Creates a new AppleUniformTypeIdentifier.
Expects a String +uti+ from ZICCLOUDSYNCINGOBJECT.ZTYPEUTI. | initialize | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def get_conforms_to_string
return "bad_uti" if bad_uti?
return "audio" if conforms_to_audio
return "document" if conforms_to_document
return "dynamic" if is_dynamic?
return "image" if conforms_to_image
return "inline" if conforms_to_inline_attachment
return "other public" if is_public?
return "video" if conforms_to_audiovisual
return "uti: #{@uti}"
end | #
This method returns a string indicating roughly how this UTI
should be treated. | get_conforms_to_string | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def bad_uti?
return false if @uti.is_a?(String)
return true
end | #
Checks for a UTI that shouldn't exist or won't behave nicely. | bad_uti? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def is_dynamic?
return false if bad_uti?
return @uti.start_with?("dyn.")
end | #
This method returns true if the UTI represented is dynamic. | is_dynamic? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def is_public?
return false if bad_uti?
return @uti.start_with?("public.")
end | #
This method returns true if the UTI represented is public. | is_public? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def conforms_to_audio
return false if bad_uti?
return true if @uti == "com.apple.m4a-audio"
return true if @uti == "com.microsoft.waveform-audio"
return true if @uti == "public.aiff-audio"
return true if @uti == "public.midi-audio"
return true if @uti == "public.mp3"
return true if @uti == "org.xiph.ogg-audio"
return false
end | #
This method returns true if the UTI conforms to public.audio | conforms_to_audio | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def conforms_to_audiovisual
return false if bad_uti?
return true if @uti == "com.apple.m4v-video"
return true if @uti == "com.apple.protected-mpeg-4-video"
return true if @uti == "com.apple.protected-mpeg-4-audio"
return true if @uti == "com.apple.quicktime-movie"
return true if @uti == "public.avi"
return true if @uti == "public.mpeg"
return true if @uti == "public.mpeg-2-video"
return true if @uti == "public.mpeg-2-transport-stream"
return true if @uti == "public.mpeg-4"
return true if @uti == "public.mpeg-4-audio"
return false
end | #
This method returns true if the UTI conforms to public.video
or public.movie. | conforms_to_audiovisual | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def conforms_to_document
return false if bad_uti?
return true if @uti == "com.apple.iwork.numbers.sffnumbers"
return true if @uti == "com.apple.log"
return true if @uti == "com.apple.rtfd"
return true if @uti == "com.microsoft.word.doc"
return true if @uti == "com.microsoft.excel.xls"
return true if @uti == "com.microsoft.powerpoint.ppt"
return true if @uti == "com.netscape.javascript-source"
return true if @uti == "net.openvpn.formats.ovpn"
return true if @uti == "org.idpf.epub-container"
return true if @uti == "org.oasis-open.opendocument.text"
return true if @uti == "org.openxmlformats.wordprocessingml.document"
return false
end | #
This method returns true if the UTI conforms to public.data objets that are likely documents | conforms_to_document | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def conforms_to_image
return false if bad_uti?
return true if @uti == "com.adobe.illustrator.ai-image"
return true if @uti == "com.adobe.photoshop-image"
return true if @uti == "com.adobe.raw-image"
return true if @uti == "com.apple.icns"
return true if @uti == "com.apple.macpaint-image"
return true if @uti == "com.apple.pict"
return true if @uti == "com.apple.quicktime-image"
return true if @uti == "com.apple.notes.sketch"
return true if @uti == "com.compuserve.gif"
return true if @uti == "com.ilm.openexr-image"
return true if @uti == "com.kodak.flashpix.image"
return true if @uti == "com.microsoft.bmp"
return true if @uti == "com.microsoft.ico"
return true if @uti == "com.sgi.sgi-image"
return true if @uti == "com.truevision.tga-image"
return true if @uti == "public.camera-raw-image"
return true if @uti == "public.fax"
return true if @uti == "public.heic"
return true if @uti == "public.jpeg"
return true if @uti == "public.jpeg-2000"
return true if @uti == "public.png"
return true if @uti == "public.svg-image"
return true if @uti == "public.tiff"
return true if @uti == "public.xbitmap-image"
return true if @uti == "org.webmproject.webp"
return false
end | #
This method returns true if the UTI conforms to public.image | conforms_to_image | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def conforms_to_inline_attachment
return false if bad_uti?
return true if @uti.start_with?("com.apple.notes.inlinetextattachment")
return false
end | #
This method returns true if the UTI represents Apple text enrichment. | conforms_to_inline_attachment | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/AppleUniformTypeIdentifier.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb | MIT |
def same_style_type?(other_attribute_run)
return false if !other_attribute_run
# We clearly aren't the same if one or the other lacks a style type completely
return false if (other_attribute_run.has_style_type and !has_style_type)
return false if (!other_attribute_run.has_style_type and has_style_type)
# If neither has a style type, that is the same
return true if (!other_attribute_run.has_style_type and !has_style_type)
# If the indent levels are different, then the styles are different.
return false if (other_attribute_run.paragraph_style.indent_amount != paragraph_style.indent_amount)
# If the block-quotedness are different, then the styles are different.
return false if (other_attribute_run.paragraph_style.block_quote != paragraph_style.block_quote)
# If both are checkboxes, but they belong to different checklist UUIDs,
# then the styles are different.
return false if (is_checkbox? && other_attribute_run.is_checkbox? && other_attribute_run.paragraph_style.checklist.uuid != paragraph_style.checklist.uuid)
# Compare our style_type to the other style_type and return the result
return (other_attribute_run.paragraph_style.style_type == paragraph_style.style_type)
end | #
This method compares the paragraph_style.style_type integer of two AttributeRun
objects to see if they have the same style_type. | same_style_type? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def same_font_weight?(other_attribute_run)
return false if !other_attribute_run
return (other_attribute_run.font_weight == font_weight)
end | #
Helper function to tell if a given AttributeRun has the same font weight as this one. | same_font_weight? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_checkbox?
return (has_style_type and paragraph_style.style_type == AppleNote::STYLE_TYPE_CHECKBOX)
end | #
Helper function to tell if a given AttributeRun is an AppleNote::STYLE_TYPE_CHECKBOX. | is_checkbox? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_numbered_list?
return (has_style_type and paragraph_style.style_type == AppleNote::STYLE_TYPE_NUMBERED_LIST)
end | #
Helper function to tell if a given AttributeRun is an AppleNote::STYLE_TYPE_NUMBERED_LIST. | is_numbered_list? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_dotted_list?
return (has_style_type and paragraph_style.style_type == AppleNote::STYLE_TYPE_DOTTED_LIST)
end | #
Helper function to tell if a given AttributeRun is an AppleNote::STYLE_TYPE_DOTTED_LIST. | is_dotted_list? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_dashed_list?
return (has_style_type and paragraph_style.style_type == AppleNote::STYLE_TYPE_DASHED_LIST)
end | #
Helper function to tell if a given AttributeRun is an AppleNote::STYLE_TYPE_DASHED_LIST. | is_dashed_list? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_block_quote?
return (has_style_type and paragraph_style.block_quote == AppleNote::STYLE_TYPE_BLOCK_QUOTE)
end | #
Helper function to tell if a given AttributeRun is an AppleNote::STYLE_TYPE_BLOCK_QUOTE. | is_block_quote? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def is_any_list?
return (is_numbered_list? or is_dotted_list? or is_dashed_list? or is_checkbox?)
end | #
Helper function to tell if a given AttributeRun is any sort of AppleNote::STYLE_TYPE_X_LIST. | is_any_list? | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def total_indent
return @indent if @indent
@indent = 0
# Determine what this AttributeRun's indent amount is on its own
my_indent = 0
if paragraph_style and paragraph_style.indent_amount
my_indent = paragraph_style.indent_amount
end
# If there is no previous AttributeRun, the answer is just this AttributeRun's indent amount
if !previous_run
@indent = my_indent
# If there is something previous, add our indent to its total indent
else
@indent = my_indent + previous_run.total_indent
end
return @indent
end | #
This method calculates the total indentation of a given AttributeRun. It caches the result since
it has to recursively check the previous AttributeRuns. | total_indent | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def generate_html(text_to_insert, root_node)
@active_html_node = root_node
@tag_is_open = !text_to_insert.end_with?("\n")
open_alignment_tag
open_block_tag
open_indent_tag
case @active_html_node.node_name
when "ol", "ul", "li"
add_list_text(text_to_insert)
else
add_html_text(text_to_insert)
end
return root_node
end | #
This method generates the HTML for a given AttributeRun. It expects a String as +text_to_insert+ | generate_html | ruby | threeplanetssoftware/apple_cloud_notes_parser | lib/ProtoPatches.rb | https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb | MIT |
def initialize(context = {})
@context = Context.build(context)
end | Internal: Initialize an Interactor.
context - A Hash whose key/value pairs are used in initializing the
interactor's context. An existing Interactor::Context may also be
given. (default: {})
Examples
MyInteractor.new(foo: "bar")
# => #<MyInteractor @context=#<Interactor::Context foo="bar">>
MyInteractor.new
# => #<MyInteractor @context=#<Interactor::Context>> | initialize | ruby | collectiveidea/interactor | lib/interactor.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor.rb | MIT |
def run
run!
rescue Failure => e
if context.object_id != e.context.object_id
raise
end
end | Internal: Invoke an interactor instance along with all defined hooks. The
"run" method is used internally by the "call" class method. The following
are equivalent:
MyInteractor.call(foo: "bar")
# => #<Interactor::Context foo="bar">
interactor = MyInteractor.new(foo: "bar")
interactor.run
interactor.context
# => #<Interactor::Context foo="bar">
After successful invocation of the interactor, the instance is tracked
within the context. If the context is failed or any error is raised, the
context is rolled back.
Returns nothing. | run | ruby | collectiveidea/interactor | lib/interactor.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor.rb | MIT |
def run!
with_hooks do
call
context.called!(self)
end
rescue
context.rollback!
raise
end | Internal: Invoke an Interactor instance along with all defined hooks. The
"run!" method is used internally by the "call!" class method. The following
are equivalent:
MyInteractor.call!(foo: "bar")
# => #<Interactor::Context foo="bar">
interactor = MyInteractor.new(foo: "bar")
interactor.run!
interactor.context
# => #<Interactor::Context foo="bar">
After successful invocation of the interactor, the instance is tracked
within the context. If the context is failed or any error is raised, the
context is rolled back.
The "run!" method behaves identically to the "run" method with one notable
exception. If the context is failed during invocation of the interactor,
the Interactor::Failure is raised.
Returns nothing.
Raises Interactor::Failure if the context is failed. | run! | ruby | collectiveidea/interactor | lib/interactor.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor.rb | MIT |
def failure?
@failure || false
end | Public: Whether the Interactor::Context has failed. By default, a new
context is successful and only changes when explicitly failed.
The "failure?" method is the inverse of the "success?" method.
Examples
context = Interactor::Context.new
# => #<Interactor::Context>
context.failure?
# => false
context.fail!
# => Interactor::Failure: #<Interactor::Context>
context.failure?
# => true
Returns false by default or true if failed. | failure? | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def fail!(context = {})
context.each { |key, value| self[key.to_sym] = value }
@failure = true
raise Failure, self
end | Public: Fail the Interactor::Context. Failing a context raises an error
that may be rescued by the calling interactor. The context is also flagged
as having failed.
Optionally the caller may provide a hash of key/value pairs to be merged
into the context before failure.
context - A Hash whose key/value pairs are merged into the existing
Interactor::Context instance. (default: {})
Examples
context = Interactor::Context.new
# => #<Interactor::Context>
context.fail!
# => Interactor::Failure: #<Interactor::Context>
context.fail! rescue false
# => false
context.fail!(foo: "baz")
# => Interactor::Failure: #<Interactor::Context foo="baz">
Raises Interactor::Failure initialized with the Interactor::Context. | fail! | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def called!(interactor)
_called << interactor
end | Internal: Track that an Interactor has been called. The "called!" method
is used by the interactor being invoked with this context. After an
interactor is successfully called, the interactor instance is tracked in
the context for the purpose of potential future rollback.
interactor - An Interactor instance that has been successfully called.
Returns nothing. | called! | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def rollback!
return false if @rolled_back
_called.reverse_each(&:rollback)
@rolled_back = true
end | Public: Roll back the Interactor::Context. Any interactors to which this
context has been passed and which have been successfully called are asked
to roll themselves back by invoking their "rollback" instance methods.
Examples
context = MyInteractor.call(foo: "bar")
# => #<Interactor::Context foo="baz">
context.rollback!
# => true
context
# => #<Interactor::Context foo="bar">
Returns true if rolled back successfully or false if already rolled back. | rollback! | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def _called
@called ||= []
end | Internal: An Array of successfully called Interactor instances invoked
against this Interactor::Context instance.
Examples
context = Interactor::Context.new
# => #<Interactor::Context>
context._called
# => []
context = MyInteractor.call(foo: "bar")
# => #<Interactor::Context foo="baz">
context._called
# => [#<MyInteractor @context=#<Interactor::Context foo="baz">>]
Returns an Array of Interactor instances or an empty Array. | _called | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def deconstruct_keys(keys)
to_h.merge(
success: success?,
failure: failure?
)
end | Internal: Support for ruby 3.0 pattern matching
Examples
context = MyInteractor.call(foo: "bar")
# => #<Interactor::Context foo="bar">
context => { foo: }
foo == "bar"
# => true
case context
in success: true, result: { first:, second: }
do_stuff(first, second)
in failure: true, error_message:
log_error(message: error_message)
end
Returns the context as a hash, including success and failure | deconstruct_keys | ruby | collectiveidea/interactor | lib/interactor/context.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/context.rb | MIT |
def initialize(context = nil)
@context = context
super
end | Internal: Initialize an Interactor::Failure.
context - An Interactor::Context to be stored within the
Interactor::Failure instance. (default: nil)
Examples
Interactor::Failure.new
# => #<Interactor::Failure: Interactor::Failure>
context = Interactor::Context.new(foo: "bar")
# => #<Interactor::Context foo="bar">
Interactor::Failure.new(context)
# => #<Interactor::Failure: #<Interactor::Context foo="bar">>
raise Interactor::Failure, context
# => Interactor::Failure: #<Interactor::Context foo="bar"> | initialize | ruby | collectiveidea/interactor | lib/interactor/error.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/error.rb | MIT |
def around(*hooks, &block)
hooks << block if block
hooks.each { |hook| around_hooks.push(hook) }
end | Public: Declare hooks to run around Interactor invocation. The around
method may be called multiple times; subsequent calls append declared
hooks to existing around hooks.
hooks - Zero or more Symbol method names representing instance methods
to be called around interactor invocation. Each instance method
invocation receives an argument representing the next link in
the around hook chain.
block - An optional block to be executed as a hook. If given, the block
is executed after methods corresponding to any given Symbols.
Examples
class MyInteractor
include Interactor
around :time_execution
around do |interactor|
puts "started"
interactor.call
puts "finished"
end
def call
puts "called"
end
private
def time_execution(interactor)
context.start_time = Time.now
interactor.call
context.finish_time = Time.now
end
end
Returns nothing. | around | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def before(*hooks, &block)
hooks << block if block
hooks.each { |hook| before_hooks.push(hook) }
end | Public: Declare hooks to run before Interactor invocation. The before
method may be called multiple times; subsequent calls append declared
hooks to existing before hooks.
hooks - Zero or more Symbol method names representing instance methods
to be called before interactor invocation.
block - An optional block to be executed as a hook. If given, the block
is executed after methods corresponding to any given Symbols.
Examples
class MyInteractor
include Interactor
before :set_start_time
before do
puts "started"
end
def call
puts "called"
end
private
def set_start_time
context.start_time = Time.now
end
end
Returns nothing. | before | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def after(*hooks, &block)
hooks << block if block
hooks.each { |hook| after_hooks.unshift(hook) }
end | Public: Declare hooks to run after Interactor invocation. The after
method may be called multiple times; subsequent calls prepend declared
hooks to existing after hooks.
hooks - Zero or more Symbol method names representing instance methods
to be called after interactor invocation.
block - An optional block to be executed as a hook. If given, the block
is executed before methods corresponding to any given Symbols.
Examples
class MyInteractor
include Interactor
after :set_finish_time
after do
puts "finished"
end
def call
puts "called"
end
private
def set_finish_time
context.finish_time = Time.now
end
end
Returns nothing. | after | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def around_hooks
@around_hooks ||= []
end | Internal: An Array of declared hooks to run around Interactor
invocation. The hooks appear in the order in which they will be run.
Examples
class MyInteractor
include Interactor
around :time_execution, :use_transaction
end
MyInteractor.around_hooks
# => [:time_execution, :use_transaction]
Returns an Array of Symbols and Procs. | around_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def before_hooks
@before_hooks ||= []
end | Internal: An Array of declared hooks to run before Interactor
invocation. The hooks appear in the order in which they will be run.
Examples
class MyInteractor
include Interactor
before :set_start_time, :say_hello
end
MyInteractor.before_hooks
# => [:set_start_time, :say_hello]
Returns an Array of Symbols and Procs. | before_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def after_hooks
@after_hooks ||= []
end | Internal: An Array of declared hooks to run before Interactor
invocation. The hooks appear in the order in which they will be run.
Examples
class MyInteractor
include Interactor
after :set_finish_time, :say_goodbye
end
MyInteractor.after_hooks
# => [:say_goodbye, :set_finish_time]
Returns an Array of Symbols and Procs. | after_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def with_hooks
run_around_hooks do
run_before_hooks
yield
run_after_hooks
end
end | Internal: Run around, before and after hooks around yielded execution. The
required block is surrounded with hooks and executed.
Examples
class MyProcessor
include Interactor::Hooks
def process_with_hooks
with_hooks do
process
end
end
def process
puts "processed!"
end
end
Returns nothing. | with_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def run_around_hooks(&block)
self.class.around_hooks.reverse.inject(block) { |chain, hook|
proc { run_hook(hook, chain) }
}.call
end | Internal: Run around hooks.
Returns nothing. | run_around_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def run_hooks(hooks)
hooks.each { |hook| run_hook(hook) }
end | Internal: Run a colection of hooks. The "run_hooks" method is the common
interface by which collections of either before or after hooks are run.
hooks - An Array of Symbol and Proc hooks.
Returns nothing. | run_hooks | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def run_hook(hook, *args)
hook.is_a?(Symbol) ? send(hook, *args) : instance_exec(*args, &hook)
end | Internal: Run an individual hook. The "run_hook" method is the common
interface by which an individual hook is run. If the given hook is a
symbol, the method is invoked whether public or private. If the hook is a
proc, the proc is evaluated in the context of the current instance.
hook - A Symbol or Proc hook.
args - Zero or more arguments to be passed as block arguments into the
given block or as arguments into the method described by the given
Symbol method name.
Returns nothing. | run_hook | ruby | collectiveidea/interactor | lib/interactor/hooks.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb | MIT |
def organize(*interactors)
@organized = interactors.flatten
end | Public: Declare Interactors to be invoked as part of the
Interactor::Organizer's invocation. These interactors are invoked in
the order in which they are declared.
interactors - Zero or more (or an Array of) Interactor classes.
Examples
class MyFirstOrganizer
include Interactor::Organizer
organize InteractorOne, InteractorTwo
end
class MySecondOrganizer
include Interactor::Organizer
organize [InteractorThree, InteractorFour]
end
Returns nothing. | organize | ruby | collectiveidea/interactor | lib/interactor/organizer.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/organizer.rb | MIT |
def organized
@organized ||= []
end | Internal: An Array of declared Interactors to be invoked.
Examples
class MyOrganizer
include Interactor::Organizer
organize InteractorOne, InteractorTwo
end
MyOrganizer.organized
# => [InteractorOne, InteractorTwo]
Returns an Array of Interactor classes or an empty Array. | organized | ruby | collectiveidea/interactor | lib/interactor/organizer.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/organizer.rb | MIT |
def call
self.class.organized.each do |interactor|
interactor.call!(context)
end
end | Internal: Invoke the organized Interactors. An Interactor::Organizer is
expected not to define its own "#call" method in favor of this default
implementation.
Returns nothing. | call | ruby | collectiveidea/interactor | lib/interactor/organizer.rb | https://github.com/collectiveidea/interactor/blob/master/lib/interactor/organizer.rb | MIT |
def start
super
@turn_config = Turn.config
@turn_suite = Turn::TestSuite.new(@turn_config.suite_name)
@test_cases = {}
Runnable.runnables.each do |c|
@test_cases[c] = @turn_suite.new_case(c.name) #Turn::TestCase.new(c)
end
@turn_suite.seed = options[:seed]
@turn_suite.cases = @test_cases.values
@turn_suite.size = @test_cases.size #::MiniTest::Unit::TestCase.test_suites.size
capture_io
#@_stdout, @_stderr = capture_io do
# super_result = super(suite, type)
#end
start_suite(@turn_suite)
end | Minitest's initial hook ran just before testing begins. | start | ruby | turn-project/turn | lib/turn/adapter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/adapter.rb | MIT |
def p(*args)
args.each{ |a| io.print(a.inspect); puts }
end | Stub out the three IO methods used by the built-in reporter. | p | ruby | turn-project/turn | lib/turn/adapter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/adapter.rb | MIT |
def initialize(result)
@result = result
end | Create new TestResult instance.
result - MiniTest's test result object. | initialize | ruby | turn-project/turn | lib/turn/adapter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/adapter.rb | MIT |
def spec?
@is_spec ||= (
Minitest.const_defined?(:Spec) && @result.class < Minitest::Spec
#@result.class.methods.include?(:it) || @result.class.methods.include?('it')
)
end | Is this a Minitest::Spec?
Returns [Boolean]. | spec? | ruby | turn-project/turn | lib/turn/adapter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/adapter.rb | MIT |
def list_option(list)
case list
when nil
[]
when Array
list
else
list.split(/[:;]/)
end
end | Collect test configuation.
def test_configuration(options={})
#options = configure_options(options, 'test')
#options['loadpath'] ||= metadata.loadpath
options['tests'] ||= self.tests
options['loadpath'] ||= self.loadpath
options['requires'] ||= self.requires
options['live'] ||= self.live
options['exclude'] ||= self.exclude
#options['tests'] = list_option(options['tests'])
options['loadpath'] = list_option(options['loadpath'])
options['exclude'] = list_option(options['exclude'])
options['require'] = list_option(options['require'])
return options
end | list_option | ruby | turn-project/turn | lib/turn/configuration.rb | https://github.com/turn-project/turn/blob/master/lib/turn/configuration.rb | MIT |
def reporter
@reporter ||= decorate_reporter(reporter_class.new($stdout, reporter_options))
end | Get selected reporter with any mode decorator. | reporter | ruby | turn-project/turn | lib/turn/configuration.rb | https://github.com/turn-project/turn/blob/master/lib/turn/configuration.rb | MIT |
def reporter_class
rpt_format = format || :pretty
class_name = rpt_format.to_s.capitalize + "Reporter"
path = "turn/reporters/#{rpt_format}_reporter"
[File.expand_path('~'), Dir.pwd].each do |dir|
file = File.join(dir, ".turn", "reporters", "#{rpt_format}_reporter.rb")
path = file if File.exist?(file)
end
require path
Turn.const_get(class_name)
end | Load reporter based on output mode and return its class. | reporter_class | ruby | turn-project/turn | lib/turn/configuration.rb | https://github.com/turn-project/turn/blob/master/lib/turn/configuration.rb | MIT |
def runner
@runner ||= (
require 'turn/runners/minirunner'
case config.runmode
when :marshal
Turn::MiniRunner
when :solo
require 'turn/runners/solorunner'
Turn::SoloRunner
when :cross
require 'turn/runners/crossrunner'
Turn::CrossRunner
else
Turn::MiniRunner
end
)
end | Insatance of Runner, selected based on format and runmode. | runner | ruby | turn-project/turn | lib/turn/controller.rb | https://github.com/turn-project/turn/blob/master/lib/turn/controller.rb | MIT |
def tabto(n)
if self =~ /^( *)\S/
indent(n - $1.length)
else
self
end
end | Preserves relative tabbing.
The first non-empty line ends up with n spaces before nonspace. | tabto | ruby | turn-project/turn | lib/turn/core_ext.rb | https://github.com/turn-project/turn/blob/master/lib/turn/core_ext.rb | MIT |
def indent(n, c=' ')
if n >= 0
gsub(/^/, c * n)
else
gsub(/^#{Regexp.escape(c)}{0,#{-n}}/, "")
end
end | Indent left or right by n spaces.
(This used to be called #tab and aliased as #indent.) | indent | ruby | turn-project/turn | lib/turn/core_ext.rb | https://github.com/turn-project/turn/blob/master/lib/turn/core_ext.rb | MIT |
def naturalized_name(test)
if @natural
test.name.gsub("test_", "").gsub(/_/, " ")
else
test.name
end
end | Returns a more readable test name with spaces instead of underscores | naturalized_name | ruby | turn-project/turn | lib/turn/reporter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/reporter.rb | MIT |
def initialize(name, *files)
@name = name
@files = (files.empty? ? [name] : files)
@tests = []
@message = nil
@count_assertions = 0
#@count_tests = 0
#@count_failures = 0
#@count_errors = 0
#@command = command
end | Command used to run test (optional depending on runner).
attr_accessor :command | initialize | ruby | turn-project/turn | lib/turn/components/case.rb | https://github.com/turn-project/turn/blob/master/lib/turn/components/case.rb | MIT |
def error?
count_errors != 0
end | Whne used by a per-file runner.
alias_method :file, :name
Were there any errors? | error? | ruby | turn-project/turn | lib/turn/components/case.rb | https://github.com/turn-project/turn/blob/master/lib/turn/components/case.rb | MIT |
def counts
return count_tests, count_assertions, count_failures, count_errors ,count_skips
end | Convenience methods --this is what is typcially wanted. | counts | ruby | turn-project/turn | lib/turn/components/suite.rb | https://github.com/turn-project/turn/blob/master/lib/turn/components/suite.rb | MIT |
def finish_suite(suite)
total = suite.count_tests
passes = suite.count_passes
assertions = suite.count_assertions
failures = suite.count_failures
errors = suite.count_errors
skips = suite.count_skips
bar = '=' * 78
bar = passes == total ? Colorize.green(bar) : Colorize.red(bar)
# @FIXME: Should we add suite.runtime, instead if this lame time calculations?
tally = [total, assertions, (Time.new - @time)]
io.puts bar
io.puts " pass: %d, fail: %d, error: %d, skip: %d" % [passes, failures, errors, skips]
io.puts " total: %d tests with %d assertions in %f seconds" % tally
io.puts bar
end | def finish_case(kase)
end
TODO: pending (skip) counts | finish_suite | ruby | turn-project/turn | lib/turn/reporters/outline_reporter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/reporters/outline_reporter.rb | MIT |
def start_suite(suite)
@suite = suite
@time = Time.now
io.puts Colorize.bold("Loaded Suite #{suite.name}")
io.puts
if suite.seed
io.puts "Started at #{Time.now} w/ seed #{suite.seed}."
else
io.puts "Started at #{Time.now}."
end
io.puts
end | TODO: solo and cross runners do not have name or seed, need to fix.
At the very start, before any testcases are run, this is called. | start_suite | ruby | turn-project/turn | lib/turn/reporters/pretty_reporter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/reporters/pretty_reporter.rb | MIT |
def fail(assertion, message=nil)
banner FAIL
prettify(assertion, message)
end | Invoked when a test raises an assertion. | fail | ruby | turn-project/turn | lib/turn/reporters/pretty_reporter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/reporters/pretty_reporter.rb | MIT |
def error(exception, message=nil)
banner ERROR
prettify(exception, message)
end | Invoked when a test raises an exception. | error | ruby | turn-project/turn | lib/turn/reporters/pretty_reporter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/reporters/pretty_reporter.rb | MIT |
def finish_case(kase)
# Print newline if there any tests in suite
io.puts if kase.size > 0
end | Invoked after all tests in a testcase have ben run. | finish_case | ruby | turn-project/turn | lib/turn/reporters/pretty_reporter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/reporters/pretty_reporter.rb | MIT |
def finish_suite(suite)
total = colorize_count("%d tests", suite.count_tests, :bold)
passes = colorize_count("%d passed", suite.count_passes, :pass)
assertions = colorize_count("%d assertions", suite.count_assertions, nil)
failures = colorize_count("%d failures", suite.count_failures, :fail)
errors = colorize_count("%d errors", suite.count_errors, :error)
skips = colorize_count("%d skips", suite.count_skips, :skip)
io.puts "Finished in %.6f seconds." % (Time.now - @time)
io.puts
io.puts [ total, passes, failures, errors, skips, assertions ].join(", ")
# Please keep this newline, since it will be useful when after test case
# there will be other lines. For example "rake aborted!" or kind of.
io.puts
end | After all tests are run, this is the last observable action. | finish_suite | ruby | turn-project/turn | lib/turn/reporters/pretty_reporter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/reporters/pretty_reporter.rb | MIT |
def colorize_count(str, count, colorize_method)
str= str % [count]
str= Colorize.send(colorize_method, str) if colorize_method and count != 0
str
end | Creates an optionally-colorized string describing the number of occurances an event occurred.
@param [String] str A printf-style string that expects an integer argument (i.e. the count)
@param [Integer] count The number of occurances of the event being described.
@param [nil, Symbol] colorize_method The method on Colorize to call in order to apply color to the result, or nil
to not apply any coloring at all. | colorize_count | ruby | turn-project/turn | lib/turn/reporters/pretty_reporter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/reporters/pretty_reporter.rb | MIT |
def banner(event)
name = naturalized_name(@test)
delta = Time.now - @test_time # test runtime
if @verbose
out = "%18s (%0.5fs) (%s) %s" % [event, delta, ticktock, name]
else
out = "%18s (%s) %s" % [event, ticktock, name]
end
if @mark > 0 && delta > @mark
out[1] = Colorize.mark('*')
end
io.puts out
end | TODO: Could also provide % done with time info. But it's already taking up
a lot of screen realestate. Maybe use --verbose flag to offer two forms.
Outputs test case header for given event (error, fail & etc)
Example:
PASS test: Test decription. (0.15s 0:00:02:059) | banner | ruby | turn-project/turn | lib/turn/reporters/pretty_reporter.rb | https://github.com/turn-project/turn/blob/master/lib/turn/reporters/pretty_reporter.rb | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.