repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
partition
stringclasses
1 value
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.modify_host_set
def modify_host_set(name, action = nil, setmembers = nil, new_name = nil, comment = nil) begin @host_set.modify_host_set(name, action, setmembers, new_name, comment) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def modify_host_set(name, action = nil, setmembers = nil, new_name = nil, comment = nil) begin @host_set.modify_host_set(name, action, setmembers, new_name, comment) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "modify_host_set", "(", "name", ",", "action", "=", "nil", ",", "setmembers", "=", "nil", ",", "new_name", "=", "nil", ",", "comment", "=", "nil", ")", "begin", "@host_set", ".", "modify_host_set", "(", "name", ",", "action", ",", "setmembers", ",", "new_name", ",", "comment", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Modifies a HostSet. ==== Attributes * name - Hostset name type name: String * action - Add or Remove host(s) from the set type action: Refer values of Hpe3parSdk::SetCustomAction::MEM_ADD and Hpe3parSdk::SetCustomAction::MEM_REMOVE * setmembers - Host(s) to add to the set, the existence of the host(s) will not be checked type setmembers: Array of String * new_name - New name of set type new_name: String * comment - New comment for the set type comment: String ==== Raises * Hpe3parSdk::HTTPBadRequest - EXISTENT_SET - The set already exits. * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_SET - The set does not exists. * Hpe3parSdk::HTTPConflict - MEMBER_IN_DOMAINSET - The host is in a domain set. * Hpe3parSdk::HTTPConflict - MEMBER_IN_SET - The object is already part of the set. * Hpe3parSdk::HTTPNotFound - MEMBER_NOT_IN_SET - The object is not part of the set. * Hpe3parSdk::HTTPConflict - MEMBER_NOT_IN_SAME_DOMAIN - Objects must be in the same domain to perform this operation. * Hpe3parSdk::HTTPBadRequest - INV_INPUT_DUP_NAME - Invalid input (duplicate name). * Hpe3parSdk::HTTPBadRequest - INV_INPUT_PARAM_CONFLICT - Invalid input (parameters cannot be present at the same time). * Hpe3parSdk::HTTPBadRequest - INV_INPUT_ILLEGAL_CHAR - Invalid contains one or more illegal characters.
[ "Modifies", "a", "HostSet", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1166-L1173
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.find_host_sets
def find_host_sets(host_name) begin @host_set.find_host_sets(host_name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def find_host_sets(host_name) begin @host_set.find_host_sets(host_name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "find_host_sets", "(", "host_name", ")", "begin", "@host_set", ".", "find_host_sets", "(", "host_name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Returns an array of every Hostset the given host is a part of. The array can contain zero, one, or multiple items. ==== Attributes * host_name - The host name of whose hostset is to be found. type host_name: String ==== Returns Array of HostSet.
[ "Returns", "an", "array", "of", "every", "Hostset", "the", "given", "host", "is", "a", "part", "of", ".", "The", "array", "can", "contain", "zero", "one", "or", "multiple", "items", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1219-L1226
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_host_set
def get_host_set(name) begin @host_set.get_host_set(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_host_set(name) begin @host_set.get_host_set(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_host_set", "(", "name", ")", "begin", "@host_set", ".", "get_host_set", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets hostset information by name. ==== Attributes * name - The name of the hostset to find. type name: String ==== Returns HostSet. ==== Raises * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_SET - The set does not exist.
[ "Gets", "hostset", "information", "by", "name", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1243-L1250
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_host_vluns
def get_host_vluns(host_name) begin @host.get_host_vluns(host_name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_host_vluns(host_name) begin @host.get_host_vluns(host_name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_host_vluns", "(", "host_name", ")", "begin", "@host", ".", "get_host_vluns", "(", "host_name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets all of the VLUNs on a specific host. ==== Attributes * host_name - Name of the host. type host_name: String ==== Returns Array of VLUN. ==== Raises * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_HOST - The specified host not found.
[ "Gets", "all", "of", "the", "VLUNs", "on", "a", "specific", "host", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1267-L1274
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_volumes
def get_volumes begin @volume.get_volumes(VolumeCopyType::BASE_VOLUME) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_volumes begin @volume.get_volumes(VolumeCopyType::BASE_VOLUME) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_volumes", "begin", "@volume", ".", "get_volumes", "(", "VolumeCopyType", "::", "BASE_VOLUME", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets all Volumes in the array ==== Returns Array of VirtualVolume
[ "Gets", "all", "Volumes", "in", "the", "array" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1281-L1288
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_snapshots
def get_snapshots begin @volume.get_volumes(VolumeCopyType::VIRTUAL_COPY) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_snapshots begin @volume.get_volumes(VolumeCopyType::VIRTUAL_COPY) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_snapshots", "begin", "@volume", ".", "get_volumes", "(", "VolumeCopyType", "::", "VIRTUAL_COPY", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets the list of snapshots in the array ==== Returns Array of VirtualVolume
[ "Gets", "the", "list", "of", "snapshots", "in", "the", "array" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1295-L1302
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_volume
def get_volume(name) begin @volume.get_volume(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_volume(name) begin @volume.get_volume(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_volume", "(", "name", ")", "begin", "@volume", ".", "get_volume", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets information about a volume by name ==== Attributes * name - The name of the volume to find type name: String ==== Returns VirtualVolume ==== Raises * Hpe3parSdk::HPE3PARException Error with code: 23 message: volume does not exist
[ "Gets", "information", "about", "a", "volume", "by", "name" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1319-L1326
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_volume_by_wwn
def get_volume_by_wwn(wwn) begin @volume.get_volume_by_wwn(wwn) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_volume_by_wwn(wwn) begin @volume.get_volume_by_wwn(wwn) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_volume_by_wwn", "(", "wwn", ")", "begin", "@volume", ".", "get_volume_by_wwn", "(", "wwn", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets information about a volume by wwn ==== Attributes * wwn - The wwn of the volume to find type wwn: String ==== Returns * VirtualVolume ==== Raises * Hpe3parSdk::HPE3PARException Error with code: 23 message: volume does not exist
[ "Gets", "information", "about", "a", "volume", "by", "wwn" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1343-L1350
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.create_volume
def create_volume(name, cpg_name, size_MiB, optional = nil) if @current_version < @min_version_with_compression && !optional.nil? optional.delete_if { |key, _value| key == :compression } end begin @volume.create_volume(name, cpg_name, size_MiB, optional) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def create_volume(name, cpg_name, size_MiB, optional = nil) if @current_version < @min_version_with_compression && !optional.nil? optional.delete_if { |key, _value| key == :compression } end begin @volume.create_volume(name, cpg_name, size_MiB, optional) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "create_volume", "(", "name", ",", "cpg_name", ",", "size_MiB", ",", "optional", "=", "nil", ")", "if", "@current_version", "<", "@min_version_with_compression", "&&", "!", "optional", ".", "nil?", "optional", ".", "delete_if", "{", "|", "key", ",", "_value", "|", "key", "==", ":compression", "}", "end", "begin", "@volume", ".", "create_volume", "(", "name", ",", "cpg_name", ",", "size_MiB", ",", "optional", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Creates a new volume. ==== Attributes * name - the name of the volume type name: String * cpg_name - the name of the destination CPG type cpg_name: String * size_MiB - size in MiB for the volume type size_MiB: Integer * optional - hash of other optional items type optional: hash optional = { 'id' => 12, # Volume ID. If not specified, next # available is chosen 'comment' => 'some comment', # Additional information up to 511 # characters 'policies: { # Specifies VV policies 'staleSS' => false, # True allows stale snapshots. 'oneHost' => true, # True constrains volume export to # single host or host cluster 'zeroDetect' => true, # True requests Storage System to # scan for zeros in incoming write # data 'system' => false, # True special volume used by system # False is normal user volume 'caching' => true}, # Read-only. True indicates write & # read caching & read ahead enabled 'snapCPG' => 'CPG name', # CPG Used for snapshots 'ssSpcAllocWarningPct' => 12, # Snapshot space allocation warning 'ssSpcAllocLimitPct' => 22, # Snapshot space allocation limit 'tpvv' => true, # True: Create TPVV # False (default) Create FPVV 'usrSpcAllocWarningPct' => 22, # Enable user space allocation # warning 'usrSpcAllocLimitPct' => 22, # User space allocation limit 'expirationHours' => 256, # Relative time from now to expire # volume (max 43,800 hours) 'retentionHours' => 256 # Relative time from now to retain } ==== Raises * Hpe3parSdk::HTTPBadRequest - INV_INPUT - Invalid Parameter * Hpe3parSdk::HTTPBadRequest - TOO_LARGE - Volume size above limit * Hpe3parSdk::HTTPBadRequest - NO_SPACE - Not Enough space is available * Hpe3parSdk::HTTPForbidden - PERM_DENIED - Permission denied * Hpe3parSdk::HTTPConflict - EXISTENT_SV - Volume Exists already
[ "Creates", "a", "new", "volume", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1406-L1416
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.modify_volume
def modify_volume(name, volume_mods) begin @volume.modify_volume(name, volume_mods) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def modify_volume(name, volume_mods) begin @volume.modify_volume(name, volume_mods) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "modify_volume", "(", "name", ",", "volume_mods", ")", "begin", "@volume", ".", "modify_volume", "(", "name", ",", "volume_mods", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Modifies a volume ==== Attributes * name - the name of the volume type name: String * volumeMods - Hash of volume attributes to change type volumeMods: Hash volumeMods = { 'newName' => 'newName', # New volume name 'comment' => 'some comment', # New volume comment 'snapCPG' => 'CPG name', # Snapshot CPG name 'policies: { # Specifies VV policies 'staleSS' => false, # True allows stale snapshots. 'oneHost' => true, # True constrains volume export to # single host or host cluster 'zeroDetect' => true, # True requests Storage System to # scan for zeros in incoming write # data 'system' => false, # True special volume used by system # False is normal user volume 'caching' => true}, # Read-only. True indicates write & # read caching & read ahead enabled 'ssSpcAllocWarningPct' => 12, # Snapshot space allocation warning 'ssSpcAllocLimitPct' => 22, # Snapshot space allocation limit 'tpvv' => true, # True: Create TPVV # False: (default) Create FPVV 'usrSpcAllocWarningPct' => 22, # Enable user space allocation # warning 'usrSpcAllocLimitPct' => 22, # User space allocation limit 'userCPG' => 'User CPG name', # User CPG name 'expirationHours' => 256, # Relative time from now to expire # volume (max 43,800 hours) 'retentionHours' => 256, # Relative time from now to retain # volume (max 43,800 hours) 'rmSsSpcAllocWarning' => false, # True removes snapshot space # allocation warning. # False sets it when value > 0 'rmUsrSpcAllocWarwaning' => false,# True removes user space # allocation warning. # False sets it when value > 0 'rmExpTime' => false, # True resets expiration time to 0. # False sets it when value > 0 'rmSsSpcAllocLimit' => false, # True removes snapshot space # allocation limit. # False sets it when value > 0 'rmUsrSpcAllocLimit' => false # True removes user space # allocation limit. # False sets it when value > 0 } ==== Raises: * Hpe3parSdk::HTTPBadRequest - INV_INPUT_WARN_GT_LIMIT - Allocation warning level is higher than the limit. * Hpe3parSdk::HTTPBadRequest - INV_INPUT_USR_ALRT_NON_TPVV - User space allocation alerts are valid only with a TPVV. * Hpe3parSdk::HTTPBadRequest - INV_INPUT_RETAIN_GT_EXPIRE - Retention time is greater than expiration time. * Hpe3parSdk::HTTPBadRequest - INV_INPUT_VV_POLICY - Invalid policy specification (for example, caching or system is set to true). * Hpe3parSdk::HTTPBadRequest - INV_INPUT_EXCEEDS_LENGTH - Invalid input: string length exceeds limit. * Hpe3parSdk::HTTPBadRequest - INV_INPUT_TIME - Invalid time specified. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_MODIFY_USR_CPG_TPVV - usr_cpg cannot be modified on a TPVV. * Hpe3parSdk::HTTPBadRequest - UNLICENSED_FEATURE - Retention time cannot be modified on a system without the Virtual Lock license. * Hpe3parSdk::HTTPForbidden - CPG_NOT_IN_SAME_DOMAIN - Snap CPG is not in the same domain as the user CPG. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_PEER_VOLUME - Cannot modify a peer volume. * Hpe3parSdk::HTTPInternalServerError - INT_SERV_ERR - Metadata of the VV is corrupted. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_SYS_VOLUME - Cannot modify retention time on a system volume. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_INTERNAL_VOLUME - Cannot modify an internal volume * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_VOLUME_NOT_DEFINED_ALL_NODES - Cannot modify a volume until the volume is defined on all volumes. * Hpe3parSdk::HTTPConflict - INVALID_OPERATION_VV_ONLINE_COPY_IN_PROGRESS - Cannot modify a volume when an online copy for that volume is in progress. * Hpe3parSdk::HTTPConflict - INVALID_OPERATION_VV_VOLUME_CONV_IN_PROGRESS - Cannot modify a volume in the middle of a conversion operation. * Hpe3parSdk::HTTPConflict - INVALID_OPERATION_VV_SNAPSPACE_NOT_MOVED_TO_CPG - Snapshot space of a volume needs to be moved to a CPG before the user space. * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_VOLUME_ACCOUNTING_IN_PROGRESS - The volume cannot be renamed until snapshot accounting has finished. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_ZERO_DETECT_TPVV - The zero_detect policy can be used only on TPVVs. * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_CPG_ON_SNAPSHOT - CPG cannot be assigned to a snapshot.
[ "Modifies", "a", "volume" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1558-L1565
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.grow_volume
def grow_volume(name, amount) begin @volume.grow_volume(name, amount) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def grow_volume(name, amount) begin @volume.grow_volume(name, amount) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "grow_volume", "(", "name", ",", "amount", ")", "begin", "@volume", ".", "grow_volume", "(", "name", ",", "amount", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Grows an existing volume by 'amount' Mebibytes. ==== Attributes * name - the name of the volume type name: String * amount: the additional size in MiB to add, rounded up to the next chunklet size (e.g. 256 or 1000 MiB) type amount: Integer ==== Raises: * Hpe3parSdk::HTTPForbidden - VV_NOT_IN_SAME_DOMAIN - The volume is not in the same domain. * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_VOL - The volume does not exist. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_UNSUPPORTED_VV_TYPE - Invalid operation: Cannot grow this type of volume. * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_TUNE_IN_PROGRESS - Invalid operation: Volume tuning is in progress. * Hpe3parSdk::HTTPBadRequest - INV_INPUT_EXCEEDS_LENGTH - Invalid input: String length exceeds limit. * Hpe3parSdk::HTTPBadRequest - INV_INPUT_VV_GROW_SIZE - Invalid grow size. * Hpe3parSdk::HTTPForbidden - VV_NEW_SIZE_EXCEEDS_CPG_LIMIT - New volume size exceeds CPG limit * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_INTERNAL_VOLUME - This operation is not allowed on an internal volume. * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_VOLUME_CONV_IN_PROGRESS - Invalid operation: VV conversion is in progress. * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_VOLUME_COPY_IN_PROGRESS - Invalid operation: online copy is in progress. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_CLEANUP_IN_PROGRESS - Internal volume cleanup is in progress. * Hpe3parSdk::HTTPForbidden - VV_IS_BEING_REMOVED - The volume is being removed. * Hpe3parSdk::HTTPForbidden - VV_IN_INCONSISTENT_STATE - The volume has an internal consistency error. * Hpe3parSdk::HTTPForbidden - VV_SIZE_CANNOT_REDUCE - New volume size is smaller than the current size. * Hpe3parSdk::HTTPForbidden - VV_NEW_SIZE_EXCEEDS_LIMITS - New volume size exceeds the limit. * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_SA_SD_SPACE_REMOVED - Invalid operation: Volume SA/SD space is being removed. * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_IS_BUSY - Invalid operation: Volume is currently busy. * Hpe3parSdk::HTTPForbidden - VV_NOT_STARTED - Volume is not started. * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_IS_PCOPY - Invalid operation: Volume is a physical copy. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_NOT_IN_NORMAL_STATE - Volume state is not normal * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_PROMOTE_IN_PROGRESS - Invalid operation: Volume promotion is in progress. * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_PARENT_OF_PCOPY - Invalid operation: Volume is the parent of physical copy. * Hpe3parSdk::HTTPBadRequest - NO_SPACE - Insufficent space for requested operation.
[ "Grows", "an", "existing", "volume", "by", "amount", "Mebibytes", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1638-L1645
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.create_physical_copy
def create_physical_copy(src_name, dest_name, dest_cpg, optional = nil) if @current_version < @min_version_with_compression && !optional.nil? [:compression, :allowRemoteCopyParent, :skipZero].each { |key| optional.delete key } end begin @volume.create_physical_copy(src_name, dest_name, dest_cpg, optional) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def create_physical_copy(src_name, dest_name, dest_cpg, optional = nil) if @current_version < @min_version_with_compression && !optional.nil? [:compression, :allowRemoteCopyParent, :skipZero].each { |key| optional.delete key } end begin @volume.create_physical_copy(src_name, dest_name, dest_cpg, optional) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "create_physical_copy", "(", "src_name", ",", "dest_name", ",", "dest_cpg", ",", "optional", "=", "nil", ")", "if", "@current_version", "<", "@min_version_with_compression", "&&", "!", "optional", ".", "nil?", "[", ":compression", ",", ":allowRemoteCopyParent", ",", ":skipZero", "]", ".", "each", "{", "|", "key", "|", "optional", ".", "delete", "key", "}", "end", "begin", "@volume", ".", "create_physical_copy", "(", "src_name", ",", "dest_name", ",", "dest_cpg", ",", "optional", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Creates a physical copy of a VirtualVolume ==== Attributes * src_name - the source volume name type src_name: String * dest_name - the destination volume name type dest_name: String * dest_cpg - the destination CPG type dest_cpg: String * optional - Hash of optional parameters type optional: Hash optional = { 'online' => false, # should physical copy be # performed online? 'tpvv' => false, # use thin provisioned space # for destination # (online copy only) 'snapCPG' => 'OpenStack_SnapCPG', # snapshot CPG for the # destination # (online copy only) 'saveSnapshot' => false, # save the snapshot of the # source volume 'priority' => 1 # taskPriorityEnum (does not # apply to online copy - Hpe3parSdk::TaskPriority) }
[ "Creates", "a", "physical", "copy", "of", "a", "VirtualVolume" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1674-L1684
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.delete_physical_copy
def delete_physical_copy(name) begin @volume.delete_volume(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def delete_physical_copy(name) begin @volume.delete_volume(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "delete_physical_copy", "(", "name", ")", "begin", "@volume", ".", "delete_volume", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Deletes a physical copy ==== Attributes * name - the name of the clone volume type name: String ==== Raises: * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_VOL - The volume does not exist * Hpe3parSdk::HTTPForbidden - PERM_DENIED - Permission denied * Hpe3parSdk::HTTPForbidden - RETAINED - Volume retention time has not expired * Hpe3parSdk::HTTPForbidden - HAS_RO_CHILD - Volume has read-only child * Hpe3parSdk::HTTPConflict - HAS_CHILD - The volume has a child volume * Hpe3parSdk::HTTPConflict - IN_USE - The volume is in use by VV set, VLUN, etc
[ "Deletes", "a", "physical", "copy" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1706-L1713
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.tune_volume
def tune_volume(name, tune_operation, optional = nil) if @current_version < @min_version_with_compression && !optional.nil? optional.delete_if { |key, _value| key == :compression } end begin object_hash = @volume.tune_volume(name, tune_operation, optional) get_task(object_hash['taskid']) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def tune_volume(name, tune_operation, optional = nil) if @current_version < @min_version_with_compression && !optional.nil? optional.delete_if { |key, _value| key == :compression } end begin object_hash = @volume.tune_volume(name, tune_operation, optional) get_task(object_hash['taskid']) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "tune_volume", "(", "name", ",", "tune_operation", ",", "optional", "=", "nil", ")", "if", "@current_version", "<", "@min_version_with_compression", "&&", "!", "optional", ".", "nil?", "optional", ".", "delete_if", "{", "|", "key", ",", "_value", "|", "key", "==", ":compression", "}", "end", "begin", "object_hash", "=", "@volume", ".", "tune_volume", "(", "name", ",", "tune_operation", ",", "optional", ")", "get_task", "(", "object_hash", "[", "'taskid'", "]", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Tunes a volume ==== Attributes * name - the volume name type name: String * tune_operation - Enum of tune operation - 1: Change User CPG, 2: Change snap CPG type dest_name: Integer * optional - hash of optional parameters type optional: hash optional = { 'userCPG' => 'user_cpg', # Specifies the new user # CPG to which the volume # will be tuned. 'snapCPG' => 'snap_cpg', # Specifies the snap CPG to # which the volume will be # tuned. 'conversionOperation' => 1, # conversion operation enum. Refer Hpe3parSdk::VolumeConversionOperation 'keepVV' => 'new_volume', # Name of the new volume # where the original logical disks are saved. 'compression' => true # Enables (true) or disables (false) compression. # You cannot compress a fully provisioned volume. }
[ "Tunes", "a", "volume" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1739-L1750
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.find_all_volume_sets
def find_all_volume_sets(name) begin @volume_set.find_all_volume_sets(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def find_all_volume_sets(name) begin @volume_set.find_all_volume_sets(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "find_all_volume_sets", "(", "name", ")", "begin", "@volume_set", ".", "find_all_volume_sets", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Returns an array of every VolumeSet the given volume is a part of. The array can contain zero, one, or multiple items. ==== Attributes * name - the volume name type name: String ==== Returns Array of VolumeSet ==== Raises * Hpe3parSdk::HTTPForbidden - VV_IN_INCONSISTENT_STATE - Internal inconsistency error in vol * Hpe3parSdk::HTTPForbidden - VV_IS_BEING_REMOVED - The volume is being removed * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_VOLUME - The volume does not exists * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_SYS_VOLUME - Illegal op on system vol * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_INTERNAL_VOLUME - Illegal op on internal vol
[ "Returns", "an", "array", "of", "every", "VolumeSet", "the", "given", "volume", "is", "a", "part", "of", ".", "The", "array", "can", "contain", "zero", "one", "or", "multiple", "items", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1776-L1783
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_volume_sets
def get_volume_sets begin @volume_set.get_volume_sets rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_volume_sets begin @volume_set.get_volume_sets rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_volume_sets", "begin", "@volume_set", ".", "get_volume_sets", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets the Volume Sets ==== Returns Array of VolumeSet
[ "Gets", "the", "Volume", "Sets" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1790-L1797
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_volume_set
def get_volume_set(name) begin @volume_set.get_volume_set(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_volume_set(name) begin @volume_set.get_volume_set(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_volume_set", "(", "name", ")", "begin", "@volume_set", ".", "get_volume_set", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets the information about a Volume Set. ==== Attributes * name - The name of the CPG to find type name: String ==== Returns VolumeSet ==== Raises * Hpe3parSdk::HPE3PARException Error with code: 102 message: Set does not exist
[ "Gets", "the", "information", "about", "a", "Volume", "Set", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1814-L1821
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.create_volume_set
def create_volume_set(name, domain = nil, comment = nil, setmembers = nil) begin @volume_set.create_volume_set(name, domain, comment, setmembers) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def create_volume_set(name, domain = nil, comment = nil, setmembers = nil) begin @volume_set.create_volume_set(name, domain, comment, setmembers) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "create_volume_set", "(", "name", ",", "domain", "=", "nil", ",", "comment", "=", "nil", ",", "setmembers", "=", "nil", ")", "begin", "@volume_set", ".", "create_volume_set", "(", "name", ",", "domain", ",", "comment", ",", "setmembers", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Creates a new volume set ==== Attributes * name - the volume set to create type name: String * domain: the domain where the set lives type domain: String * comment: the comment for the vv set type comment: String * setmembers: the vv(s) to add to the set, the existence of the vv(s) will not be checked type name: Array of String ==== Raises * Hpe3parSdk::HTTPBadRequest - INV_INPUT Invalid URI Syntax. * Hpe3parSdk::HTTPBadRequest - NON_EXISTENT_DOMAIN - Domain doesn't exist. * Hpe3parSdk::HTTPBadRequest - NO_SPACE - Not Enough space is available. * Hpe3parSdk::HTTPBadRequest - BAD_CPG_PATTERN A Pattern in a CPG specifies illegal values. * Hpe3parSdk::HTTPForbidden - PERM_DENIED - Permission denied * Hpe3parSdk::HTTPConflict - EXISTENT_CPG - CPG Exists already
[ "Creates", "a", "new", "volume", "set" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1850-L1857
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.delete_volume_set
def delete_volume_set(name) begin @volume_set.delete_volume_set(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def delete_volume_set(name) begin @volume_set.delete_volume_set(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "delete_volume_set", "(", "name", ")", "begin", "@volume_set", ".", "delete_volume_set", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Deletes the volume set. You must clear all QOS rules before a volume set can be deleted. ==== Attributes * name - The name of the VolumeSet type name: String ==== Raises * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_SET - The set does not exists. * Hpe3parSdk::HTTPConflict - - EXPORTED_VLUN - The host set has exported VLUNs. The VV set was exported. * Hpe3parSdk::HTTPConflict - VVSET_QOS_TARGET - The object is already part of the set.
[ "Deletes", "the", "volume", "set", ".", "You", "must", "clear", "all", "QOS", "rules", "before", "a", "volume", "set", "can", "be", "deleted", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1874-L1881
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.modify_volume_set
def modify_volume_set(name, action = nil, newName = nil, comment = nil, flash_cache_policy = nil, setmembers = nil) begin @volume_set.modify_volume_set(name, action, newName, comment, flash_cache_policy, setmembers) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def modify_volume_set(name, action = nil, newName = nil, comment = nil, flash_cache_policy = nil, setmembers = nil) begin @volume_set.modify_volume_set(name, action, newName, comment, flash_cache_policy, setmembers) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "modify_volume_set", "(", "name", ",", "action", "=", "nil", ",", "newName", "=", "nil", ",", "comment", "=", "nil", ",", "flash_cache_policy", "=", "nil", ",", "setmembers", "=", "nil", ")", "begin", "@volume_set", ".", "modify_volume_set", "(", "name", ",", "action", ",", "newName", ",", "comment", ",", "flash_cache_policy", ",", "setmembers", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Modifies a volume set by adding or removing a volume from the volume set. It's actions is based on the enums MEM_ADD or MEM_REMOVE. ==== Attributes * action: add or remove volume from the set type name: Hpe3parSdk::SetCustomAction * name: the volume set name type name: String * newName: new name of set type newName: String * comment: the comment for on the vv set type comment: String * flash_cache_policy: the flash-cache policy for the vv set type flash_cache_policy: enum * setmembers: the vv to add to the set, the existence of the vv will not be checked type name: Array of String ==== Raises * Hpe3parSdk::HTTPBadRequest - EXISTENT_SET - The set already exits. * Hpe3parSdk::HTTPBadRequest - EXISTENT_SET - The set already exits. * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_SET - The set does not exists. * Hpe3parSdk::HTTPConflict - MEMBER_IN_DOMAINSET - The host is in a domain set. * Hpe3parSdk::HTTPConflict - MEMBER_IN_SET - The object is already part of the set. * Hpe3parSdk::HTTPNotFound - MEMBER_NOT_IN_SET - The object is not part of the set. * Hpe3parSdk::HTTPConflict - MEMBER_NOT_IN_SAME_DOMAIN - Objects must be in the same domain to perform this operation. * Hpe3parSdk::HTTPForbidden - VV_IN_INCONSISTENT_STATE - The volume has an internal inconsistency error. * Hpe3parSdk::HTTPForbidden - VV_IS_BEING_REMOVED - The volume is being removed. * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_VOLUME - The volume does not exists. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_SYS_VOLUME - The operation is not allowed on a system volume. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_INTERNAL_VOLUME - The operation is not allowed on an internal volume. * Hpe3parSdk::HTTPBadRequest - INV_INPUT_DUP_NAME - Invalid input (duplicate name). * Hpe3parSdk::HTTPBadRequest - INV_INPUT_PARAM_CONFLICT - Invalid input (parameters cannot be present at the same time). * Hpe3parSdk::HTTPBadRequest - INV_INPUT_ILLEGAL_CHAR - Invalid contains one or more illegal characters.
[ "Modifies", "a", "volume", "set", "by", "adding", "or", "removing", "a", "volume", "from", "the", "volume", "set", ".", "It", "s", "actions", "is", "based", "on", "the", "enums", "MEM_ADD", "or", "MEM_REMOVE", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L1939-L1946
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.create_snapshot_of_volume_set
def create_snapshot_of_volume_set(name, copy_of_name, optional = nil) begin @volume_set.create_snapshot_of_volume_set(name, copy_of_name, optional) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def create_snapshot_of_volume_set(name, copy_of_name, optional = nil) begin @volume_set.create_snapshot_of_volume_set(name, copy_of_name, optional) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "create_snapshot_of_volume_set", "(", "name", ",", "copy_of_name", ",", "optional", "=", "nil", ")", "begin", "@volume_set", ".", "create_snapshot_of_volume_set", "(", "name", ",", "copy_of_name", ",", "optional", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Creates a snapshot of an existing VolumeSet ==== Attributes * name: Name of the Snapshot. The vvname pattern is described in "VV Name Patterns" in the HPE 3PAR Command Line Interface Reference, which is available at the following website: http://www.hp.com/go/storage/docs type name: String * copy_of_name: the name of the parent volume type copy_of_name: String * comment: the comment on the vv set type comment: String * optional: Hash of optional params type optional: Hash optional = { 'id' => 12, # Specifies ID of the volume set # set, next by default 'comment' => "some comment", 'readOnly' => true, # Read Only 'expirationHours' => 36, # time from now to expire 'retentionHours' => 12 # time from now to expire } ==== Raises * Hpe3parSdk::HTTPBadRequest - INVALID_INPUT_VV_PATTERN - Invalid volume pattern specified * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_SET - The set does not exists. * Hpe3parSdk::HTTPNotFound - EMPTY_SET - The set is empty * Hpe3parSdk::HTTPServiceUnavailable - VV_LIMIT_REACHED - Maximum number of volumes reached * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_VOL - The storage volume does not exist * Hpe3parSdk::HTTPForbidden - VV_IS_BEING_REMOVED - The volume is being removed * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_READONLY_TO_READONLY_SNAP - Creating a read-only copy from a read-only volume is not permitted * Hpe3parSdk::HTTPConflict - NO_SNAP_CPG - No snapshot CPG has been configured for the volume * Hpe3parSdk::HTTPBadRequest - INV_INPUT_DUP_NAME - Invalid input (duplicate name). * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_SNAP_PARENT_SAME_BASE - Two parent snapshots share the same base volume * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_ONLINE_COPY_IN_PROGRESS - Invalid operation. Online copyis in progress * Hpe3parSdk::HTTPServiceUnavailable - VV_ID_LIMIT_REACHED - Max number of volumeIDs has been reached * Hpe3parSdk::HTTPNotFound - NON_EXISTENT_VOLUME - The volume does not exists * Hpe3parSdk::HTTPForbidden - VV_IN_STALE_STATE - The volume is in a stale state. * Hpe3parSdk::HTTPForbidden - VV_NOT_STARTED - Volume is not started * Hpe3parSdk::HTTPForbidden - VV_UNAVAILABLE - The volume is not accessible * Hpe3parSdk::HTTPServiceUnavailable - SNAPSHOT_LIMIT_REACHED - Max number of snapshots has been reached * Hpe3parSdk::HTTPServiceUnavailable - CPG_ALLOCATION_WARNING_REACHED - The CPG has reached the allocation warning * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_VOLUME_CONV_IN_PROGRESS - Invalid operation: VV conversion is in progress. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_CLEANUP_IN_PROGRESS - Internal volume cleanup is in progress. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_PEER_VOLUME - Cannot modify a peer volume. * Hpe3parSdk::HTTPConflict - INV_OPERATION_VV_VOLUME_CONV_IN_PROGRESS - INV_OPERATION_VV_ONLINE_COPY_IN_PROGRESS - The volume is the target of an online copy. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_INTERNAL_VOLUME - Illegal op on internal vol * Hpe3parSdk::HTTPConflict - EXISTENT_ID - An ID exists * Hpe3parSdk::HTTPForbidden - INV_OPERATION_VV_NOT_IN_NORMAL_STATE - Volume state is not normal * Hpe3parSdk::HTTPForbidden - VV_IN_INCONSISTENT_STATE - Internal inconsistency error in vol * Hpe3parSdk::HTTPBadRequest - INVALID_INPUT_VV_PATTERN - - INV_INPUT_RETAIN_GT_EXPIRE - Retention time is greater than expiration time. * Hpe3parSdk::HTTPBadRequest - INV_INPUT_TIME - Invalid time specified. * Hpe3parSdk::HTTPForbidden - INV_OPERATION_SNAPSHOT_NOT_SAME_TYPE - Some snapshots in the volume set are read-only, some are read-write
[ "Creates", "a", "snapshot", "of", "an", "existing", "VolumeSet" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2064-L2071
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.create_snapshot
def create_snapshot(name, copy_of_name, optional = nil) if @current_version < @min_version_with_compression && !optional.nil? optional.delete_if { |key, _value| key == :allowRemoteCopyParent } end begin @volume.create_snapshot(name, copy_of_name, optional) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def create_snapshot(name, copy_of_name, optional = nil) if @current_version < @min_version_with_compression && !optional.nil? optional.delete_if { |key, _value| key == :allowRemoteCopyParent } end begin @volume.create_snapshot(name, copy_of_name, optional) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "create_snapshot", "(", "name", ",", "copy_of_name", ",", "optional", "=", "nil", ")", "if", "@current_version", "<", "@min_version_with_compression", "&&", "!", "optional", ".", "nil?", "optional", ".", "delete_if", "{", "|", "key", ",", "_value", "|", "key", "==", ":allowRemoteCopyParent", "}", "end", "begin", "@volume", ".", "create_snapshot", "(", "name", ",", "copy_of_name", ",", "optional", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Creates a snapshot of an existing Volume. ==== Attributes * name - the name of the Snapshot type name: String * copy_of_name - the name of the parent volume type copy_of_name: String * optional - Hash of other optional items type optional: Hash optional = { 'id' => 12, # Specifies the ID of the volume, # next by default 'comment' => "some comment", 'readOnly' => true, # Read Only 'expirationHours' => 36, # time from now to expire 'retentionHours' => 12 # time from now to expire } ==== Raises * Hpe3parSdk::HTTPNotFound - INON_EXISTENT_VOL - The volume does not exist * Hpe3parSdk::HTTPForbidden - PERM_DENIED - Permission denied
[ "Creates", "a", "snapshot", "of", "an", "existing", "Volume", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2099-L2109
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_volume_snapshots
def get_volume_snapshots(name) begin @volume.get_volume_snapshots(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_volume_snapshots(name) begin @volume.get_volume_snapshots(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_volume_snapshots", "(", "name", ")", "begin", "@volume", ".", "get_volume_snapshots", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets the snapshots of a particular volume ==== Attributes * name - the name of the volume type name: String ==== Returns Array of VirtualVolume
[ "Gets", "the", "snapshots", "of", "a", "particular", "volume" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2192-L2199
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_ports
def get_ports begin @port.get_ports rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_ports begin @port.get_ports rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_ports", "begin", "@port", ".", "get_ports", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets an array of all ports on the 3PAR. ==== Returns Array of Port.
[ "Gets", "an", "array", "of", "all", "ports", "on", "the", "3PAR", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2206-L2213
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_fc_ports
def get_fc_ports(state = nil) begin @port.get_fc_ports(state) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_fc_ports(state = nil) begin @port.get_fc_ports(state) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_fc_ports", "(", "state", "=", "nil", ")", "begin", "@port", ".", "get_fc_ports", "(", "state", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets an array of Fibre Channel Ports. * state - Port link state. type name: Integer. Refer Hpe3parSdk::PortLinkState for complete enumeration. ==== Returns Array of Fibre Channel Port.
[ "Gets", "an", "array", "of", "Fibre", "Channel", "Ports", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2223-L2230
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_iscsi_ports
def get_iscsi_ports(state = nil) begin @port.get_iscsi_ports(state) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_iscsi_ports(state = nil) begin @port.get_iscsi_ports(state) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_iscsi_ports", "(", "state", "=", "nil", ")", "begin", "@port", ".", "get_iscsi_ports", "(", "state", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets an array of iSCSI Ports. * state - Port link state. type name: Integer. Refer Hpe3parSdk::PortLinkState for complete enumeration. ==== Returns Array of iSCSI Port.
[ "Gets", "an", "array", "of", "iSCSI", "Ports", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2240-L2247
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_ip_ports
def get_ip_ports(state = nil) begin @port.get_ip_ports(state) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_ip_ports(state = nil) begin @port.get_ip_ports(state) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_ip_ports", "(", "state", "=", "nil", ")", "begin", "@port", ".", "get_ip_ports", "(", "state", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets an array of IP Ports. ==== Attributes * state - Port link state. type name: Integer. Refer Hpe3parSdk::PortLinkState for complete enumeration. ==== Returns Array of IP Port.
[ "Gets", "an", "array", "of", "IP", "Ports", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2259-L2266
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_cpgs
def get_cpgs begin @cpg.get_cpgs rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_cpgs begin @cpg.get_cpgs rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_cpgs", "begin", "@cpg", ".", "get_cpgs", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets entire list of CPGs. ==== Returns CPG array
[ "Gets", "entire", "list", "of", "CPGs", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2273-L2280
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_cpg
def get_cpg(name) begin @cpg.get_cpg(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_cpg(name) begin @cpg.get_cpg(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_cpg", "(", "name", ")", "begin", "@cpg", ".", "get_cpg", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets information about a Cpg. ==== Attributes * name - The name of the cpg to find type name: String ==== Returns CPG ==== Raises * Hpe3parSdk::HPE3PARException Error with code: 15 message: cpg does not exist
[ "Gets", "information", "about", "a", "Cpg", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2297-L2304
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.create_cpg
def create_cpg(name, optional = nil) begin @cpg.create_cpg(name, optional) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def create_cpg(name, optional = nil) begin @cpg.create_cpg(name, optional) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "create_cpg", "(", "name", ",", "optional", "=", "nil", ")", "begin", "@cpg", ".", "create_cpg", "(", "name", ",", "optional", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Creates a new CPG. ==== Attributes * name - Name of the cpg type name: String * optional - Hash of other optional items type optional: Hash optional = { 'growthIncrementMiB' 100, # Growth increment in MiB for # each auto-grown operation 'growthLimitMiB': 1024, # Auto-grow operation is limited # to specified storage amount 'usedLDWarningAlertMiB': 200, # Threshold to trigger warning # of used logical disk space 'domain': 'MyDomain', # Name of the domain object 'LDLayout': { 'RAIDType': 1, # Disk Raid Type 'setSize': 100, # Size in number of chunklets 'HA': 0, # Layout supports failure of # one port pair (1), # one cage (2), # or one magazine (3) 'chunkletPosPref': 2, # Chunklet location perference # characteristics. # Lowest Number/Fastest transfer # = 1 # Higher Number/Slower transfer # = 2 'diskPatterns': []} # Patterns for candidate disks } ==== Raises * Hpe3parSdk::HTTPBadRequest - INV_INPUT Invalid URI Syntax. * Hpe3parSdk::HTTPBadRequest - NON_EXISTENT_DOMAIN - Domain doesn't exist. * Hpe3parSdk::HTTPBadRequest - NO_SPACE - Not Enough space is available. * Hpe3parSdk::HTTPBadRequest - BAD_CPG_PATTERN A Pattern in a CPG specifies illegal values. * Hpe3parSdk::HTTPForbidden - PERM_DENIED - Permission denied * Hpe3parSdk::HTTPConflict - EXISTENT_CPG - Cpg Exists already
[ "Creates", "a", "new", "CPG", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2353-L2360
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.modify_cpg
def modify_cpg(name, cpg_mods) begin @cpg.modify_cpg(name, cpg_mods) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def modify_cpg(name, cpg_mods) begin @cpg.modify_cpg(name, cpg_mods) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "modify_cpg", "(", "name", ",", "cpg_mods", ")", "begin", "@cpg", ".", "modify_cpg", "(", "name", ",", "cpg_mods", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Modifies a CPG. ==== Attributes * name - Name of the CPG type name: String * optional - hash of other optional items type optional: Hash optional = { 'newName'=> "newCPG:, # Specifies the name of the # CPG to update. 'disableAutoGrow'=>false, # Enables (false) or # disables (true) CPG auto # grow. Defaults to false. 'rmGrowthLimit'=> false, # Enables (false) or # disables (true) auto grow # limit enforcement. Defaults # to false. 'rmWarningAlert'=> false, # Enables (false) or # disables (true) warning # limit enforcement. Defaults # to false. }
[ "Modifies", "a", "CPG", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2387-L2394
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_cpg_available_space
def get_cpg_available_space(name) begin @cpg.get_cpg_available_space(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_cpg_available_space(name) begin @cpg.get_cpg_available_space(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_cpg_available_space", "(", "name", ")", "begin", "@cpg", ".", "get_cpg_available_space", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets available space information about a cpg. ==== Attributes * name - The name of the cpg to find type name: String ==== Returns Available space details in form of LDLayoutCapacity object ==== Raises * Hpe3parSdk::HPE3PARException Error with code: 15 message: cpg does not exist
[ "Gets", "available", "space", "information", "about", "a", "cpg", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2411-L2418
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.delete_cpg
def delete_cpg(name) begin @cpg.delete_cpg(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def delete_cpg(name) begin @cpg.delete_cpg(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "delete_cpg", "(", "name", ")", "begin", "@cpg", ".", "delete_cpg", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Deletes a CPG. ==== Attributes * name - The name of the CPG type name: String ==== Raises * Hpe3parSdk::HPE3PARException Error with code: 15 message: CPG does not exist * Hpe3parSdk::HTTPForbidden - IN_USE - The CPG Cannot be removed because it's in use. * Hpe3parSdk::HTTPForbidden - PERM_DENIED - Permission denied
[ "Deletes", "a", "CPG", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2435-L2442
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.get_online_physical_copy_status
def get_online_physical_copy_status(name) begin @volume.get_online_physical_copy_status(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def get_online_physical_copy_status(name) begin @volume.get_online_physical_copy_status(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "get_online_physical_copy_status", "(", "name", ")", "begin", "@volume", ".", "get_online_physical_copy_status", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Gets the status of an online physical copy ==== Attributes * name - The name of the volume type name: str ==== Returns Status of online copy (String) ==== Raises * Hpe3parSdk::HPE3PARException Error: message: Volume not an online physical copy
[ "Gets", "the", "status", "of", "an", "online", "physical", "copy" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2459-L2466
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.stop_offline_physical_copy
def stop_offline_physical_copy(name) begin @volume.stop_offline_physical_copy(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def stop_offline_physical_copy(name) begin @volume.stop_offline_physical_copy(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "stop_offline_physical_copy", "(", "name", ")", "begin", "@volume", ".", "stop_offline_physical_copy", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Stops an offline physical copy operation ==== Attributes * name - The name of the volume type name: String
[ "Stops", "an", "offline", "physical", "copy", "operation" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2474-L2481
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.stop_online_physical_copy
def stop_online_physical_copy(name) begin @volume.stop_online_physical_copy(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def stop_online_physical_copy(name) begin @volume.stop_online_physical_copy(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "stop_online_physical_copy", "(", "name", ")", "begin", "@volume", ".", "stop_online_physical_copy", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Stops an online physical copy operation ==== Attributes * name - The name of the volume type name: String
[ "Stops", "an", "online", "physical", "copy", "operation" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2489-L2496
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.resync_physical_copy
def resync_physical_copy(name) begin @volume.resync_physical_copy(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def resync_physical_copy(name) begin @volume.resync_physical_copy(name) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "resync_physical_copy", "(", "name", ")", "begin", "@volume", ".", "resync_physical_copy", "(", "name", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Resynchronizes a physical copy. ==== Attributes * name - The name of the volume type name: String
[ "Resynchronizes", "a", "physical", "copy", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2504-L2511
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.wait_for_task_to_end
def wait_for_task_to_end(task_id, poll_rate_secs = 15) begin @task.wait_for_task_to_end(task_id, poll_rate_secs) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def wait_for_task_to_end(task_id, poll_rate_secs = 15) begin @task.wait_for_task_to_end(task_id, poll_rate_secs) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "wait_for_task_to_end", "(", "task_id", ",", "poll_rate_secs", "=", "15", ")", "begin", "@task", ".", "wait_for_task_to_end", "(", "task_id", ",", "poll_rate_secs", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Waits for a 3PAR task to end. ==== Attributes * task_id - The Id of the task to be waited upon. type task_id: Integer * poll_rate_secs - The polling interval in seconds. type poll_rate_secs: Integer
[ "Waits", "for", "a", "3PAR", "task", "to", "end", "." ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2521-L2528
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.cancel_task
def cancel_task(task_id) begin @task.cancel_task(task_id) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
ruby
def cancel_task(task_id) begin @task.cancel_task(task_id) rescue => ex Util.log_exception(ex, caller_locations(1, 1)[0].label) raise ex end end
[ "def", "cancel_task", "(", "task_id", ")", "begin", "@task", ".", "cancel_task", "(", "task_id", ")", "rescue", "=>", "ex", "Util", ".", "log_exception", "(", "ex", ",", "caller_locations", "(", "1", ",", "1", ")", "[", "0", "]", ".", "label", ")", "raise", "ex", "end", "end" ]
Cancel a 3PAR task ==== Attributes * task_id - The Id of the task to be cancelled. type task_id: Integer ==== Raises * Hpe3parSdk::HTTPBadRequest - NON_ACTIVE_TASK - The task is not active at this time. * Hpe3parSdk::HTTPConflict - INV_OPERATION_CANNOT_CANCEL_ TASK - Invalid operation: Task cannot be cancelled.
[ "Cancel", "a", "3PAR", "task" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2542-L2549
train
HewlettPackard/hpe3par_ruby_sdk
lib/Hpe3parSdk/client.rb
Hpe3parSdk.Client.logout
def logout unless @log_file_path.nil? if Hpe3parSdk.logger != nil Hpe3parSdk.logger.close Hpe3parSdk.logger = nil end end begin @http.unauthenticate rescue Hpe3parSdk::HPE3PARException => ex #Do nothing end end
ruby
def logout unless @log_file_path.nil? if Hpe3parSdk.logger != nil Hpe3parSdk.logger.close Hpe3parSdk.logger = nil end end begin @http.unauthenticate rescue Hpe3parSdk::HPE3PARException => ex #Do nothing end end
[ "def", "logout", "unless", "@log_file_path", ".", "nil?", "if", "Hpe3parSdk", ".", "logger", "!=", "nil", "Hpe3parSdk", ".", "logger", ".", "close", "Hpe3parSdk", ".", "logger", "=", "nil", "end", "end", "begin", "@http", ".", "unauthenticate", "rescue", "Hpe3parSdk", "::", "HPE3PARException", "=>", "ex", "end", "end" ]
Logout from the 3PAR Array
[ "Logout", "from", "the", "3PAR", "Array" ]
f8cfc6e597741be593cf7fe013accadf982ee68b
https://github.com/HewlettPackard/hpe3par_ruby_sdk/blob/f8cfc6e597741be593cf7fe013accadf982ee68b/lib/Hpe3parSdk/client.rb#L2633-L2645
train
blythedunham/health_monitor
lib/health_monitor/built_in_checks.rb
HealthMonitor.BuiltInChecks.ey_agent_check
def ey_agent_check results = { :description => 'Run ey-agent to monitor haproxy and monitor' } agent_results = JSON.load( `sudo ey-agent` ) results.update( :message => agent_results.inspect, :status => agent_results && agent_results.any?{|k,v| v == 'down' } ) rescue => e return results.update( :status => :failure, :exception => e ) end
ruby
def ey_agent_check results = { :description => 'Run ey-agent to monitor haproxy and monitor' } agent_results = JSON.load( `sudo ey-agent` ) results.update( :message => agent_results.inspect, :status => agent_results && agent_results.any?{|k,v| v == 'down' } ) rescue => e return results.update( :status => :failure, :exception => e ) end
[ "def", "ey_agent_check", "results", "=", "{", ":description", "=>", "'Run ey-agent to monitor haproxy and monitor'", "}", "agent_results", "=", "JSON", ".", "load", "(", "`", "`", ")", "results", ".", "update", "(", ":message", "=>", "agent_results", ".", "inspect", ",", ":status", "=>", "agent_results", "&&", "agent_results", ".", "any?", "{", "|", "k", ",", "v", "|", "v", "==", "'down'", "}", ")", "rescue", "=>", "e", "return", "results", ".", "update", "(", ":status", "=>", ":failure", ",", ":exception", "=>", "e", ")", "end" ]
Call ey-agent to return nginx or apache status as well as database status
[ "Call", "ey", "-", "agent", "to", "return", "nginx", "or", "apache", "status", "as", "well", "as", "database", "status" ]
de41ae1204ff8d88d20e134c280e70d618d60dfc
https://github.com/blythedunham/health_monitor/blob/de41ae1204ff8d88d20e134c280e70d618d60dfc/lib/health_monitor/built_in_checks.rb#L49-L62
train
blythedunham/health_monitor
lib/health_monitor/health_monitoring.rb
HealthMonitor.HealthMonitoring.monitor_health
def monitor_health find_features @results = @features.inject({}) do |results, feature_name| results[ feature_name ] = monitor_health_of( feature_name ) results end healthy? ? on_healthy : on_unhealthy render_health end
ruby
def monitor_health find_features @results = @features.inject({}) do |results, feature_name| results[ feature_name ] = monitor_health_of( feature_name ) results end healthy? ? on_healthy : on_unhealthy render_health end
[ "def", "monitor_health", "find_features", "@results", "=", "@features", ".", "inject", "(", "{", "}", ")", "do", "|", "results", ",", "feature_name", "|", "results", "[", "feature_name", "]", "=", "monitor_health_of", "(", "feature_name", ")", "results", "end", "healthy?", "?", "on_healthy", ":", "on_unhealthy", "render_health", "end" ]
Show a status page showing the health of monitored features Returns a 404 if any features have a success of unsuccessful Skip features: z2live.com/health/status?skip=mongo,mysql Include features: z2live.com/health/status?feature=mongo
[ "Show", "a", "status", "page", "showing", "the", "health", "of", "monitored", "features", "Returns", "a", "404", "if", "any", "features", "have", "a", "success", "of", "unsuccessful" ]
de41ae1204ff8d88d20e134c280e70d618d60dfc
https://github.com/blythedunham/health_monitor/blob/de41ae1204ff8d88d20e134c280e70d618d60dfc/lib/health_monitor/health_monitoring.rb#L188-L196
train
blythedunham/health_monitor
lib/health_monitor/health_monitoring.rb
HealthMonitor.HealthMonitoring.render_health
def render_health return if performed? respond_to do |format| format.html { render_health_html } format.js { render_health_json } format.xml { render_health_xml } end end
ruby
def render_health return if performed? respond_to do |format| format.html { render_health_html } format.js { render_health_json } format.xml { render_health_xml } end end
[ "def", "render_health", "return", "if", "performed?", "respond_to", "do", "|", "format", "|", "format", ".", "html", "{", "render_health_html", "}", "format", ".", "js", "{", "render_health_json", "}", "format", ".", "xml", "{", "render_health_xml", "}", "end", "end" ]
Render the result
[ "Render", "the", "result" ]
de41ae1204ff8d88d20e134c280e70d618d60dfc
https://github.com/blythedunham/health_monitor/blob/de41ae1204ff8d88d20e134c280e70d618d60dfc/lib/health_monitor/health_monitoring.rb#L257-L265
train
blythedunham/health_monitor
lib/health_monitor/health_monitoring.rb
HealthMonitor.HealthMonitoring.find_features
def find_features @features = if params[ :only ] params[ :only ].to_s.split( "," ).collect( &:to_sym ).uniq elsif skip = params[ :skip ] || params[ :exclude ] monitored_features.keys - skip.to_s.split( "," ).collect( &:to_sym ) else monitored_features.keys end end
ruby
def find_features @features = if params[ :only ] params[ :only ].to_s.split( "," ).collect( &:to_sym ).uniq elsif skip = params[ :skip ] || params[ :exclude ] monitored_features.keys - skip.to_s.split( "," ).collect( &:to_sym ) else monitored_features.keys end end
[ "def", "find_features", "@features", "=", "if", "params", "[", ":only", "]", "params", "[", ":only", "]", ".", "to_s", ".", "split", "(", "\",\"", ")", ".", "collect", "(", "&", ":to_sym", ")", ".", "uniq", "elsif", "skip", "=", "params", "[", ":skip", "]", "||", "params", "[", ":exclude", "]", "monitored_features", ".", "keys", "-", "skip", ".", "to_s", ".", "split", "(", "\",\"", ")", ".", "collect", "(", "&", ":to_sym", ")", "else", "monitored_features", ".", "keys", "end", "end" ]
Skip features by appending skip=mongo,fun,etc Include features by appending feature=mongo,urban_airship,etc to filter
[ "Skip", "features", "by", "appending", "skip", "=", "mongo", "fun", "etc", "Include", "features", "by", "appending", "feature", "=", "mongo", "urban_airship", "etc", "to", "filter" ]
de41ae1204ff8d88d20e134c280e70d618d60dfc
https://github.com/blythedunham/health_monitor/blob/de41ae1204ff8d88d20e134c280e70d618d60dfc/lib/health_monitor/health_monitoring.rb#L271-L281
train
cloudfoundry-attic/vmc
lib/vmc/cli/app/start.rb
VMC::App.Start.switch_mode
def switch_mode(app, mode) mode = nil if mode == "none" mode = "run" if mode == "" # no value given return false if app.debug == mode if mode.nil? with_progress("Removing debug mode") do app.debug = nil app.stop! if app.started? end return true end with_progress("Switching mode to #{c(mode, :name)}") do |s| app.debug = mode app.stop! if app.started? end end
ruby
def switch_mode(app, mode) mode = nil if mode == "none" mode = "run" if mode == "" # no value given return false if app.debug == mode if mode.nil? with_progress("Removing debug mode") do app.debug = nil app.stop! if app.started? end return true end with_progress("Switching mode to #{c(mode, :name)}") do |s| app.debug = mode app.stop! if app.started? end end
[ "def", "switch_mode", "(", "app", ",", "mode", ")", "mode", "=", "nil", "if", "mode", "==", "\"none\"", "mode", "=", "\"run\"", "if", "mode", "==", "\"\"", "return", "false", "if", "app", ".", "debug", "==", "mode", "if", "mode", ".", "nil?", "with_progress", "(", "\"Removing debug mode\"", ")", "do", "app", ".", "debug", "=", "nil", "app", ".", "stop!", "if", "app", ".", "started?", "end", "return", "true", "end", "with_progress", "(", "\"Switching mode to #{c(mode, :name)}\"", ")", "do", "|", "s", "|", "app", ".", "debug", "=", "mode", "app", ".", "stop!", "if", "app", ".", "started?", "end", "end" ]
set app debug mode, ensuring it's valid, and shutting it down
[ "set", "app", "debug", "mode", "ensuring", "it", "s", "valid", "and", "shutting", "it", "down" ]
87528848570e3ffe58a57ce9a804abec6bdecc5a
https://github.com/cloudfoundry-attic/vmc/blob/87528848570e3ffe58a57ce9a804abec6bdecc5a/lib/vmc/cli/app/start.rb#L66-L85
train
lenovo/xclarity_client
lib/xclarity_client/services/xclarity_management_mixin.rb
XClarityClient.ManagementMixin.add_listname_on_body
def add_listname_on_body(resource, body) body.kind_of?(Array) ? process_body_as_array(resource, body) : process_body_as_hash(resource, body) end
ruby
def add_listname_on_body(resource, body) body.kind_of?(Array) ? process_body_as_array(resource, body) : process_body_as_hash(resource, body) end
[ "def", "add_listname_on_body", "(", "resource", ",", "body", ")", "body", ".", "kind_of?", "(", "Array", ")", "?", "process_body_as_array", "(", "resource", ",", "body", ")", ":", "process_body_as_hash", "(", "resource", ",", "body", ")", "end" ]
Process the response body to make sure that its contains the list name defined on resource Returns the list name present on body and the body itself
[ "Process", "the", "response", "body", "to", "make", "sure", "that", "its", "contains", "the", "list", "name", "defined", "on", "resource", "Returns", "the", "list", "name", "present", "on", "body", "and", "the", "body", "itself" ]
42a9cd16617302c028190de8b3d50abd134dd61f
https://github.com/lenovo/xclarity_client/blob/42a9cd16617302c028190de8b3d50abd134dd61f/lib/xclarity_client/services/xclarity_management_mixin.rb#L155-L157
train
lenovo/xclarity_client
lib/xclarity_client/services/xclarity_management_mixin.rb
XClarityClient.ManagementMixin.any_listname_of
def any_listname_of(resource) if resource::LIST_NAME.kind_of?(Array) resource::LIST_NAME.first # If is an array, any listname can be use else resource::LIST_NAME # If is not an array, just return the listname of resource end end
ruby
def any_listname_of(resource) if resource::LIST_NAME.kind_of?(Array) resource::LIST_NAME.first # If is an array, any listname can be use else resource::LIST_NAME # If is not an array, just return the listname of resource end end
[ "def", "any_listname_of", "(", "resource", ")", "if", "resource", "::", "LIST_NAME", ".", "kind_of?", "(", "Array", ")", "resource", "::", "LIST_NAME", ".", "first", "else", "resource", "::", "LIST_NAME", "end", "end" ]
Return any listname described on resource
[ "Return", "any", "listname", "described", "on", "resource" ]
42a9cd16617302c028190de8b3d50abd134dd61f
https://github.com/lenovo/xclarity_client/blob/42a9cd16617302c028190de8b3d50abd134dd61f/lib/xclarity_client/services/xclarity_management_mixin.rb#L160-L166
train
lenovo/xclarity_client
lib/xclarity_client/services/xclarity_management_mixin.rb
XClarityClient.ManagementMixin.process_body_as_hash
def process_body_as_hash(resource, body) result = body if resource::LIST_NAME.kind_of? Array # search which list name is present on body list_name = resource::LIST_NAME.find { |name| body.keys.include?(name) && body[name].kind_of?(Array) } else list_name = any_listname_of(resource) end result = {list_name => [body]} unless body.has_key? list_name # for the cases where body represents a single resource return list_name, result end
ruby
def process_body_as_hash(resource, body) result = body if resource::LIST_NAME.kind_of? Array # search which list name is present on body list_name = resource::LIST_NAME.find { |name| body.keys.include?(name) && body[name].kind_of?(Array) } else list_name = any_listname_of(resource) end result = {list_name => [body]} unless body.has_key? list_name # for the cases where body represents a single resource return list_name, result end
[ "def", "process_body_as_hash", "(", "resource", ",", "body", ")", "result", "=", "body", "if", "resource", "::", "LIST_NAME", ".", "kind_of?", "Array", "list_name", "=", "resource", "::", "LIST_NAME", ".", "find", "{", "|", "name", "|", "body", ".", "keys", ".", "include?", "(", "name", ")", "&&", "body", "[", "name", "]", ".", "kind_of?", "(", "Array", ")", "}", "else", "list_name", "=", "any_listname_of", "(", "resource", ")", "end", "result", "=", "{", "list_name", "=>", "[", "body", "]", "}", "unless", "body", ".", "has_key?", "list_name", "return", "list_name", ",", "result", "end" ]
Discover what list name defined on resource is present on body If none of then is find assume that the body is a single resource and add it value into array and assing to any list name
[ "Discover", "what", "list", "name", "defined", "on", "resource", "is", "present", "on", "body", "If", "none", "of", "then", "is", "find", "assume", "that", "the", "body", "is", "a", "single", "resource", "and", "add", "it", "value", "into", "array", "and", "assing", "to", "any", "list", "name" ]
42a9cd16617302c028190de8b3d50abd134dd61f
https://github.com/lenovo/xclarity_client/blob/42a9cd16617302c028190de8b3d50abd134dd61f/lib/xclarity_client/services/xclarity_management_mixin.rb#L178-L188
train
lenovo/xclarity_client
lib/xclarity_client/services/user_management.rb
XClarityClient.UserManagement.mount_response_change_password
def mount_response_change_password(response) response = JSON.parse(response.body) { changed: response['response']['changed'], message: response['messages'].first['explanation'] } end
ruby
def mount_response_change_password(response) response = JSON.parse(response.body) { changed: response['response']['changed'], message: response['messages'].first['explanation'] } end
[ "def", "mount_response_change_password", "(", "response", ")", "response", "=", "JSON", ".", "parse", "(", "response", ".", "body", ")", "{", "changed", ":", "response", "[", "'response'", "]", "[", "'changed'", "]", ",", "message", ":", "response", "[", "'messages'", "]", ".", "first", "[", "'explanation'", "]", "}", "end" ]
Mounts a friendly response for the change password request @param [response] response provided by LXCA in change password endpoint @return [Hash] represents LXCA response :changed [Boolean] says if the password was changed or not :message [String] message from LXCA about the operation
[ "Mounts", "a", "friendly", "response", "for", "the", "change", "password", "request" ]
42a9cd16617302c028190de8b3d50abd134dd61f
https://github.com/lenovo/xclarity_client/blob/42a9cd16617302c028190de8b3d50abd134dd61f/lib/xclarity_client/services/user_management.rb#L29-L36
train
markaby/markaby
lib/markaby/builder.rb
Markaby.Builder.capture
def capture(&block) @streams.push(@builder.target = Stream.new) @builder.level += 1 str = instance_eval(&block) str = @streams.last.join if @streams.last.any? @streams.pop @builder.level -= 1 @builder.target = @streams.last str end
ruby
def capture(&block) @streams.push(@builder.target = Stream.new) @builder.level += 1 str = instance_eval(&block) str = @streams.last.join if @streams.last.any? @streams.pop @builder.level -= 1 @builder.target = @streams.last str end
[ "def", "capture", "(", "&", "block", ")", "@streams", ".", "push", "(", "@builder", ".", "target", "=", "Stream", ".", "new", ")", "@builder", ".", "level", "+=", "1", "str", "=", "instance_eval", "(", "&", "block", ")", "str", "=", "@streams", ".", "last", ".", "join", "if", "@streams", ".", "last", ".", "any?", "@streams", ".", "pop", "@builder", ".", "level", "-=", "1", "@builder", ".", "target", "=", "@streams", ".", "last", "str", "end" ]
Captures the HTML code built inside the +block+. This is done by creating a new stream for the builder object, running the block and passing back its stream as a string. >> Markaby::Builder.new.capture { h1 "TEST"; h2 "CAPTURE ME" } => "<h1>TEST</h1><h2>CAPTURE ME</h2>"
[ "Captures", "the", "HTML", "code", "built", "inside", "the", "+", "block", "+", ".", "This", "is", "done", "by", "creating", "a", "new", "stream", "for", "the", "builder", "object", "running", "the", "block", "and", "passing", "back", "its", "stream", "as", "a", "string", "." ]
e44d7e16cd86302ecce1694b95940b5eb402acf7
https://github.com/markaby/markaby/blob/e44d7e16cd86302ecce1694b95940b5eb402acf7/lib/markaby/builder.rb#L139-L148
train
markaby/markaby
lib/markaby/builder.rb
Markaby.Builder.tag!
def tag!(tag, *args, &block) ele_id = nil # TODO: Move this logic to the tagset so that the tagset itself can validate + raise when invalid if @auto_validation && @tagset if [email protected]_key?(tag) raise InvalidXhtmlError, "no element `#{tag}' for #{tagset.doctype}" elsif args.last.respond_to?(:to_hash) attrs = args.last.to_hash if @tagset.forms.include?(tag) && attrs[:id] attrs[:name] ||= attrs[:id] end attrs.each do |k, v| atname = k.to_s.downcase.intern unless k =~ /:/ or @tagset.tagset[tag].include?(atname) or (@tagset == Markaby::HTML5 && atname.to_s =~ /^data-/) raise InvalidXhtmlError, "no attribute `#{k}' on #{tag} elements" end if atname == :id ele_id = v.to_s if @used_ids.has_key? ele_id raise InvalidXhtmlError, "id `#{ele_id}' already used (id's must be unique)." end end if AttrsBoolean.include? atname if v attrs[k] = atname.to_s else attrs.delete k end end end end end if block str = capture(&block) block = proc { text(str) } end f = fragment { @builder.tag!(tag, *args, &block) } @used_ids[ele_id] = f if ele_id f end
ruby
def tag!(tag, *args, &block) ele_id = nil # TODO: Move this logic to the tagset so that the tagset itself can validate + raise when invalid if @auto_validation && @tagset if [email protected]_key?(tag) raise InvalidXhtmlError, "no element `#{tag}' for #{tagset.doctype}" elsif args.last.respond_to?(:to_hash) attrs = args.last.to_hash if @tagset.forms.include?(tag) && attrs[:id] attrs[:name] ||= attrs[:id] end attrs.each do |k, v| atname = k.to_s.downcase.intern unless k =~ /:/ or @tagset.tagset[tag].include?(atname) or (@tagset == Markaby::HTML5 && atname.to_s =~ /^data-/) raise InvalidXhtmlError, "no attribute `#{k}' on #{tag} elements" end if atname == :id ele_id = v.to_s if @used_ids.has_key? ele_id raise InvalidXhtmlError, "id `#{ele_id}' already used (id's must be unique)." end end if AttrsBoolean.include? atname if v attrs[k] = atname.to_s else attrs.delete k end end end end end if block str = capture(&block) block = proc { text(str) } end f = fragment { @builder.tag!(tag, *args, &block) } @used_ids[ele_id] = f if ele_id f end
[ "def", "tag!", "(", "tag", ",", "*", "args", ",", "&", "block", ")", "ele_id", "=", "nil", "if", "@auto_validation", "&&", "@tagset", "if", "!", "@tagset", ".", "tagset", ".", "has_key?", "(", "tag", ")", "raise", "InvalidXhtmlError", ",", "\"no element `#{tag}' for #{tagset.doctype}\"", "elsif", "args", ".", "last", ".", "respond_to?", "(", ":to_hash", ")", "attrs", "=", "args", ".", "last", ".", "to_hash", "if", "@tagset", ".", "forms", ".", "include?", "(", "tag", ")", "&&", "attrs", "[", ":id", "]", "attrs", "[", ":name", "]", "||=", "attrs", "[", ":id", "]", "end", "attrs", ".", "each", "do", "|", "k", ",", "v", "|", "atname", "=", "k", ".", "to_s", ".", "downcase", ".", "intern", "unless", "k", "=~", "/", "/", "or", "@tagset", ".", "tagset", "[", "tag", "]", ".", "include?", "(", "atname", ")", "or", "(", "@tagset", "==", "Markaby", "::", "HTML5", "&&", "atname", ".", "to_s", "=~", "/", "/", ")", "raise", "InvalidXhtmlError", ",", "\"no attribute `#{k}' on #{tag} elements\"", "end", "if", "atname", "==", ":id", "ele_id", "=", "v", ".", "to_s", "if", "@used_ids", ".", "has_key?", "ele_id", "raise", "InvalidXhtmlError", ",", "\"id `#{ele_id}' already used (id's must be unique).\"", "end", "end", "if", "AttrsBoolean", ".", "include?", "atname", "if", "v", "attrs", "[", "k", "]", "=", "atname", ".", "to_s", "else", "attrs", ".", "delete", "k", "end", "end", "end", "end", "end", "if", "block", "str", "=", "capture", "(", "&", "block", ")", "block", "=", "proc", "{", "text", "(", "str", ")", "}", "end", "f", "=", "fragment", "{", "@builder", ".", "tag!", "(", "tag", ",", "*", "args", ",", "&", "block", ")", "}", "@used_ids", "[", "ele_id", "]", "=", "f", "if", "ele_id", "f", "end" ]
Create a tag named +tag+. Other than the first argument which is the tag name, the arguments are the same as the tags implemented via method_missing.
[ "Create", "a", "tag", "named", "+", "tag", "+", ".", "Other", "than", "the", "first", "argument", "which", "is", "the", "tag", "name", "the", "arguments", "are", "the", "same", "as", "the", "tags", "implemented", "via", "method_missing", "." ]
e44d7e16cd86302ecce1694b95940b5eb402acf7
https://github.com/markaby/markaby/blob/e44d7e16cd86302ecce1694b95940b5eb402acf7/lib/markaby/builder.rb#L152-L200
train
lenovo/xclarity_client
lib/xclarity_client/services/update_comp_management.rb
XClarityClient.UpdateCompManagement.add_uri
def add_uri(force_update_mode, onerror_mode, uri) fmode = force_update_mode.nil? uri += '&forceUpdateMode=' + force_update_mode unless fmode uri += '&onErrorMode=' + onerror_mode unless onerror_mode.nil? uri end
ruby
def add_uri(force_update_mode, onerror_mode, uri) fmode = force_update_mode.nil? uri += '&forceUpdateMode=' + force_update_mode unless fmode uri += '&onErrorMode=' + onerror_mode unless onerror_mode.nil? uri end
[ "def", "add_uri", "(", "force_update_mode", ",", "onerror_mode", ",", "uri", ")", "fmode", "=", "force_update_mode", ".", "nil?", "uri", "+=", "'&forceUpdateMode='", "+", "force_update_mode", "unless", "fmode", "uri", "+=", "'&onErrorMode='", "+", "onerror_mode", "unless", "onerror_mode", ".", "nil?", "uri", "end" ]
splitted create_uri just to fix codeclimate error
[ "splitted", "create_uri", "just", "to", "fix", "codeclimate", "error" ]
42a9cd16617302c028190de8b3d50abd134dd61f
https://github.com/lenovo/xclarity_client/blob/42a9cd16617302c028190de8b3d50abd134dd61f/lib/xclarity_client/services/update_comp_management.rb#L86-L91
train
bmedici/rest-ftp-daemon
lib/rest-ftp-daemon/job_queue.rb
RestFtpDaemon.JobQueue.jobs_with_status
def jobs_with_status status # No status filter: return all execept queued if status.empty? @jobs.reject { |job| job.status == JOB_STATUS_QUEUED } # Status filtering: only those jobs else @jobs.select { |job| job.status == status.to_s } end end
ruby
def jobs_with_status status # No status filter: return all execept queued if status.empty? @jobs.reject { |job| job.status == JOB_STATUS_QUEUED } # Status filtering: only those jobs else @jobs.select { |job| job.status == status.to_s } end end
[ "def", "jobs_with_status", "status", "if", "status", ".", "empty?", "@jobs", ".", "reject", "{", "|", "job", "|", "job", ".", "status", "==", "JOB_STATUS_QUEUED", "}", "else", "@jobs", ".", "select", "{", "|", "job", "|", "job", ".", "status", "==", "status", ".", "to_s", "}", "end", "end" ]
Jobs acess and searching
[ "Jobs", "acess", "and", "searching" ]
72754b9fb1ada2a4711a2f2351a3aa47adaa43da
https://github.com/bmedici/rest-ftp-daemon/blob/72754b9fb1ada2a4711a2f2351a3aa47adaa43da/lib/rest-ftp-daemon/job_queue.rb#L210-L220
train
bmedici/rest-ftp-daemon
lib/rest-ftp-daemon/job.rb
RestFtpDaemon.Job.debug_value_utf8
def debug_value_utf8 value case value when Symbol return value.to_s.force_encoding(Encoding::UTF_8) when String return value.dup.force_encoding(Encoding::UTF_8) if value.is_a? String else return value end end
ruby
def debug_value_utf8 value case value when Symbol return value.to_s.force_encoding(Encoding::UTF_8) when String return value.dup.force_encoding(Encoding::UTF_8) if value.is_a? String else return value end end
[ "def", "debug_value_utf8", "value", "case", "value", "when", "Symbol", "return", "value", ".", "to_s", ".", "force_encoding", "(", "Encoding", "::", "UTF_8", ")", "when", "String", "return", "value", ".", "dup", ".", "force_encoding", "(", "Encoding", "::", "UTF_8", ")", "if", "value", ".", "is_a?", "String", "else", "return", "value", "end", "end" ]
Force strings to UTF8
[ "Force", "strings", "to", "UTF8" ]
72754b9fb1ada2a4711a2f2351a3aa47adaa43da
https://github.com/bmedici/rest-ftp-daemon/blob/72754b9fb1ada2a4711a2f2351a3aa47adaa43da/lib/rest-ftp-daemon/job.rb#L246-L255
train
james2m/canard
lib/canard/user_model.rb
Canard.UserModel.has_roles_mask_accessors?
def has_roles_mask_accessors? instance_method_names = instance_methods.map { |method_name| method_name.to_s } [roles_attribute_name.to_s, "#{roles_attribute_name}="].all? do |accessor| instance_method_names.include?(accessor) end end
ruby
def has_roles_mask_accessors? instance_method_names = instance_methods.map { |method_name| method_name.to_s } [roles_attribute_name.to_s, "#{roles_attribute_name}="].all? do |accessor| instance_method_names.include?(accessor) end end
[ "def", "has_roles_mask_accessors?", "instance_method_names", "=", "instance_methods", ".", "map", "{", "|", "method_name", "|", "method_name", ".", "to_s", "}", "[", "roles_attribute_name", ".", "to_s", ",", "\"#{roles_attribute_name}=\"", "]", ".", "all?", "do", "|", "accessor", "|", "instance_method_names", ".", "include?", "(", "accessor", ")", "end", "end" ]
This is overridden by the ActiveRecord adapter as the attribute accessors don't show up in instance_methods.
[ "This", "is", "overridden", "by", "the", "ActiveRecord", "adapter", "as", "the", "attribute", "accessors", "don", "t", "show", "up", "in", "instance_methods", "." ]
59caec2648aa95b88fd53b999ab19d1366750b6c
https://github.com/james2m/canard/blob/59caec2648aa95b88fd53b999ab19d1366750b6c/lib/canard/user_model.rb#L83-L88
train
alagu/pagoda
lib/pagoda/app.rb
Shwedagon.App.create_new_post
def create_new_post(params) post_title = params['post']['title'] post_date = (Time.now).strftime("%Y-%m-%d") content = yaml_data(post_title).to_yaml + "---\n" + params[:post][:content] post_file = (post_date + " " + post_title).to_url + '.md' file = File.join(jekyll_site.source, *%w[_posts], post_file) File.open(file, 'w') { |file| file.write(content)} post_file end
ruby
def create_new_post(params) post_title = params['post']['title'] post_date = (Time.now).strftime("%Y-%m-%d") content = yaml_data(post_title).to_yaml + "---\n" + params[:post][:content] post_file = (post_date + " " + post_title).to_url + '.md' file = File.join(jekyll_site.source, *%w[_posts], post_file) File.open(file, 'w') { |file| file.write(content)} post_file end
[ "def", "create_new_post", "(", "params", ")", "post_title", "=", "params", "[", "'post'", "]", "[", "'title'", "]", "post_date", "=", "(", "Time", ".", "now", ")", ".", "strftime", "(", "\"%Y-%m-%d\"", ")", "content", "=", "yaml_data", "(", "post_title", ")", ".", "to_yaml", "+", "\"---\\n\"", "+", "params", "[", ":post", "]", "[", ":content", "]", "post_file", "=", "(", "post_date", "+", "\" \"", "+", "post_title", ")", ".", "to_url", "+", "'.md'", "file", "=", "File", ".", "join", "(", "jekyll_site", ".", "source", ",", "*", "%w[", "_posts", "]", ",", "post_file", ")", "File", ".", "open", "(", "file", ",", "'w'", ")", "{", "|", "file", "|", "file", ".", "write", "(", "content", ")", "}", "post_file", "end" ]
Create a new post from scratch. Return filename This would not commit the file.
[ "Create", "a", "new", "post", "from", "scratch", ".", "Return", "filename", "This", "would", "not", "commit", "the", "file", "." ]
c1587fb245946f8cca1ceee19ef6677f315c42ed
https://github.com/alagu/pagoda/blob/c1587fb245946f8cca1ceee19ef6677f315c42ed/lib/pagoda/app.rb#L43-L52
train
alagu/pagoda
lib/pagoda/app.rb
Shwedagon.App.merge_config
def merge_config(yaml, params) if params['post'].has_key? 'yaml' params['post']['yaml'].each do |key, value| if value == 'true' yaml[key] = true elsif value == 'false' yaml[key] = false else yaml[key] = value end end end yaml end
ruby
def merge_config(yaml, params) if params['post'].has_key? 'yaml' params['post']['yaml'].each do |key, value| if value == 'true' yaml[key] = true elsif value == 'false' yaml[key] = false else yaml[key] = value end end end yaml end
[ "def", "merge_config", "(", "yaml", ",", "params", ")", "if", "params", "[", "'post'", "]", ".", "has_key?", "'yaml'", "params", "[", "'post'", "]", "[", "'yaml'", "]", ".", "each", "do", "|", "key", ",", "value", "|", "if", "value", "==", "'true'", "yaml", "[", "key", "]", "=", "true", "elsif", "value", "==", "'false'", "yaml", "[", "key", "]", "=", "false", "else", "yaml", "[", "key", "]", "=", "value", "end", "end", "end", "yaml", "end" ]
Merge existing yaml with post params
[ "Merge", "existing", "yaml", "with", "post", "params" ]
c1587fb245946f8cca1ceee19ef6677f315c42ed
https://github.com/alagu/pagoda/blob/c1587fb245946f8cca1ceee19ef6677f315c42ed/lib/pagoda/app.rb#L56-L70
train
alagu/pagoda
lib/pagoda/app.rb
Shwedagon.App.update_post
def update_post(params) post_file = params[:post][:name] post = jekyll_post(post_file) yaml_config = merge_config(post.data, params) write_post_contents(params[:post][:content], yaml_config, post_file) post_file end
ruby
def update_post(params) post_file = params[:post][:name] post = jekyll_post(post_file) yaml_config = merge_config(post.data, params) write_post_contents(params[:post][:content], yaml_config, post_file) post_file end
[ "def", "update_post", "(", "params", ")", "post_file", "=", "params", "[", ":post", "]", "[", ":name", "]", "post", "=", "jekyll_post", "(", "post_file", ")", "yaml_config", "=", "merge_config", "(", "post", ".", "data", ",", "params", ")", "write_post_contents", "(", "params", "[", ":post", "]", "[", ":content", "]", ",", "yaml_config", ",", "post_file", ")", "post_file", "end" ]
Update exiting post.
[ "Update", "exiting", "post", "." ]
c1587fb245946f8cca1ceee19ef6677f315c42ed
https://github.com/alagu/pagoda/blob/c1587fb245946f8cca1ceee19ef6677f315c42ed/lib/pagoda/app.rb#L82-L89
train
alagu/pagoda
lib/pagoda/helper.rb
Shwedagon.App.jekyll_site
def jekyll_site if not @site # Supress stdout original_stdout = $stdout $stdout = File.new('/tmp/null.txt', 'w') config = Jekyll.configuration({'source' => cloned_repo_path}) @site = Jekyll::Site.new(config) @site.read $stdout = original_stdout end @site end
ruby
def jekyll_site if not @site # Supress stdout original_stdout = $stdout $stdout = File.new('/tmp/null.txt', 'w') config = Jekyll.configuration({'source' => cloned_repo_path}) @site = Jekyll::Site.new(config) @site.read $stdout = original_stdout end @site end
[ "def", "jekyll_site", "if", "not", "@site", "original_stdout", "=", "$stdout", "$stdout", "=", "File", ".", "new", "(", "'/tmp/null.txt'", ",", "'w'", ")", "config", "=", "Jekyll", ".", "configuration", "(", "{", "'source'", "=>", "cloned_repo_path", "}", ")", "@site", "=", "Jekyll", "::", "Site", ".", "new", "(", "config", ")", "@site", ".", "read", "$stdout", "=", "original_stdout", "end", "@site", "end" ]
Jekyll site instance
[ "Jekyll", "site", "instance" ]
c1587fb245946f8cca1ceee19ef6677f315c42ed
https://github.com/alagu/pagoda/blob/c1587fb245946f8cca1ceee19ef6677f315c42ed/lib/pagoda/helper.rb#L6-L20
train
alagu/pagoda
lib/pagoda/helper.rb
Shwedagon.App.posts_template_data
def posts_template_data(post_items) if post_items.nil? return [] end template_data = post_items.map do |post| { :title => post.data['title'], :filename => post.name, :date => post.date } end template_data.sort! { |x,y| y[:date] <=> x[:date] } template_data end
ruby
def posts_template_data(post_items) if post_items.nil? return [] end template_data = post_items.map do |post| { :title => post.data['title'], :filename => post.name, :date => post.date } end template_data.sort! { |x,y| y[:date] <=> x[:date] } template_data end
[ "def", "posts_template_data", "(", "post_items", ")", "if", "post_items", ".", "nil?", "return", "[", "]", "end", "template_data", "=", "post_items", ".", "map", "do", "|", "post", "|", "{", ":title", "=>", "post", ".", "data", "[", "'title'", "]", ",", ":filename", "=>", "post", ".", "name", ",", ":date", "=>", "post", ".", "date", "}", "end", "template_data", ".", "sort!", "{", "|", "x", ",", "y", "|", "y", "[", ":date", "]", "<=>", "x", "[", ":date", "]", "}", "template_data", "end" ]
Gives out a sorted list of post template data for a post or draft
[ "Gives", "out", "a", "sorted", "list", "of", "post", "template", "data", "for", "a", "post", "or", "draft" ]
c1587fb245946f8cca1ceee19ef6677f315c42ed
https://github.com/alagu/pagoda/blob/c1587fb245946f8cca1ceee19ef6677f315c42ed/lib/pagoda/helper.rb#L86-L102
train
xuanxu/nimbus
lib/nimbus/application.rb
Nimbus.Application.nimbus_exception_handling
def nimbus_exception_handling begin yield rescue SystemExit => ex raise rescue Nimbus::Error => ex display_error_message(ex) Nimbus.stop rescue Exception => ex display_error_message(ex) Nimbus.stop end end
ruby
def nimbus_exception_handling begin yield rescue SystemExit => ex raise rescue Nimbus::Error => ex display_error_message(ex) Nimbus.stop rescue Exception => ex display_error_message(ex) Nimbus.stop end end
[ "def", "nimbus_exception_handling", "begin", "yield", "rescue", "SystemExit", "=>", "ex", "raise", "rescue", "Nimbus", "::", "Error", "=>", "ex", "display_error_message", "(", "ex", ")", "Nimbus", ".", "stop", "rescue", "Exception", "=>", "ex", "display_error_message", "(", "ex", ")", "Nimbus", ".", "stop", "end", "end" ]
Provides the default exception handling for the given block.
[ "Provides", "the", "default", "exception", "handling", "for", "the", "given", "block", "." ]
6646dbc00147408765044a99702005d3d30e052e
https://github.com/xuanxu/nimbus/blob/6646dbc00147408765044a99702005d3d30e052e/lib/nimbus/application.rb#L57-L69
train
xuanxu/nimbus
lib/nimbus/regression_tree.rb
Nimbus.RegressionTree.seed
def seed(all_individuals, individuals_sample, ids_fenotypes) super @structure = build_node individuals_sample, Nimbus::LossFunctions.average(individuals_sample, @id_to_fenotype) end
ruby
def seed(all_individuals, individuals_sample, ids_fenotypes) super @structure = build_node individuals_sample, Nimbus::LossFunctions.average(individuals_sample, @id_to_fenotype) end
[ "def", "seed", "(", "all_individuals", ",", "individuals_sample", ",", "ids_fenotypes", ")", "super", "@structure", "=", "build_node", "individuals_sample", ",", "Nimbus", "::", "LossFunctions", ".", "average", "(", "individuals_sample", ",", "@id_to_fenotype", ")", "end" ]
Creates the structure of the tree, as a hash of SNP splits and values. It just initializes the needed variables and then defines the first node of the tree. The rest of the structure of the tree is computed recursively building every node calling +build_node+.
[ "Creates", "the", "structure", "of", "the", "tree", "as", "a", "hash", "of", "SNP", "splits", "and", "values", "." ]
6646dbc00147408765044a99702005d3d30e052e
https://github.com/xuanxu/nimbus/blob/6646dbc00147408765044a99702005d3d30e052e/lib/nimbus/regression_tree.rb#L23-L26
train
xuanxu/nimbus
lib/nimbus/configuration.rb
Nimbus.Configuration.load
def load(config_file = DEFAULTS[:config_file]) user_config_params = {} dirname = Dir.pwd if File.exists?(File.expand_path(config_file, Dir.pwd)) begin config_file_path = File.expand_path config_file, Dir.pwd user_config_params = Psych.load(File.open(config_file_path)) dirname = File.dirname config_file_path rescue ArgumentError => e raise Nimbus::WrongFormatFileError, "It was not posible to parse the config file (#{config_file}): \r\n#{e.message} " end end if user_config_params['input'] @training_file = File.expand_path(user_config_params['input']['training'], dirname) if user_config_params['input']['training'] @testing_file = File.expand_path(user_config_params['input']['testing' ], dirname) if user_config_params['input']['testing'] @forest_file = File.expand_path(user_config_params['input']['forest' ], dirname) if user_config_params['input']['forest'] @classes = user_config_params['input']['classes'] if user_config_params['input']['classes'] else @training_file = File.expand_path(DEFAULTS[:training_file], Dir.pwd) if File.exists? File.expand_path(DEFAULTS[:training_file], Dir.pwd) @testing_file = File.expand_path(DEFAULTS[:testing_file ], Dir.pwd) if File.exists? File.expand_path(DEFAULTS[:testing_file ], Dir.pwd) @forest_file = File.expand_path(DEFAULTS[:forest_file ], Dir.pwd) if File.exists? File.expand_path(DEFAULTS[:forest_file ], Dir.pwd) end @do_training = true unless @training_file.nil? @do_testing = true unless @testing_file.nil? @classes = @classes.map{|c| c.to_s.strip} if @classes if @do_testing && !@do_training && !@forest_file raise Nimbus::InputFileError, "There is not random forest data (training file not defined, and forest file not found)." end if user_config_params['forest'] @forest_size = user_config_params['forest']['forest_size'].to_i if user_config_params['forest']['forest_size'] @tree_SNP_total_count = user_config_params['forest']['SNP_total_count'].to_i if user_config_params['forest']['SNP_total_count'] @tree_SNP_sample_size = user_config_params['forest']['SNP_sample_size_mtry'].to_i if user_config_params['forest']['SNP_sample_size_mtry'] @tree_node_min_size = user_config_params['forest']['node_min_size'].to_i if user_config_params['forest']['node_min_size'] @do_importances = user_config_params['forest']['var_importances'].to_s.strip.downcase @do_importances = (@do_importances != 'no' && @do_importances != 'false') end check_configuration log_configuration end
ruby
def load(config_file = DEFAULTS[:config_file]) user_config_params = {} dirname = Dir.pwd if File.exists?(File.expand_path(config_file, Dir.pwd)) begin config_file_path = File.expand_path config_file, Dir.pwd user_config_params = Psych.load(File.open(config_file_path)) dirname = File.dirname config_file_path rescue ArgumentError => e raise Nimbus::WrongFormatFileError, "It was not posible to parse the config file (#{config_file}): \r\n#{e.message} " end end if user_config_params['input'] @training_file = File.expand_path(user_config_params['input']['training'], dirname) if user_config_params['input']['training'] @testing_file = File.expand_path(user_config_params['input']['testing' ], dirname) if user_config_params['input']['testing'] @forest_file = File.expand_path(user_config_params['input']['forest' ], dirname) if user_config_params['input']['forest'] @classes = user_config_params['input']['classes'] if user_config_params['input']['classes'] else @training_file = File.expand_path(DEFAULTS[:training_file], Dir.pwd) if File.exists? File.expand_path(DEFAULTS[:training_file], Dir.pwd) @testing_file = File.expand_path(DEFAULTS[:testing_file ], Dir.pwd) if File.exists? File.expand_path(DEFAULTS[:testing_file ], Dir.pwd) @forest_file = File.expand_path(DEFAULTS[:forest_file ], Dir.pwd) if File.exists? File.expand_path(DEFAULTS[:forest_file ], Dir.pwd) end @do_training = true unless @training_file.nil? @do_testing = true unless @testing_file.nil? @classes = @classes.map{|c| c.to_s.strip} if @classes if @do_testing && !@do_training && !@forest_file raise Nimbus::InputFileError, "There is not random forest data (training file not defined, and forest file not found)." end if user_config_params['forest'] @forest_size = user_config_params['forest']['forest_size'].to_i if user_config_params['forest']['forest_size'] @tree_SNP_total_count = user_config_params['forest']['SNP_total_count'].to_i if user_config_params['forest']['SNP_total_count'] @tree_SNP_sample_size = user_config_params['forest']['SNP_sample_size_mtry'].to_i if user_config_params['forest']['SNP_sample_size_mtry'] @tree_node_min_size = user_config_params['forest']['node_min_size'].to_i if user_config_params['forest']['node_min_size'] @do_importances = user_config_params['forest']['var_importances'].to_s.strip.downcase @do_importances = (@do_importances != 'no' && @do_importances != 'false') end check_configuration log_configuration end
[ "def", "load", "(", "config_file", "=", "DEFAULTS", "[", ":config_file", "]", ")", "user_config_params", "=", "{", "}", "dirname", "=", "Dir", ".", "pwd", "if", "File", ".", "exists?", "(", "File", ".", "expand_path", "(", "config_file", ",", "Dir", ".", "pwd", ")", ")", "begin", "config_file_path", "=", "File", ".", "expand_path", "config_file", ",", "Dir", ".", "pwd", "user_config_params", "=", "Psych", ".", "load", "(", "File", ".", "open", "(", "config_file_path", ")", ")", "dirname", "=", "File", ".", "dirname", "config_file_path", "rescue", "ArgumentError", "=>", "e", "raise", "Nimbus", "::", "WrongFormatFileError", ",", "\"It was not posible to parse the config file (#{config_file}): \\r\\n#{e.message} \"", "end", "end", "if", "user_config_params", "[", "'input'", "]", "@training_file", "=", "File", ".", "expand_path", "(", "user_config_params", "[", "'input'", "]", "[", "'training'", "]", ",", "dirname", ")", "if", "user_config_params", "[", "'input'", "]", "[", "'training'", "]", "@testing_file", "=", "File", ".", "expand_path", "(", "user_config_params", "[", "'input'", "]", "[", "'testing'", "]", ",", "dirname", ")", "if", "user_config_params", "[", "'input'", "]", "[", "'testing'", "]", "@forest_file", "=", "File", ".", "expand_path", "(", "user_config_params", "[", "'input'", "]", "[", "'forest'", "]", ",", "dirname", ")", "if", "user_config_params", "[", "'input'", "]", "[", "'forest'", "]", "@classes", "=", "user_config_params", "[", "'input'", "]", "[", "'classes'", "]", "if", "user_config_params", "[", "'input'", "]", "[", "'classes'", "]", "else", "@training_file", "=", "File", ".", "expand_path", "(", "DEFAULTS", "[", ":training_file", "]", ",", "Dir", ".", "pwd", ")", "if", "File", ".", "exists?", "File", ".", "expand_path", "(", "DEFAULTS", "[", ":training_file", "]", ",", "Dir", ".", "pwd", ")", "@testing_file", "=", "File", ".", "expand_path", "(", "DEFAULTS", "[", ":testing_file", "]", ",", "Dir", ".", "pwd", ")", "if", "File", ".", "exists?", "File", ".", "expand_path", "(", "DEFAULTS", "[", ":testing_file", "]", ",", "Dir", ".", "pwd", ")", "@forest_file", "=", "File", ".", "expand_path", "(", "DEFAULTS", "[", ":forest_file", "]", ",", "Dir", ".", "pwd", ")", "if", "File", ".", "exists?", "File", ".", "expand_path", "(", "DEFAULTS", "[", ":forest_file", "]", ",", "Dir", ".", "pwd", ")", "end", "@do_training", "=", "true", "unless", "@training_file", ".", "nil?", "@do_testing", "=", "true", "unless", "@testing_file", ".", "nil?", "@classes", "=", "@classes", ".", "map", "{", "|", "c", "|", "c", ".", "to_s", ".", "strip", "}", "if", "@classes", "if", "@do_testing", "&&", "!", "@do_training", "&&", "!", "@forest_file", "raise", "Nimbus", "::", "InputFileError", ",", "\"There is not random forest data (training file not defined, and forest file not found).\"", "end", "if", "user_config_params", "[", "'forest'", "]", "@forest_size", "=", "user_config_params", "[", "'forest'", "]", "[", "'forest_size'", "]", ".", "to_i", "if", "user_config_params", "[", "'forest'", "]", "[", "'forest_size'", "]", "@tree_SNP_total_count", "=", "user_config_params", "[", "'forest'", "]", "[", "'SNP_total_count'", "]", ".", "to_i", "if", "user_config_params", "[", "'forest'", "]", "[", "'SNP_total_count'", "]", "@tree_SNP_sample_size", "=", "user_config_params", "[", "'forest'", "]", "[", "'SNP_sample_size_mtry'", "]", ".", "to_i", "if", "user_config_params", "[", "'forest'", "]", "[", "'SNP_sample_size_mtry'", "]", "@tree_node_min_size", "=", "user_config_params", "[", "'forest'", "]", "[", "'node_min_size'", "]", ".", "to_i", "if", "user_config_params", "[", "'forest'", "]", "[", "'node_min_size'", "]", "@do_importances", "=", "user_config_params", "[", "'forest'", "]", "[", "'var_importances'", "]", ".", "to_s", ".", "strip", ".", "downcase", "@do_importances", "=", "(", "@do_importances", "!=", "'no'", "&&", "@do_importances", "!=", "'false'", ")", "end", "check_configuration", "log_configuration", "end" ]
This is the first method to be called on Configuration when a config.yml file exists with user input options for the forest. * The method will read the config file and change the default value of the selected options. * Then based on the options and the existence of training, testing and forest files, it will mark: - if training is needed, - if testing is needed, - which forest will be used for the testing. * Finally it will run basic checks on the input data trying to prevent future program errors.
[ "This", "is", "the", "first", "method", "to", "be", "called", "on", "Configuration", "when", "a", "config", ".", "yml", "file", "exists", "with", "user", "input", "options", "for", "the", "forest", "." ]
6646dbc00147408765044a99702005d3d30e052e
https://github.com/xuanxu/nimbus/blob/6646dbc00147408765044a99702005d3d30e052e/lib/nimbus/configuration.rb#L105-L148
train
AlchemyCMS/alchemy-devise
app/models/alchemy/user.rb
Alchemy.User.fullname
def fullname(options = {}) if lastname.blank? && firstname.blank? login else options = {:flipped => false}.merge(options) fullname = options[:flipped] ? "#{lastname}, #{firstname}" : "#{firstname} #{lastname}" fullname.squeeze(" ").strip end end
ruby
def fullname(options = {}) if lastname.blank? && firstname.blank? login else options = {:flipped => false}.merge(options) fullname = options[:flipped] ? "#{lastname}, #{firstname}" : "#{firstname} #{lastname}" fullname.squeeze(" ").strip end end
[ "def", "fullname", "(", "options", "=", "{", "}", ")", "if", "lastname", ".", "blank?", "&&", "firstname", ".", "blank?", "login", "else", "options", "=", "{", ":flipped", "=>", "false", "}", ".", "merge", "(", "options", ")", "fullname", "=", "options", "[", ":flipped", "]", "?", "\"#{lastname}, #{firstname}\"", ":", "\"#{firstname} #{lastname}\"", "fullname", ".", "squeeze", "(", "\" \"", ")", ".", "strip", "end", "end" ]
Returns the firstname and lastname as a string If both are blank, returns the login @option options :flipped (false) Flip the firstname and lastname
[ "Returns", "the", "firstname", "and", "lastname", "as", "a", "string" ]
ab1781db136cc634c38775d939f45e98f9d74e8e
https://github.com/AlchemyCMS/alchemy-devise/blob/ab1781db136cc634c38775d939f45e98f9d74e8e/app/models/alchemy/user.rb#L125-L133
train
AlchemyCMS/alchemy-devise
app/models/alchemy/user.rb
Alchemy.User.deliver_welcome_mail
def deliver_welcome_mail if has_role?('author') || has_role?('editor') || has_role?('admin') Notifications.alchemy_user_created(self).deliver_later else Notifications.member_created(self).deliver_later end end
ruby
def deliver_welcome_mail if has_role?('author') || has_role?('editor') || has_role?('admin') Notifications.alchemy_user_created(self).deliver_later else Notifications.member_created(self).deliver_later end end
[ "def", "deliver_welcome_mail", "if", "has_role?", "(", "'author'", ")", "||", "has_role?", "(", "'editor'", ")", "||", "has_role?", "(", "'admin'", ")", "Notifications", ".", "alchemy_user_created", "(", "self", ")", ".", "deliver_later", "else", "Notifications", ".", "member_created", "(", "self", ")", ".", "deliver_later", "end", "end" ]
Delivers a welcome mail depending from user's role.
[ "Delivers", "a", "welcome", "mail", "depending", "from", "user", "s", "role", "." ]
ab1781db136cc634c38775d939f45e98f9d74e8e
https://github.com/AlchemyCMS/alchemy-devise/blob/ab1781db136cc634c38775d939f45e98f9d74e8e/app/models/alchemy/user.rb#L160-L166
train
AlchemyCMS/alchemy-devise
app/controllers/alchemy/user_sessions_controller.rb
Alchemy.UserSessionsController.after_sign_out_path_for
def after_sign_out_path_for(resource_or_scope) if request.referer.blank? || request.referer.to_s =~ /admin/ root_path else request.referer end end
ruby
def after_sign_out_path_for(resource_or_scope) if request.referer.blank? || request.referer.to_s =~ /admin/ root_path else request.referer end end
[ "def", "after_sign_out_path_for", "(", "resource_or_scope", ")", "if", "request", ".", "referer", ".", "blank?", "||", "request", ".", "referer", ".", "to_s", "=~", "/", "/", "root_path", "else", "request", ".", "referer", "end", "end" ]
Overwriting the default of Devise
[ "Overwriting", "the", "default", "of", "Devise" ]
ab1781db136cc634c38775d939f45e98f9d74e8e
https://github.com/AlchemyCMS/alchemy-devise/blob/ab1781db136cc634c38775d939f45e98f9d74e8e/app/controllers/alchemy/user_sessions_controller.rb#L54-L60
train
xuanxu/nimbus
lib/nimbus/forest.rb
Nimbus.Forest.traverse_regression_forest
def traverse_regression_forest @predictions = {} prediction_count = trees.size @options.read_testing_data{|individual| individual_prediction = 0.0 trees.each do |t| individual_prediction = (individual_prediction + Nimbus::Tree.traverse(t, individual.snp_list)).round(5) end @predictions[individual.id] = (individual_prediction / prediction_count).round(5) } end
ruby
def traverse_regression_forest @predictions = {} prediction_count = trees.size @options.read_testing_data{|individual| individual_prediction = 0.0 trees.each do |t| individual_prediction = (individual_prediction + Nimbus::Tree.traverse(t, individual.snp_list)).round(5) end @predictions[individual.id] = (individual_prediction / prediction_count).round(5) } end
[ "def", "traverse_regression_forest", "@predictions", "=", "{", "}", "prediction_count", "=", "trees", ".", "size", "@options", ".", "read_testing_data", "{", "|", "individual", "|", "individual_prediction", "=", "0.0", "trees", ".", "each", "do", "|", "t", "|", "individual_prediction", "=", "(", "individual_prediction", "+", "Nimbus", "::", "Tree", ".", "traverse", "(", "t", ",", "individual", ".", "snp_list", ")", ")", ".", "round", "(", "5", ")", "end", "@predictions", "[", "individual", ".", "id", "]", "=", "(", "individual_prediction", "/", "prediction_count", ")", ".", "round", "(", "5", ")", "}", "end" ]
Traverse a testing set through every regression tree of the forest and get averaged predictions for every individual in the sample.
[ "Traverse", "a", "testing", "set", "through", "every", "regression", "tree", "of", "the", "forest", "and", "get", "averaged", "predictions", "for", "every", "individual", "in", "the", "sample", "." ]
6646dbc00147408765044a99702005d3d30e052e
https://github.com/xuanxu/nimbus/blob/6646dbc00147408765044a99702005d3d30e052e/lib/nimbus/forest.rb#L61-L71
train
metanorma/relaton
lib/relaton/db.rb
Relaton.Db.docid_type
def docid_type(code) stdclass = standard_class(code) or return [nil, code] prefix, code = strip_id_wrapper(code, stdclass) [@registry.processors[stdclass].idtype, code] end
ruby
def docid_type(code) stdclass = standard_class(code) or return [nil, code] prefix, code = strip_id_wrapper(code, stdclass) [@registry.processors[stdclass].idtype, code] end
[ "def", "docid_type", "(", "code", ")", "stdclass", "=", "standard_class", "(", "code", ")", "or", "return", "[", "nil", ",", "code", "]", "prefix", ",", "code", "=", "strip_id_wrapper", "(", "code", ",", "stdclass", ")", "[", "@registry", ".", "processors", "[", "stdclass", "]", ".", "idtype", ",", "code", "]", "end" ]
The document identifier class corresponding to the given code
[ "The", "document", "identifier", "class", "corresponding", "to", "the", "given", "code" ]
2fac19da2f3ef3c30b8e8d8815a14d2115df0be6
https://github.com/metanorma/relaton/blob/2fac19da2f3ef3c30b8e8d8815a14d2115df0be6/lib/relaton/db.rb#L64-L68
train
metanorma/relaton
lib/relaton/db.rb
Relaton.Db.to_xml
def to_xml db = @local_db || @db || return Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml| xml.documents do xml.parent.add_child db.all.join(" ") end end.to_xml end
ruby
def to_xml db = @local_db || @db || return Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml| xml.documents do xml.parent.add_child db.all.join(" ") end end.to_xml end
[ "def", "to_xml", "db", "=", "@local_db", "||", "@db", "||", "return", "Nokogiri", "::", "XML", "::", "Builder", ".", "new", "(", "encoding", ":", "\"UTF-8\"", ")", "do", "|", "xml", "|", "xml", ".", "documents", "do", "xml", ".", "parent", ".", "add_child", "db", ".", "all", ".", "join", "(", "\" \"", ")", "end", "end", ".", "to_xml", "end" ]
list all entries as a serialization @return [String]
[ "list", "all", "entries", "as", "a", "serialization" ]
2fac19da2f3ef3c30b8e8d8815a14d2115df0be6
https://github.com/metanorma/relaton/blob/2fac19da2f3ef3c30b8e8d8815a14d2115df0be6/lib/relaton/db.rb#L90-L97
train
metanorma/relaton
lib/relaton/db.rb
Relaton.Db.new_bib_entry
def new_bib_entry(code, year, opts, stdclass) bib = @registry.processors[stdclass].get(code, year, opts) bib = bib.to_xml if bib.respond_to? :to_xml bib = "not_found #{Date.today}" if bib.nil? || bib.empty? bib end
ruby
def new_bib_entry(code, year, opts, stdclass) bib = @registry.processors[stdclass].get(code, year, opts) bib = bib.to_xml if bib.respond_to? :to_xml bib = "not_found #{Date.today}" if bib.nil? || bib.empty? bib end
[ "def", "new_bib_entry", "(", "code", ",", "year", ",", "opts", ",", "stdclass", ")", "bib", "=", "@registry", ".", "processors", "[", "stdclass", "]", ".", "get", "(", "code", ",", "year", ",", "opts", ")", "bib", "=", "bib", ".", "to_xml", "if", "bib", ".", "respond_to?", ":to_xml", "bib", "=", "\"not_found #{Date.today}\"", "if", "bib", ".", "nil?", "||", "bib", ".", "empty?", "bib", "end" ]
hash uses => , because the hash is imported from JSON @param code [String] @param year [String] @param opts [Hash] @param stdclass [Symbol] @return [Hash]
[ "hash", "uses", "=", ">", "because", "the", "hash", "is", "imported", "from", "JSON" ]
2fac19da2f3ef3c30b8e8d8815a14d2115df0be6
https://github.com/metanorma/relaton/blob/2fac19da2f3ef3c30b8e8d8815a14d2115df0be6/lib/relaton/db.rb#L171-L176
train
metanorma/relaton
lib/relaton/db_cache.rb
Relaton.DbCache.all
def all Dir.glob("#{@dir}/**/*.xml").sort.map do |f| File.read(f, encoding: "utf-8") end end
ruby
def all Dir.glob("#{@dir}/**/*.xml").sort.map do |f| File.read(f, encoding: "utf-8") end end
[ "def", "all", "Dir", ".", "glob", "(", "\"#{@dir}/**/*.xml\"", ")", ".", "sort", ".", "map", "do", "|", "f", "|", "File", ".", "read", "(", "f", ",", "encoding", ":", "\"utf-8\"", ")", "end", "end" ]
Returns all items @return [Array<Hash>]
[ "Returns", "all", "items" ]
2fac19da2f3ef3c30b8e8d8815a14d2115df0be6
https://github.com/metanorma/relaton/blob/2fac19da2f3ef3c30b8e8d8815a14d2115df0be6/lib/relaton/db_cache.rb#L52-L56
train
ZestFinance/zestphone
app/models/telephony/call.rb
Telephony.Call.terminate_conversation_and_all_call_legs
def terminate_conversation_and_all_call_legs(trace_only = false) if self.conversation Rails.logger.info "zestphone: ** Terminating all linked calls and conversation **" Rails.logger.info "zestphone: conversation - (pre) state: #{self.conversation.state}" Rails.logger.info "zestphone: conversation - (pre) details: #{self.conversation.inspect}" Rails.logger.info "zestphone: calls - (pre) states: #{self.conversation.calls.map(&:state)}" Rails.logger.info "zestphone: calls - (pre) details: #{self.conversation.calls.map(&:inspect)}" unless trace_only self.conversation.calls.each do |c| c.terminate end self.conversation.terminate end else # Conversation not found - terminate the current call anyway Rails.logger.info "zestphone: call - details: #{self.inspect}" self.terminate unless trace_only end end
ruby
def terminate_conversation_and_all_call_legs(trace_only = false) if self.conversation Rails.logger.info "zestphone: ** Terminating all linked calls and conversation **" Rails.logger.info "zestphone: conversation - (pre) state: #{self.conversation.state}" Rails.logger.info "zestphone: conversation - (pre) details: #{self.conversation.inspect}" Rails.logger.info "zestphone: calls - (pre) states: #{self.conversation.calls.map(&:state)}" Rails.logger.info "zestphone: calls - (pre) details: #{self.conversation.calls.map(&:inspect)}" unless trace_only self.conversation.calls.each do |c| c.terminate end self.conversation.terminate end else # Conversation not found - terminate the current call anyway Rails.logger.info "zestphone: call - details: #{self.inspect}" self.terminate unless trace_only end end
[ "def", "terminate_conversation_and_all_call_legs", "(", "trace_only", "=", "false", ")", "if", "self", ".", "conversation", "Rails", ".", "logger", ".", "info", "\"zestphone: ** Terminating all linked calls and conversation **\"", "Rails", ".", "logger", ".", "info", "\"zestphone: conversation - (pre) state: #{self.conversation.state}\"", "Rails", ".", "logger", ".", "info", "\"zestphone: conversation - (pre) details: #{self.conversation.inspect}\"", "Rails", ".", "logger", ".", "info", "\"zestphone: calls - (pre) states: #{self.conversation.calls.map(&:state)}\"", "Rails", ".", "logger", ".", "info", "\"zestphone: calls - (pre) details: #{self.conversation.calls.map(&:inspect)}\"", "unless", "trace_only", "self", ".", "conversation", ".", "calls", ".", "each", "do", "|", "c", "|", "c", ".", "terminate", "end", "self", ".", "conversation", ".", "terminate", "end", "else", "Rails", ".", "logger", ".", "info", "\"zestphone: call - details: #{self.inspect}\"", "self", ".", "terminate", "unless", "trace_only", "end", "end" ]
Nuclear termination if trace_only is "true", we only print what we're going to do but not actually do it
[ "Nuclear", "termination", "if", "trace_only", "is", "true", "we", "only", "print", "what", "we", "re", "going", "to", "do", "but", "not", "actually", "do", "it" ]
8f8b81d5bf33229ada36f74319799834ecda1599
https://github.com/ZestFinance/zestphone/blob/8f8b81d5bf33229ada36f74319799834ecda1599/app/models/telephony/call.rb#L86-L107
train
phaxio/phaxio-ruby
lib/phaxio/resource.rb
Phaxio.Resource.populate_attributes
def populate_attributes self.class.normal_attribute_list.each do |normal_attribute| self.public_send "#{normal_attribute}=", raw_data[normal_attribute] end self.class.time_attribute_list.each do |time_attribute| time = raw_data[time_attribute] time = Time.parse(time) if !time.nil? self.public_send "#{time_attribute}=", time end self.class.collection_attribute_mappings.each do |collection_attribute, klass| collection = raw_data[collection_attribute] || [] collection = {'data' => collection} collection = klass.response_collection(collection) self.public_send "#{collection_attribute}=", collection end end
ruby
def populate_attributes self.class.normal_attribute_list.each do |normal_attribute| self.public_send "#{normal_attribute}=", raw_data[normal_attribute] end self.class.time_attribute_list.each do |time_attribute| time = raw_data[time_attribute] time = Time.parse(time) if !time.nil? self.public_send "#{time_attribute}=", time end self.class.collection_attribute_mappings.each do |collection_attribute, klass| collection = raw_data[collection_attribute] || [] collection = {'data' => collection} collection = klass.response_collection(collection) self.public_send "#{collection_attribute}=", collection end end
[ "def", "populate_attributes", "self", ".", "class", ".", "normal_attribute_list", ".", "each", "do", "|", "normal_attribute", "|", "self", ".", "public_send", "\"#{normal_attribute}=\"", ",", "raw_data", "[", "normal_attribute", "]", "end", "self", ".", "class", ".", "time_attribute_list", ".", "each", "do", "|", "time_attribute", "|", "time", "=", "raw_data", "[", "time_attribute", "]", "time", "=", "Time", ".", "parse", "(", "time", ")", "if", "!", "time", ".", "nil?", "self", ".", "public_send", "\"#{time_attribute}=\"", ",", "time", "end", "self", ".", "class", ".", "collection_attribute_mappings", ".", "each", "do", "|", "collection_attribute", ",", "klass", "|", "collection", "=", "raw_data", "[", "collection_attribute", "]", "||", "[", "]", "collection", "=", "{", "'data'", "=>", "collection", "}", "collection", "=", "klass", ".", "response_collection", "(", "collection", ")", "self", ".", "public_send", "\"#{collection_attribute}=\"", ",", "collection", "end", "end" ]
Populates the instance's attributes based on the `raw_data`.
[ "Populates", "the", "instance", "s", "attributes", "based", "on", "the", "raw_data", "." ]
eb701a0333da068844f0c7bba45ce70caff39148
https://github.com/phaxio/phaxio-ruby/blob/eb701a0333da068844f0c7bba45ce70caff39148/lib/phaxio/resource.rb#L17-L34
train
patricklindsay/will_paginate-materialize
lib/materialize_pagination/view_helpers.rb
MaterializePagination.ViewHelpers.will_paginate
def will_paginate(collection_or_options = nil, options = {}) if collection_or_options.is_a? Hash options, collection_or_options = collection_or_options, nil end unless options[:renderer] options = options.merge :renderer => MaterializePagination::Rails end super *[collection_or_options, options].compact end
ruby
def will_paginate(collection_or_options = nil, options = {}) if collection_or_options.is_a? Hash options, collection_or_options = collection_or_options, nil end unless options[:renderer] options = options.merge :renderer => MaterializePagination::Rails end super *[collection_or_options, options].compact end
[ "def", "will_paginate", "(", "collection_or_options", "=", "nil", ",", "options", "=", "{", "}", ")", "if", "collection_or_options", ".", "is_a?", "Hash", "options", ",", "collection_or_options", "=", "collection_or_options", ",", "nil", "end", "unless", "options", "[", ":renderer", "]", "options", "=", "options", ".", "merge", ":renderer", "=>", "MaterializePagination", "::", "Rails", "end", "super", "*", "[", "collection_or_options", ",", "options", "]", ".", "compact", "end" ]
Change the default link renderer for will_paginate
[ "Change", "the", "default", "link", "renderer", "for", "will_paginate" ]
732aa4f4bdfeff9a63052ef2e9aaa78318833dfe
https://github.com/patricklindsay/will_paginate-materialize/blob/732aa4f4bdfeff9a63052ef2e9aaa78318833dfe/lib/materialize_pagination/view_helpers.rb#L4-L12
train
pascalh1011/migrant
lib/dsl/data_type.rb
DataType.Base.structure_changes_from
def structure_changes_from(current_structure = nil) new_structure = column if current_structure # General RDBMS data loss scenarios if new_structure[:limit] && current_structure[:limit].to_i != new_structure[:limit].to_i || new_structure[:type] != current_structure[:type] || !new_structure[:default].nil? && column_default_changed?(current_structure[:default], new_structure[:default]) column else nil # No changes end else column end end
ruby
def structure_changes_from(current_structure = nil) new_structure = column if current_structure # General RDBMS data loss scenarios if new_structure[:limit] && current_structure[:limit].to_i != new_structure[:limit].to_i || new_structure[:type] != current_structure[:type] || !new_structure[:default].nil? && column_default_changed?(current_structure[:default], new_structure[:default]) column else nil # No changes end else column end end
[ "def", "structure_changes_from", "(", "current_structure", "=", "nil", ")", "new_structure", "=", "column", "if", "current_structure", "if", "new_structure", "[", ":limit", "]", "&&", "current_structure", "[", ":limit", "]", ".", "to_i", "!=", "new_structure", "[", ":limit", "]", ".", "to_i", "||", "new_structure", "[", ":type", "]", "!=", "current_structure", "[", ":type", "]", "||", "!", "new_structure", "[", ":default", "]", ".", "nil?", "&&", "column_default_changed?", "(", "current_structure", "[", ":default", "]", ",", "new_structure", "[", ":default", "]", ")", "column", "else", "nil", "end", "else", "column", "end", "end" ]
Decides if and how a column will be changed Provide the details of a previously column, or simply nil to create a new column
[ "Decides", "if", "and", "how", "a", "column", "will", "be", "changed", "Provide", "the", "details", "of", "a", "previously", "column", "or", "simply", "nil", "to", "create", "a", "new", "column" ]
9415e0d4d26565b72972ccff39a17ffc5de71100
https://github.com/pascalh1011/migrant/blob/9415e0d4d26565b72972ccff39a17ffc5de71100/lib/dsl/data_type.rb#L55-L71
train
InfoTech/salesforce_ar_sync
lib/salesforce_ar_sync/salesforce_sync.rb
SalesforceArSync.SalesforceSync.salesforce_attributes_to_set
def salesforce_attributes_to_set(attributes = {}) {}.tap do |hash| # loop through the hash of attributes from the outbound message, and compare to our sf mappings and # create a reversed hash of value's and key's to pass to update_attributes attributes.each do |key, value| # make sure our sync_mapping contains the salesforce attribute AND that our object has a setter for it hash[self.class.salesforce_sync_attribute_mapping[key.to_s].to_sym] = value if self.class.salesforce_sync_attribute_mapping.include?(key.to_s) && self.respond_to?("#{self.class.salesforce_sync_attribute_mapping[key.to_s]}=") end # remove the web_id from hash if it exists, as we don't want to modify a web_id hash.delete(:id) if hash[:id] # update the sf_updated_at field with the system mod stamp from sf hash[:salesforce_updated_at] = attributes[:SystemModstamp] # incase we looked up via the WebId__c, we should set the salesforce_id hash[:salesforce_id] = attributes[self.class.salesforce_id_attribute_name] end end
ruby
def salesforce_attributes_to_set(attributes = {}) {}.tap do |hash| # loop through the hash of attributes from the outbound message, and compare to our sf mappings and # create a reversed hash of value's and key's to pass to update_attributes attributes.each do |key, value| # make sure our sync_mapping contains the salesforce attribute AND that our object has a setter for it hash[self.class.salesforce_sync_attribute_mapping[key.to_s].to_sym] = value if self.class.salesforce_sync_attribute_mapping.include?(key.to_s) && self.respond_to?("#{self.class.salesforce_sync_attribute_mapping[key.to_s]}=") end # remove the web_id from hash if it exists, as we don't want to modify a web_id hash.delete(:id) if hash[:id] # update the sf_updated_at field with the system mod stamp from sf hash[:salesforce_updated_at] = attributes[:SystemModstamp] # incase we looked up via the WebId__c, we should set the salesforce_id hash[:salesforce_id] = attributes[self.class.salesforce_id_attribute_name] end end
[ "def", "salesforce_attributes_to_set", "(", "attributes", "=", "{", "}", ")", "{", "}", ".", "tap", "do", "|", "hash", "|", "attributes", ".", "each", "do", "|", "key", ",", "value", "|", "hash", "[", "self", ".", "class", ".", "salesforce_sync_attribute_mapping", "[", "key", ".", "to_s", "]", ".", "to_sym", "]", "=", "value", "if", "self", ".", "class", ".", "salesforce_sync_attribute_mapping", ".", "include?", "(", "key", ".", "to_s", ")", "&&", "self", ".", "respond_to?", "(", "\"#{self.class.salesforce_sync_attribute_mapping[key.to_s]}=\"", ")", "end", "hash", ".", "delete", "(", ":id", ")", "if", "hash", "[", ":id", "]", "hash", "[", ":salesforce_updated_at", "]", "=", "attributes", "[", ":SystemModstamp", "]", "hash", "[", ":salesforce_id", "]", "=", "attributes", "[", "self", ".", "class", ".", "salesforce_id_attribute_name", "]", "end", "end" ]
An internal method used to get a hash of values that we are going to set from a Salesforce outbound message hash
[ "An", "internal", "method", "used", "to", "get", "a", "hash", "of", "values", "that", "we", "are", "going", "to", "set", "from", "a", "Salesforce", "outbound", "message", "hash" ]
3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4
https://github.com/InfoTech/salesforce_ar_sync/blob/3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4/lib/salesforce_ar_sync/salesforce_sync.rb#L99-L117
train
InfoTech/salesforce_ar_sync
lib/salesforce_ar_sync/salesforce_sync.rb
SalesforceArSync.SalesforceSync.salesforce_process_update
def salesforce_process_update(attributes = {}) attributes_to_update = salesforce_attributes_to_set(self.new_record? ? attributes : salesforce_empty_attributes.merge(attributes)) # only merge empty attributes for updates, so we don't overwrite the default create attributes attributes_to_update.each_pair do |k, v| self.send("#{k}=", v) end # we don't want to keep going in a endless loop. SF has just updated these values. self.salesforce_skip_sync = true self.save! end
ruby
def salesforce_process_update(attributes = {}) attributes_to_update = salesforce_attributes_to_set(self.new_record? ? attributes : salesforce_empty_attributes.merge(attributes)) # only merge empty attributes for updates, so we don't overwrite the default create attributes attributes_to_update.each_pair do |k, v| self.send("#{k}=", v) end # we don't want to keep going in a endless loop. SF has just updated these values. self.salesforce_skip_sync = true self.save! end
[ "def", "salesforce_process_update", "(", "attributes", "=", "{", "}", ")", "attributes_to_update", "=", "salesforce_attributes_to_set", "(", "self", ".", "new_record?", "?", "attributes", ":", "salesforce_empty_attributes", ".", "merge", "(", "attributes", ")", ")", "attributes_to_update", ".", "each_pair", "do", "|", "k", ",", "v", "|", "self", ".", "send", "(", "\"#{k}=\"", ",", "v", ")", "end", "self", ".", "salesforce_skip_sync", "=", "true", "self", ".", "save!", "end" ]
Gets passed the Salesforce outbound message hash of changed values and updates the corresponding model
[ "Gets", "passed", "the", "Salesforce", "outbound", "message", "hash", "of", "changed", "values", "and", "updates", "the", "corresponding", "model" ]
3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4
https://github.com/InfoTech/salesforce_ar_sync/blob/3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4/lib/salesforce_ar_sync/salesforce_sync.rb#L120-L129
train
InfoTech/salesforce_ar_sync
lib/salesforce_ar_sync/salesforce_sync.rb
SalesforceArSync.SalesforceSync.system_mod_stamp
def system_mod_stamp hash = JSON.parse(SF_CLIENT.http_get("/services/data/v#{SF_CLIENT.version}/query", :q => "SELECT SystemModstamp FROM #{salesforce_object_name} WHERE Id = '#{salesforce_id}'").body) hash["records"].first.try(:[], "SystemModstamp") end
ruby
def system_mod_stamp hash = JSON.parse(SF_CLIENT.http_get("/services/data/v#{SF_CLIENT.version}/query", :q => "SELECT SystemModstamp FROM #{salesforce_object_name} WHERE Id = '#{salesforce_id}'").body) hash["records"].first.try(:[], "SystemModstamp") end
[ "def", "system_mod_stamp", "hash", "=", "JSON", ".", "parse", "(", "SF_CLIENT", ".", "http_get", "(", "\"/services/data/v#{SF_CLIENT.version}/query\"", ",", ":q", "=>", "\"SELECT SystemModstamp FROM #{salesforce_object_name} WHERE Id = '#{salesforce_id}'\"", ")", ".", "body", ")", "hash", "[", "\"records\"", "]", ".", "first", ".", "try", "(", ":[]", ",", "\"SystemModstamp\"", ")", "end" ]
def salesforce_object_exists? return salesforce_object_exists_method if respond_to? salesforce_exists_method return salesforce_object_exists_default end Finds a salesforce record by its Id and returns nil or its SystemModstamp
[ "def", "salesforce_object_exists?", "return", "salesforce_object_exists_method", "if", "respond_to?", "salesforce_exists_method", "return", "salesforce_object_exists_default", "end", "Finds", "a", "salesforce", "record", "by", "its", "Id", "and", "returns", "nil", "or", "its", "SystemModstamp" ]
3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4
https://github.com/InfoTech/salesforce_ar_sync/blob/3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4/lib/salesforce_ar_sync/salesforce_sync.rb#L138-L141
train
InfoTech/salesforce_ar_sync
lib/salesforce_ar_sync/salesforce_sync.rb
SalesforceArSync.SalesforceSync.salesforce_attributes_to_update
def salesforce_attributes_to_update(include_all = false) {}.tap do |hash| self.class.salesforce_sync_attribute_mapping.each do |key, value| if self.respond_to?(value) #Checkboxes in SFDC Cannot be nil. Here we check for boolean field type and set nil values to be false attribute_value = self.send(value) if is_boolean?(value) && attribute_value.nil? attribute_value = false end hash[key] = attribute_value if include_all || salesforce_should_update_attribute?(value) end end end end
ruby
def salesforce_attributes_to_update(include_all = false) {}.tap do |hash| self.class.salesforce_sync_attribute_mapping.each do |key, value| if self.respond_to?(value) #Checkboxes in SFDC Cannot be nil. Here we check for boolean field type and set nil values to be false attribute_value = self.send(value) if is_boolean?(value) && attribute_value.nil? attribute_value = false end hash[key] = attribute_value if include_all || salesforce_should_update_attribute?(value) end end end end
[ "def", "salesforce_attributes_to_update", "(", "include_all", "=", "false", ")", "{", "}", ".", "tap", "do", "|", "hash", "|", "self", ".", "class", ".", "salesforce_sync_attribute_mapping", ".", "each", "do", "|", "key", ",", "value", "|", "if", "self", ".", "respond_to?", "(", "value", ")", "attribute_value", "=", "self", ".", "send", "(", "value", ")", "if", "is_boolean?", "(", "value", ")", "&&", "attribute_value", ".", "nil?", "attribute_value", "=", "false", "end", "hash", "[", "key", "]", "=", "attribute_value", "if", "include_all", "||", "salesforce_should_update_attribute?", "(", "value", ")", "end", "end", "end", "end" ]
create a hash of updates to send to salesforce
[ "create", "a", "hash", "of", "updates", "to", "send", "to", "salesforce" ]
3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4
https://github.com/InfoTech/salesforce_ar_sync/blob/3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4/lib/salesforce_ar_sync/salesforce_sync.rb#L155-L170
train
InfoTech/salesforce_ar_sync
lib/salesforce_ar_sync/salesforce_sync.rb
SalesforceArSync.SalesforceSync.salesforce_perform_async_call?
def salesforce_perform_async_call? return false if salesforce_attributes_to_update.empty? || self.class.salesforce_async_attributes.empty? salesforce_attributes_to_update.keys.all? {|key| self.class.salesforce_async_attributes.include?(key) } && salesforce_id.present? end
ruby
def salesforce_perform_async_call? return false if salesforce_attributes_to_update.empty? || self.class.salesforce_async_attributes.empty? salesforce_attributes_to_update.keys.all? {|key| self.class.salesforce_async_attributes.include?(key) } && salesforce_id.present? end
[ "def", "salesforce_perform_async_call?", "return", "false", "if", "salesforce_attributes_to_update", ".", "empty?", "||", "self", ".", "class", ".", "salesforce_async_attributes", ".", "empty?", "salesforce_attributes_to_update", ".", "keys", ".", "all?", "{", "|", "key", "|", "self", ".", "class", ".", "salesforce_async_attributes", ".", "include?", "(", "key", ")", "}", "&&", "salesforce_id", ".", "present?", "end" ]
if attributes specified in the async_attributes array are the only attributes being modified, then sync the data via delayed_job
[ "if", "attributes", "specified", "in", "the", "async_attributes", "array", "are", "the", "only", "attributes", "being", "modified", "then", "sync", "the", "data", "via", "delayed_job" ]
3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4
https://github.com/InfoTech/salesforce_ar_sync/blob/3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4/lib/salesforce_ar_sync/salesforce_sync.rb#L206-L209
train
InfoTech/salesforce_ar_sync
lib/salesforce_ar_sync/salesforce_sync.rb
SalesforceArSync.SalesforceSync.salesforce_sync
def salesforce_sync return if self.salesforce_skip_sync? if salesforce_perform_async_call? Delayed::Job.enqueue(SalesforceArSync::SalesforceObjectSync.new(self.class.salesforce_web_class_name, salesforce_id, salesforce_attributes_to_update), :priority => 50) else if salesforce_object_exists? salesforce_update_object(salesforce_attributes_to_update) if salesforce_attributes_to_update.present? else salesforce_create_object(salesforce_attributes_to_update(!new_record?)) if salesforce_id.nil? end end rescue Exception => ex self.errors[:base] << ex.message return false end
ruby
def salesforce_sync return if self.salesforce_skip_sync? if salesforce_perform_async_call? Delayed::Job.enqueue(SalesforceArSync::SalesforceObjectSync.new(self.class.salesforce_web_class_name, salesforce_id, salesforce_attributes_to_update), :priority => 50) else if salesforce_object_exists? salesforce_update_object(salesforce_attributes_to_update) if salesforce_attributes_to_update.present? else salesforce_create_object(salesforce_attributes_to_update(!new_record?)) if salesforce_id.nil? end end rescue Exception => ex self.errors[:base] << ex.message return false end
[ "def", "salesforce_sync", "return", "if", "self", ".", "salesforce_skip_sync?", "if", "salesforce_perform_async_call?", "Delayed", "::", "Job", ".", "enqueue", "(", "SalesforceArSync", "::", "SalesforceObjectSync", ".", "new", "(", "self", ".", "class", ".", "salesforce_web_class_name", ",", "salesforce_id", ",", "salesforce_attributes_to_update", ")", ",", ":priority", "=>", "50", ")", "else", "if", "salesforce_object_exists?", "salesforce_update_object", "(", "salesforce_attributes_to_update", ")", "if", "salesforce_attributes_to_update", ".", "present?", "else", "salesforce_create_object", "(", "salesforce_attributes_to_update", "(", "!", "new_record?", ")", ")", "if", "salesforce_id", ".", "nil?", "end", "end", "rescue", "Exception", "=>", "ex", "self", ".", "errors", "[", ":base", "]", "<<", "ex", ".", "message", "return", "false", "end" ]
sync model data to Salesforce, adding any Salesforce validation errors to the models errors
[ "sync", "model", "data", "to", "Salesforce", "adding", "any", "Salesforce", "validation", "errors", "to", "the", "models", "errors" ]
3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4
https://github.com/InfoTech/salesforce_ar_sync/blob/3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4/lib/salesforce_ar_sync/salesforce_sync.rb#L212-L226
train
InfoTech/salesforce_ar_sync
app/controllers/salesforce_ar_sync/soap_message_controller.rb
SalesforceArSync.SoapMessageController.validate_ip_ranges
def validate_ip_ranges raise ActionController::RoutingError.new('Not Found') unless SalesforceArSync::IPConstraint.new.matches?(request) end
ruby
def validate_ip_ranges raise ActionController::RoutingError.new('Not Found') unless SalesforceArSync::IPConstraint.new.matches?(request) end
[ "def", "validate_ip_ranges", "raise", "ActionController", "::", "RoutingError", ".", "new", "(", "'Not Found'", ")", "unless", "SalesforceArSync", "::", "IPConstraint", ".", "new", ".", "matches?", "(", "request", ")", "end" ]
to be used in a before_filter, checks ip ranges specified in configuration and renders a 404 unless the request matches
[ "to", "be", "used", "in", "a", "before_filter", "checks", "ip", "ranges", "specified", "in", "configuration", "and", "renders", "a", "404", "unless", "the", "request", "matches" ]
3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4
https://github.com/InfoTech/salesforce_ar_sync/blob/3f6351fe462cc7374b8f00c0f36e8c8cfd9c39c4/app/controllers/salesforce_ar_sync/soap_message_controller.rb#L29-L31
train
futuresimple/api_client
lib/api_client/scope.rb
ApiClient.Scope.request
def request(method, path, options = {}) options = options.dup raw = raw? || options.delete(:raw) params(options) response = connection.send method, path, (@raw_body || @params), @headers raw ? response : @scopeable.parse(response) end
ruby
def request(method, path, options = {}) options = options.dup raw = raw? || options.delete(:raw) params(options) response = connection.send method, path, (@raw_body || @params), @headers raw ? response : @scopeable.parse(response) end
[ "def", "request", "(", "method", ",", "path", ",", "options", "=", "{", "}", ")", "options", "=", "options", ".", "dup", "raw", "=", "raw?", "||", "options", ".", "delete", "(", ":raw", ")", "params", "(", "options", ")", "response", "=", "connection", ".", "send", "method", ",", "path", ",", "(", "@raw_body", "||", "@params", ")", ",", "@headers", "raw", "?", "response", ":", "@scopeable", ".", "parse", "(", "response", ")", "end" ]
Low-level connection methods
[ "Low", "-", "level", "connection", "methods" ]
75d664fbbac60204415924c1fedf12b7bc4634a1
https://github.com/futuresimple/api_client/blob/75d664fbbac60204415924c1fedf12b7bc4634a1/lib/api_client/scope.rb#L83-L90
train
alphagov/govuk_schemas
lib/govuk_schemas/random_example.rb
GovukSchemas.RandomExample.payload
def payload payload = @random_generator.payload # ensure the base payload is valid errors = validation_errors_for(payload) raise InvalidContentGenerated, error_message(payload, errors) if errors.any? if block_given? payload = yield(payload) # check the payload again after customisation errors = validation_errors_for(payload) raise InvalidContentGenerated, error_message(payload, errors, true) if errors.any? end payload end
ruby
def payload payload = @random_generator.payload # ensure the base payload is valid errors = validation_errors_for(payload) raise InvalidContentGenerated, error_message(payload, errors) if errors.any? if block_given? payload = yield(payload) # check the payload again after customisation errors = validation_errors_for(payload) raise InvalidContentGenerated, error_message(payload, errors, true) if errors.any? end payload end
[ "def", "payload", "payload", "=", "@random_generator", ".", "payload", "errors", "=", "validation_errors_for", "(", "payload", ")", "raise", "InvalidContentGenerated", ",", "error_message", "(", "payload", ",", "errors", ")", "if", "errors", ".", "any?", "if", "block_given?", "payload", "=", "yield", "(", "payload", ")", "errors", "=", "validation_errors_for", "(", "payload", ")", "raise", "InvalidContentGenerated", ",", "error_message", "(", "payload", ",", "errors", ",", "true", ")", "if", "errors", ".", "any?", "end", "payload", "end" ]
Return a content item merged with a hash and with the excluded fields removed. If the resulting content item isn't valid against the schema an error will be raised. Example without block: generator.payload # => {"base_path"=>"/e42dd28e", "title"=>"dolor est...", "publishing_app"=>"elit"...} Example with block: generator.payload do |payload| payload.merge('base_path' => "Test base path") end # => {"base_path"=>"Test base path", "title"=>"dolor est...", "publishing_app"=>"elit"...} @param [Block] the base payload is passed inton the block, with the block result then becoming the new payload. The new payload is then validated. (optional) @return [Hash] A content item @raise [GovukSchemas::InvalidContentGenerated]
[ "Return", "a", "content", "item", "merged", "with", "a", "hash", "and", "with", "the", "excluded", "fields", "removed", ".", "If", "the", "resulting", "content", "item", "isn", "t", "valid", "against", "the", "schema", "an", "error", "will", "be", "raised", "." ]
f709a10cd2af63b29c22288fc7e0ad6af426926a
https://github.com/alphagov/govuk_schemas/blob/f709a10cd2af63b29c22288fc7e0ad6af426926a/lib/govuk_schemas/random_example.rb#L78-L92
train
gopherst/hidemyass
lib/hidemyass/ip.rb
HideMyAss.IP.decode
def decode(elements) elements.each do |element| # Remove elements with CSS style "none" if !TAGS.include?(element.name) || (element["style"] && element["style"] =~ /none/) element.children.remove # Get rid of decoy children elsif element["class"] decoys.each do |decoy| element.children.remove if decoy.include?(element["class"]) end end end elements end
ruby
def decode(elements) elements.each do |element| # Remove elements with CSS style "none" if !TAGS.include?(element.name) || (element["style"] && element["style"] =~ /none/) element.children.remove # Get rid of decoy children elsif element["class"] decoys.each do |decoy| element.children.remove if decoy.include?(element["class"]) end end end elements end
[ "def", "decode", "(", "elements", ")", "elements", ".", "each", "do", "|", "element", "|", "if", "!", "TAGS", ".", "include?", "(", "element", ".", "name", ")", "||", "(", "element", "[", "\"style\"", "]", "&&", "element", "[", "\"style\"", "]", "=~", "/", "/", ")", "element", ".", "children", ".", "remove", "elsif", "element", "[", "\"class\"", "]", "decoys", ".", "each", "do", "|", "decoy", "|", "element", ".", "children", ".", "remove", "if", "decoy", ".", "include?", "(", "element", "[", "\"class\"", "]", ")", "end", "end", "end", "elements", "end" ]
Receives an array of elements and returns another without invisibles.
[ "Receives", "an", "array", "of", "elements", "and", "returns", "another", "without", "invisibles", "." ]
9011e43237c68c4e96e0137fdb550fcef23de8eb
https://github.com/gopherst/hidemyass/blob/9011e43237c68c4e96e0137fdb550fcef23de8eb/lib/hidemyass/ip.rb#L29-L45
train
norman/ambry
lib/ambry/abstract_key_set.rb
Ambry.AbstractKeySet.count
def count(&block) return keys.count unless block_given? proxy = HashProxy.new keys.inject(0) do |count, key| proxy.with(mapper[key], &block) ? count.succ : count end end
ruby
def count(&block) return keys.count unless block_given? proxy = HashProxy.new keys.inject(0) do |count, key| proxy.with(mapper[key], &block) ? count.succ : count end end
[ "def", "count", "(", "&", "block", ")", "return", "keys", ".", "count", "unless", "block_given?", "proxy", "=", "HashProxy", ".", "new", "keys", ".", "inject", "(", "0", ")", "do", "|", "count", ",", "key", "|", "proxy", ".", "with", "(", "mapper", "[", "key", "]", ",", "&", "block", ")", "?", "count", ".", "succ", ":", "count", "end", "end" ]
With no block, returns the number of keys. If a block is given, counts the number of elements yielding a true value.
[ "With", "no", "block", "returns", "the", "number", "of", "keys", ".", "If", "a", "block", "is", "given", "counts", "the", "number", "of", "elements", "yielding", "a", "true", "value", "." ]
f6563b0d3c881ace9839114f8a8b6e2f26ab9d07
https://github.com/norman/ambry/blob/f6563b0d3c881ace9839114f8a8b6e2f26ab9d07/lib/ambry/abstract_key_set.rb#L52-L58
train
misshie/interval-tree
lib/interval_tree.rb
IntervalTree.Tree.center
def center(intervals) i = intervals.reduce([intervals.first.first, intervals.first.last]) { |acc, int| [[acc.first, int.first].min, [acc.last, int.last].max] } i.first + (i.last - i.first) / 2 end
ruby
def center(intervals) i = intervals.reduce([intervals.first.first, intervals.first.last]) { |acc, int| [[acc.first, int.first].min, [acc.last, int.last].max] } i.first + (i.last - i.first) / 2 end
[ "def", "center", "(", "intervals", ")", "i", "=", "intervals", ".", "reduce", "(", "[", "intervals", ".", "first", ".", "first", ",", "intervals", ".", "first", ".", "last", "]", ")", "{", "|", "acc", ",", "int", "|", "[", "[", "acc", ".", "first", ",", "int", ".", "first", "]", ".", "min", ",", "[", "acc", ".", "last", ",", "int", ".", "last", "]", ".", "max", "]", "}", "i", ".", "first", "+", "(", "i", ".", "last", "-", "i", ".", "first", ")", "/", "2", "end" ]
augmented tree using a start point as resresentative value of the node
[ "augmented", "tree", "using", "a", "start", "point", "as", "resresentative", "value", "of", "the", "node" ]
14955993828edc004d4386da1bb429271dbecaa8
https://github.com/misshie/interval-tree/blob/14955993828edc004d4386da1bb429271dbecaa8/lib/interval_tree.rb#L97-L100
train
norman/ambry
lib/ambry/hash_proxy.rb
Ambry.HashProxy.method_missing
def method_missing(symbol) if hash.key?(symbol) hash[symbol] elsif hash.key?(symbol.to_s) hash[symbol.to_s] else raise NoMethodError end end
ruby
def method_missing(symbol) if hash.key?(symbol) hash[symbol] elsif hash.key?(symbol.to_s) hash[symbol.to_s] else raise NoMethodError end end
[ "def", "method_missing", "(", "symbol", ")", "if", "hash", ".", "key?", "(", "symbol", ")", "hash", "[", "symbol", "]", "elsif", "hash", ".", "key?", "(", "symbol", ".", "to_s", ")", "hash", "[", "symbol", ".", "to_s", "]", "else", "raise", "NoMethodError", "end", "end" ]
Allows accessing a hash attribute as a method.
[ "Allows", "accessing", "a", "hash", "attribute", "as", "a", "method", "." ]
f6563b0d3c881ace9839114f8a8b6e2f26ab9d07
https://github.com/norman/ambry/blob/f6563b0d3c881ace9839114f8a8b6e2f26ab9d07/lib/ambry/hash_proxy.rb#L14-L22
train
norman/ambry
lib/ambry/hash_proxy.rb
Ambry.HashProxy.[]
def [](key) if hash.key?(key) then hash[key] elsif hash.key?(key.to_sym) then hash[key.to_sym] elsif hash.key?(key.to_s) then hash[key.to_s] end end
ruby
def [](key) if hash.key?(key) then hash[key] elsif hash.key?(key.to_sym) then hash[key.to_sym] elsif hash.key?(key.to_s) then hash[key.to_s] end end
[ "def", "[]", "(", "key", ")", "if", "hash", ".", "key?", "(", "key", ")", "then", "hash", "[", "key", "]", "elsif", "hash", ".", "key?", "(", "key", ".", "to_sym", ")", "then", "hash", "[", "key", ".", "to_sym", "]", "elsif", "hash", ".", "key?", "(", "key", ".", "to_s", ")", "then", "hash", "[", "key", ".", "to_s", "]", "end", "end" ]
Allows accessing a hash attribute as hash key, either a string or symbol.
[ "Allows", "accessing", "a", "hash", "attribute", "as", "hash", "key", "either", "a", "string", "or", "symbol", "." ]
f6563b0d3c881ace9839114f8a8b6e2f26ab9d07
https://github.com/norman/ambry/blob/f6563b0d3c881ace9839114f8a8b6e2f26ab9d07/lib/ambry/hash_proxy.rb#L25-L30
train
norman/ambry
lib/ambry/mapper.rb
Ambry.Mapper.[]=
def []=(key, value) @lock.synchronize do @indexes = {} if value.id_changed? hash.delete value.to_id(true) end saved = hash[key] = value.to_hash.freeze adapter.save_database if @options[:sync] saved end end
ruby
def []=(key, value) @lock.synchronize do @indexes = {} if value.id_changed? hash.delete value.to_id(true) end saved = hash[key] = value.to_hash.freeze adapter.save_database if @options[:sync] saved end end
[ "def", "[]=", "(", "key", ",", "value", ")", "@lock", ".", "synchronize", "do", "@indexes", "=", "{", "}", "if", "value", ".", "id_changed?", "hash", ".", "delete", "value", ".", "to_id", "(", "true", ")", "end", "saved", "=", "hash", "[", "key", "]", "=", "value", ".", "to_hash", ".", "freeze", "adapter", ".", "save_database", "if", "@options", "[", ":sync", "]", "saved", "end", "end" ]
Sets a hash by key.
[ "Sets", "a", "hash", "by", "key", "." ]
f6563b0d3c881ace9839114f8a8b6e2f26ab9d07
https://github.com/norman/ambry/blob/f6563b0d3c881ace9839114f8a8b6e2f26ab9d07/lib/ambry/mapper.rb#L28-L38
train
williambarry007/caboose-cms
app/models/caboose/invoice.rb
Caboose.Invoice.authorize_and_capture
def authorize_and_capture resp = StdClass.new if self.financial_status == Invoice::FINANCIAL_STATUS_CAPTURED resp.error = "Funds for this invoice have already been captured." else sc = self.site.store_config case sc.pp_name when StoreConfig::PAYMENT_PROCESSOR_STRIPE Stripe.api_key = sc.stripe_secret_key.strip bt = nil begin c = Stripe::Charge.create( :amount => (self.total * 100).to_i, :currency => 'usd', :customer => self.customer.stripe_customer_id, :capture => true, :metadata => { :invoice_id => self.id }, :statement_descriptor => "#{self.site.description.truncate(22)}" ) rescue Exception => ex resp.error = "Error during capture process\n#{ex.message}" end if resp.error.nil? InvoiceTransaction.create( :invoice_id => self.id, :transaction_id => c.id, :transaction_type => InvoiceTransaction::TYPE_AUTHCAP, :payment_processor => sc.pp_name, :amount => c.amount / 100.0, :captured => true, :date_processed => DateTime.now.utc, :success => c.status == 'succeeded' ) if c.status == 'succeeded' self.financial_status = Invoice::FINANCIAL_STATUS_CAPTURED self.save resp.success = true else resp.error = "Error capturing funds." end end end end return resp end
ruby
def authorize_and_capture resp = StdClass.new if self.financial_status == Invoice::FINANCIAL_STATUS_CAPTURED resp.error = "Funds for this invoice have already been captured." else sc = self.site.store_config case sc.pp_name when StoreConfig::PAYMENT_PROCESSOR_STRIPE Stripe.api_key = sc.stripe_secret_key.strip bt = nil begin c = Stripe::Charge.create( :amount => (self.total * 100).to_i, :currency => 'usd', :customer => self.customer.stripe_customer_id, :capture => true, :metadata => { :invoice_id => self.id }, :statement_descriptor => "#{self.site.description.truncate(22)}" ) rescue Exception => ex resp.error = "Error during capture process\n#{ex.message}" end if resp.error.nil? InvoiceTransaction.create( :invoice_id => self.id, :transaction_id => c.id, :transaction_type => InvoiceTransaction::TYPE_AUTHCAP, :payment_processor => sc.pp_name, :amount => c.amount / 100.0, :captured => true, :date_processed => DateTime.now.utc, :success => c.status == 'succeeded' ) if c.status == 'succeeded' self.financial_status = Invoice::FINANCIAL_STATUS_CAPTURED self.save resp.success = true else resp.error = "Error capturing funds." end end end end return resp end
[ "def", "authorize_and_capture", "resp", "=", "StdClass", ".", "new", "if", "self", ".", "financial_status", "==", "Invoice", "::", "FINANCIAL_STATUS_CAPTURED", "resp", ".", "error", "=", "\"Funds for this invoice have already been captured.\"", "else", "sc", "=", "self", ".", "site", ".", "store_config", "case", "sc", ".", "pp_name", "when", "StoreConfig", "::", "PAYMENT_PROCESSOR_STRIPE", "Stripe", ".", "api_key", "=", "sc", ".", "stripe_secret_key", ".", "strip", "bt", "=", "nil", "begin", "c", "=", "Stripe", "::", "Charge", ".", "create", "(", ":amount", "=>", "(", "self", ".", "total", "*", "100", ")", ".", "to_i", ",", ":currency", "=>", "'usd'", ",", ":customer", "=>", "self", ".", "customer", ".", "stripe_customer_id", ",", ":capture", "=>", "true", ",", ":metadata", "=>", "{", ":invoice_id", "=>", "self", ".", "id", "}", ",", ":statement_descriptor", "=>", "\"#{self.site.description.truncate(22)}\"", ")", "rescue", "Exception", "=>", "ex", "resp", ".", "error", "=", "\"Error during capture process\\n#{ex.message}\"", "end", "if", "resp", ".", "error", ".", "nil?", "InvoiceTransaction", ".", "create", "(", ":invoice_id", "=>", "self", ".", "id", ",", ":transaction_id", "=>", "c", ".", "id", ",", ":transaction_type", "=>", "InvoiceTransaction", "::", "TYPE_AUTHCAP", ",", ":payment_processor", "=>", "sc", ".", "pp_name", ",", ":amount", "=>", "c", ".", "amount", "/", "100.0", ",", ":captured", "=>", "true", ",", ":date_processed", "=>", "DateTime", ".", "now", ".", "utc", ",", ":success", "=>", "c", ".", "status", "==", "'succeeded'", ")", "if", "c", ".", "status", "==", "'succeeded'", "self", ".", "financial_status", "=", "Invoice", "::", "FINANCIAL_STATUS_CAPTURED", "self", ".", "save", "resp", ".", "success", "=", "true", "else", "resp", ".", "error", "=", "\"Error capturing funds.\"", "end", "end", "end", "end", "return", "resp", "end" ]
Authorize and capture funds
[ "Authorize", "and", "capture", "funds" ]
7c112911318f94cc89dba86091903a3acaf0a833
https://github.com/williambarry007/caboose-cms/blob/7c112911318f94cc89dba86091903a3acaf0a833/app/models/caboose/invoice.rb#L282-L330
train
williambarry007/caboose-cms
app/models/caboose/invoice.rb
Caboose.Invoice.void
def void resp = StdClass.new t = InvoiceTransaction.where(:invoice_id => self.id, :transaction_type => InvoiceTransaction::TYPE_AUTHORIZE, :success => true).first if self.financial_status == Invoice::FINANCIAL_STATUS_CAPTURED resp.error = "This invoice has already been captured, you will need to refund instead" elsif t.nil? resp.error = "This invoice doesn't seem to be authorized." else sc = self.site.store_config ot = Caboose::InvoiceTransaction.new( :invoice_id => self.id, :date_processed => DateTime.now.utc, :transaction_type => InvoiceTransaction::TYPE_VOID, :payment_processor => sc.pp_name, :amount => self.total ) case sc.pp_name when 'authorize.net' response = AuthorizeNet::SIM::Transaction.new( sc.authnet_api_login_id, sc.authnet_api_transaction_key, self.total, :transaction_type => InvoiceTransaction::TYPE_VOID, :transaction_id => t.transaction_id, :test => sc.pp_testing ) self.update_attributes( :financial_status => Invoice::FINANCIAL_STATUS_VOIDED, :status => Invoice::STATUS_CANCELED ) self.save # TODO: Add the variant quantities invoiceed back resp.success = "Invoice voided successfully" ot.success = response.response_code && response.response_code == '1' ot.transaction_id = response.transaction_id #ot.auth_code = response.authorization_code ot.response_code = response.response_code ot.save when 'stripe' # TODO: Implement void invoice for strip when 'payscape' # TODO: Implement void invoice for payscape end end return resp end
ruby
def void resp = StdClass.new t = InvoiceTransaction.where(:invoice_id => self.id, :transaction_type => InvoiceTransaction::TYPE_AUTHORIZE, :success => true).first if self.financial_status == Invoice::FINANCIAL_STATUS_CAPTURED resp.error = "This invoice has already been captured, you will need to refund instead" elsif t.nil? resp.error = "This invoice doesn't seem to be authorized." else sc = self.site.store_config ot = Caboose::InvoiceTransaction.new( :invoice_id => self.id, :date_processed => DateTime.now.utc, :transaction_type => InvoiceTransaction::TYPE_VOID, :payment_processor => sc.pp_name, :amount => self.total ) case sc.pp_name when 'authorize.net' response = AuthorizeNet::SIM::Transaction.new( sc.authnet_api_login_id, sc.authnet_api_transaction_key, self.total, :transaction_type => InvoiceTransaction::TYPE_VOID, :transaction_id => t.transaction_id, :test => sc.pp_testing ) self.update_attributes( :financial_status => Invoice::FINANCIAL_STATUS_VOIDED, :status => Invoice::STATUS_CANCELED ) self.save # TODO: Add the variant quantities invoiceed back resp.success = "Invoice voided successfully" ot.success = response.response_code && response.response_code == '1' ot.transaction_id = response.transaction_id #ot.auth_code = response.authorization_code ot.response_code = response.response_code ot.save when 'stripe' # TODO: Implement void invoice for strip when 'payscape' # TODO: Implement void invoice for payscape end end return resp end
[ "def", "void", "resp", "=", "StdClass", ".", "new", "t", "=", "InvoiceTransaction", ".", "where", "(", ":invoice_id", "=>", "self", ".", "id", ",", ":transaction_type", "=>", "InvoiceTransaction", "::", "TYPE_AUTHORIZE", ",", ":success", "=>", "true", ")", ".", "first", "if", "self", ".", "financial_status", "==", "Invoice", "::", "FINANCIAL_STATUS_CAPTURED", "resp", ".", "error", "=", "\"This invoice has already been captured, you will need to refund instead\"", "elsif", "t", ".", "nil?", "resp", ".", "error", "=", "\"This invoice doesn't seem to be authorized.\"", "else", "sc", "=", "self", ".", "site", ".", "store_config", "ot", "=", "Caboose", "::", "InvoiceTransaction", ".", "new", "(", ":invoice_id", "=>", "self", ".", "id", ",", ":date_processed", "=>", "DateTime", ".", "now", ".", "utc", ",", ":transaction_type", "=>", "InvoiceTransaction", "::", "TYPE_VOID", ",", ":payment_processor", "=>", "sc", ".", "pp_name", ",", ":amount", "=>", "self", ".", "total", ")", "case", "sc", ".", "pp_name", "when", "'authorize.net'", "response", "=", "AuthorizeNet", "::", "SIM", "::", "Transaction", ".", "new", "(", "sc", ".", "authnet_api_login_id", ",", "sc", ".", "authnet_api_transaction_key", ",", "self", ".", "total", ",", ":transaction_type", "=>", "InvoiceTransaction", "::", "TYPE_VOID", ",", ":transaction_id", "=>", "t", ".", "transaction_id", ",", ":test", "=>", "sc", ".", "pp_testing", ")", "self", ".", "update_attributes", "(", ":financial_status", "=>", "Invoice", "::", "FINANCIAL_STATUS_VOIDED", ",", ":status", "=>", "Invoice", "::", "STATUS_CANCELED", ")", "self", ".", "save", "resp", ".", "success", "=", "\"Invoice voided successfully\"", "ot", ".", "success", "=", "response", ".", "response_code", "&&", "response", ".", "response_code", "==", "'1'", "ot", ".", "transaction_id", "=", "response", ".", "transaction_id", "ot", ".", "response_code", "=", "response", ".", "response_code", "ot", ".", "save", "when", "'stripe'", "when", "'payscape'", "end", "end", "return", "resp", "end" ]
Void an authorized invoice
[ "Void", "an", "authorized", "invoice" ]
7c112911318f94cc89dba86091903a3acaf0a833
https://github.com/williambarry007/caboose-cms/blob/7c112911318f94cc89dba86091903a3acaf0a833/app/models/caboose/invoice.rb#L414-L468
train
puppetlabs/beaker-vmpooler
lib/beaker/hypervisor/vmpooler.rb
Beaker.Vmpooler.add_tags
def add_tags(host) host[:host_tags].merge( 'beaker_version' => Beaker::Version::STRING, 'jenkins_build_url' => @options[:jenkins_build_url], 'department' => @options[:department], 'project' => @options[:project], 'created_by' => @options[:created_by], 'name' => host.name, 'roles' => host.host_hash[:roles].join(', ') ) end
ruby
def add_tags(host) host[:host_tags].merge( 'beaker_version' => Beaker::Version::STRING, 'jenkins_build_url' => @options[:jenkins_build_url], 'department' => @options[:department], 'project' => @options[:project], 'created_by' => @options[:created_by], 'name' => host.name, 'roles' => host.host_hash[:roles].join(', ') ) end
[ "def", "add_tags", "(", "host", ")", "host", "[", ":host_tags", "]", ".", "merge", "(", "'beaker_version'", "=>", "Beaker", "::", "Version", "::", "STRING", ",", "'jenkins_build_url'", "=>", "@options", "[", ":jenkins_build_url", "]", ",", "'department'", "=>", "@options", "[", ":department", "]", ",", "'project'", "=>", "@options", "[", ":project", "]", ",", "'created_by'", "=>", "@options", "[", ":created_by", "]", ",", "'name'", "=>", "host", ".", "name", ",", "'roles'", "=>", "host", ".", "host_hash", "[", ":roles", "]", ".", "join", "(", "', '", ")", ")", "end" ]
Override host tags with presets @param [Beaker::Host] host Beaker host @return [Hash] Tag hash
[ "Override", "host", "tags", "with", "presets" ]
d54e825506d740ad12d6fe0a9d83b5172401f79b
https://github.com/puppetlabs/beaker-vmpooler/blob/d54e825506d740ad12d6fe0a9d83b5172401f79b/lib/beaker/hypervisor/vmpooler.rb#L75-L85
train
williambarry007/caboose-cms
app/models/caboose/subscription.rb
Caboose.Subscription.create_invoices
def create_invoices self.calculate_date_started_full if self.date_started_full.nil? v = self.variant interval = case v.subscription_interval when Variant::SUBSCRIPTION_INTERVAL_MONTHLY then 1.month when Variant::SUBSCRIPTION_INTERVAL_YEARLY then 1.year end sc = v.product.site.store_config unit_price = v.clearance && v.clearance_price ? v.clearance_price : (v.on_sale? ? v.sale_price : v.price) # Special case if the subscription starts on specific day if v.subscription_start_on_day && (Date.today > self.date_started_full) li = self.line_items.where("date_starts = ? date_ends = ?", self.date_started, self.date_started_full - 1.day).first if li.nil? prorated_unit_price = unit_price + 0.00 if v.subscription_prorate prorated_unit_price = case v.subscription_prorate_method when Variant::SUBSCRIPTION_PRORATE_METHOD_FLAT then v.subscription_prorate_flat_amount when Variant::SUBSCRIPTION_PRORATE_METHOD_PERCENTAGE then unit_price * ((self.date_started_full - self.date_started).to_f / ((self.date_started_full + interval) - self.date_started_full).to_f) when Variant::SUBSCRIPTION_PRORATE_METHOD_CUSTOM then self.custom_prorate end end invoice = Caboose::Invoice.create( :site_id => v.product.site_id, :status => Caboose::Invoice::STATUS_PENDING, :financial_status => Caboose::Invoice::STATUS_PENDING, :date_created => DateTime.now, :payment_terms => sc.default_payment_terms, :invoice_number => sc.next_invoice_number ) LineItem.create( :invoice_id => invoice.id, :variant_id => v.id, :quantity => 1, :unit_price => prorated_unit_price, :subtotal => prorated_unit_price, :status => 'pending', :subscription_id => self.id, :date_starts => d, :date_ends => d + interval - 1.day ) invoice.calculate invoice.save end end d2 = self.date_started_full + 1.day - 1.day while d2 <= Date.today do d2 = d2 + interval end d = self.date_started + 1.day - 1.day while d <= d2 do # See if an invoice has already been created for today li = self.line_items.where("date_starts = ? AND date_ends = ?", d, d + interval - 1.day).first if li.nil? invoice = Caboose::Invoice.create( :site_id => v.product.site_id, :customer_id => self.user_id, :status => Caboose::Invoice::STATUS_PENDING, :financial_status => Caboose::Invoice::STATUS_PENDING, :date_created => DateTime.now, :payment_terms => sc.default_payment_terms, :invoice_number => sc.next_invoice_number ) LineItem.create( :invoice_id => invoice.id, :variant_id => v.id, :quantity => 1, :unit_price => unit_price, :subtotal => unit_price, :status => 'pending', :subscription_id => self.id, :date_starts => d, :date_ends => d + interval - 1.day ) invoice.calculate invoice.save end d = d + interval end return true end
ruby
def create_invoices self.calculate_date_started_full if self.date_started_full.nil? v = self.variant interval = case v.subscription_interval when Variant::SUBSCRIPTION_INTERVAL_MONTHLY then 1.month when Variant::SUBSCRIPTION_INTERVAL_YEARLY then 1.year end sc = v.product.site.store_config unit_price = v.clearance && v.clearance_price ? v.clearance_price : (v.on_sale? ? v.sale_price : v.price) # Special case if the subscription starts on specific day if v.subscription_start_on_day && (Date.today > self.date_started_full) li = self.line_items.where("date_starts = ? date_ends = ?", self.date_started, self.date_started_full - 1.day).first if li.nil? prorated_unit_price = unit_price + 0.00 if v.subscription_prorate prorated_unit_price = case v.subscription_prorate_method when Variant::SUBSCRIPTION_PRORATE_METHOD_FLAT then v.subscription_prorate_flat_amount when Variant::SUBSCRIPTION_PRORATE_METHOD_PERCENTAGE then unit_price * ((self.date_started_full - self.date_started).to_f / ((self.date_started_full + interval) - self.date_started_full).to_f) when Variant::SUBSCRIPTION_PRORATE_METHOD_CUSTOM then self.custom_prorate end end invoice = Caboose::Invoice.create( :site_id => v.product.site_id, :status => Caboose::Invoice::STATUS_PENDING, :financial_status => Caboose::Invoice::STATUS_PENDING, :date_created => DateTime.now, :payment_terms => sc.default_payment_terms, :invoice_number => sc.next_invoice_number ) LineItem.create( :invoice_id => invoice.id, :variant_id => v.id, :quantity => 1, :unit_price => prorated_unit_price, :subtotal => prorated_unit_price, :status => 'pending', :subscription_id => self.id, :date_starts => d, :date_ends => d + interval - 1.day ) invoice.calculate invoice.save end end d2 = self.date_started_full + 1.day - 1.day while d2 <= Date.today do d2 = d2 + interval end d = self.date_started + 1.day - 1.day while d <= d2 do # See if an invoice has already been created for today li = self.line_items.where("date_starts = ? AND date_ends = ?", d, d + interval - 1.day).first if li.nil? invoice = Caboose::Invoice.create( :site_id => v.product.site_id, :customer_id => self.user_id, :status => Caboose::Invoice::STATUS_PENDING, :financial_status => Caboose::Invoice::STATUS_PENDING, :date_created => DateTime.now, :payment_terms => sc.default_payment_terms, :invoice_number => sc.next_invoice_number ) LineItem.create( :invoice_id => invoice.id, :variant_id => v.id, :quantity => 1, :unit_price => unit_price, :subtotal => unit_price, :status => 'pending', :subscription_id => self.id, :date_starts => d, :date_ends => d + interval - 1.day ) invoice.calculate invoice.save end d = d + interval end return true end
[ "def", "create_invoices", "self", ".", "calculate_date_started_full", "if", "self", ".", "date_started_full", ".", "nil?", "v", "=", "self", ".", "variant", "interval", "=", "case", "v", ".", "subscription_interval", "when", "Variant", "::", "SUBSCRIPTION_INTERVAL_MONTHLY", "then", "1", ".", "month", "when", "Variant", "::", "SUBSCRIPTION_INTERVAL_YEARLY", "then", "1", ".", "year", "end", "sc", "=", "v", ".", "product", ".", "site", ".", "store_config", "unit_price", "=", "v", ".", "clearance", "&&", "v", ".", "clearance_price", "?", "v", ".", "clearance_price", ":", "(", "v", ".", "on_sale?", "?", "v", ".", "sale_price", ":", "v", ".", "price", ")", "if", "v", ".", "subscription_start_on_day", "&&", "(", "Date", ".", "today", ">", "self", ".", "date_started_full", ")", "li", "=", "self", ".", "line_items", ".", "where", "(", "\"date_starts = ? date_ends = ?\"", ",", "self", ".", "date_started", ",", "self", ".", "date_started_full", "-", "1", ".", "day", ")", ".", "first", "if", "li", ".", "nil?", "prorated_unit_price", "=", "unit_price", "+", "0.00", "if", "v", ".", "subscription_prorate", "prorated_unit_price", "=", "case", "v", ".", "subscription_prorate_method", "when", "Variant", "::", "SUBSCRIPTION_PRORATE_METHOD_FLAT", "then", "v", ".", "subscription_prorate_flat_amount", "when", "Variant", "::", "SUBSCRIPTION_PRORATE_METHOD_PERCENTAGE", "then", "unit_price", "*", "(", "(", "self", ".", "date_started_full", "-", "self", ".", "date_started", ")", ".", "to_f", "/", "(", "(", "self", ".", "date_started_full", "+", "interval", ")", "-", "self", ".", "date_started_full", ")", ".", "to_f", ")", "when", "Variant", "::", "SUBSCRIPTION_PRORATE_METHOD_CUSTOM", "then", "self", ".", "custom_prorate", "end", "end", "invoice", "=", "Caboose", "::", "Invoice", ".", "create", "(", ":site_id", "=>", "v", ".", "product", ".", "site_id", ",", ":status", "=>", "Caboose", "::", "Invoice", "::", "STATUS_PENDING", ",", ":financial_status", "=>", "Caboose", "::", "Invoice", "::", "STATUS_PENDING", ",", ":date_created", "=>", "DateTime", ".", "now", ",", ":payment_terms", "=>", "sc", ".", "default_payment_terms", ",", ":invoice_number", "=>", "sc", ".", "next_invoice_number", ")", "LineItem", ".", "create", "(", ":invoice_id", "=>", "invoice", ".", "id", ",", ":variant_id", "=>", "v", ".", "id", ",", ":quantity", "=>", "1", ",", ":unit_price", "=>", "prorated_unit_price", ",", ":subtotal", "=>", "prorated_unit_price", ",", ":status", "=>", "'pending'", ",", ":subscription_id", "=>", "self", ".", "id", ",", ":date_starts", "=>", "d", ",", ":date_ends", "=>", "d", "+", "interval", "-", "1", ".", "day", ")", "invoice", ".", "calculate", "invoice", ".", "save", "end", "end", "d2", "=", "self", ".", "date_started_full", "+", "1", ".", "day", "-", "1", ".", "day", "while", "d2", "<=", "Date", ".", "today", "do", "d2", "=", "d2", "+", "interval", "end", "d", "=", "self", ".", "date_started", "+", "1", ".", "day", "-", "1", ".", "day", "while", "d", "<=", "d2", "do", "li", "=", "self", ".", "line_items", ".", "where", "(", "\"date_starts = ? AND date_ends = ?\"", ",", "d", ",", "d", "+", "interval", "-", "1", ".", "day", ")", ".", "first", "if", "li", ".", "nil?", "invoice", "=", "Caboose", "::", "Invoice", ".", "create", "(", ":site_id", "=>", "v", ".", "product", ".", "site_id", ",", ":customer_id", "=>", "self", ".", "user_id", ",", ":status", "=>", "Caboose", "::", "Invoice", "::", "STATUS_PENDING", ",", ":financial_status", "=>", "Caboose", "::", "Invoice", "::", "STATUS_PENDING", ",", ":date_created", "=>", "DateTime", ".", "now", ",", ":payment_terms", "=>", "sc", ".", "default_payment_terms", ",", ":invoice_number", "=>", "sc", ".", "next_invoice_number", ")", "LineItem", ".", "create", "(", ":invoice_id", "=>", "invoice", ".", "id", ",", ":variant_id", "=>", "v", ".", "id", ",", ":quantity", "=>", "1", ",", ":unit_price", "=>", "unit_price", ",", ":subtotal", "=>", "unit_price", ",", ":status", "=>", "'pending'", ",", ":subscription_id", "=>", "self", ".", "id", ",", ":date_starts", "=>", "d", ",", ":date_ends", "=>", "d", "+", "interval", "-", "1", ".", "day", ")", "invoice", ".", "calculate", "invoice", ".", "save", "end", "d", "=", "d", "+", "interval", "end", "return", "true", "end" ]
Verify invoices exist for the entire subscription period up until today
[ "Verify", "invoices", "exist", "for", "the", "entire", "subscription", "period", "up", "until", "today" ]
7c112911318f94cc89dba86091903a3acaf0a833
https://github.com/williambarry007/caboose-cms/blob/7c112911318f94cc89dba86091903a3acaf0a833/app/models/caboose/subscription.rb#L46-L129
train
williambarry007/caboose-cms
app/models/caboose/invoice_package.rb
Caboose.InvoicePackage.activemerchant_package
def activemerchant_package sc = self.invoice.site.store_config weight = 0.0 self.line_items.each{ |li| weight = weight + (li.variant.weight * li.quantity) } weight = weight * 0.035274 if sc.weight_unit == StoreConfig::WEIGHT_UNIT_METRIC # grams to ounces sp = self.shipping_package dimensions = [sp.outside_length, sp.outside_width, sp.outside_height] if sc.length_unit == StoreConfig::LENGTH_UNIT_METRIC # cm to inches dimensions[0] = dimensions[0] / 2.54 dimensions[1] = dimensions[0] / 2.54 dimensions[2] = dimensions[0] / 2.54 end return ActiveShipping::Package.new(weight, dimensions, :units => :imperial, :container => :variable) end
ruby
def activemerchant_package sc = self.invoice.site.store_config weight = 0.0 self.line_items.each{ |li| weight = weight + (li.variant.weight * li.quantity) } weight = weight * 0.035274 if sc.weight_unit == StoreConfig::WEIGHT_UNIT_METRIC # grams to ounces sp = self.shipping_package dimensions = [sp.outside_length, sp.outside_width, sp.outside_height] if sc.length_unit == StoreConfig::LENGTH_UNIT_METRIC # cm to inches dimensions[0] = dimensions[0] / 2.54 dimensions[1] = dimensions[0] / 2.54 dimensions[2] = dimensions[0] / 2.54 end return ActiveShipping::Package.new(weight, dimensions, :units => :imperial, :container => :variable) end
[ "def", "activemerchant_package", "sc", "=", "self", ".", "invoice", ".", "site", ".", "store_config", "weight", "=", "0.0", "self", ".", "line_items", ".", "each", "{", "|", "li", "|", "weight", "=", "weight", "+", "(", "li", ".", "variant", ".", "weight", "*", "li", ".", "quantity", ")", "}", "weight", "=", "weight", "*", "0.035274", "if", "sc", ".", "weight_unit", "==", "StoreConfig", "::", "WEIGHT_UNIT_METRIC", "sp", "=", "self", ".", "shipping_package", "dimensions", "=", "[", "sp", ".", "outside_length", ",", "sp", ".", "outside_width", ",", "sp", ".", "outside_height", "]", "if", "sc", ".", "length_unit", "==", "StoreConfig", "::", "LENGTH_UNIT_METRIC", "dimensions", "[", "0", "]", "=", "dimensions", "[", "0", "]", "/", "2.54", "dimensions", "[", "1", "]", "=", "dimensions", "[", "0", "]", "/", "2.54", "dimensions", "[", "2", "]", "=", "dimensions", "[", "0", "]", "/", "2.54", "end", "return", "ActiveShipping", "::", "Package", ".", "new", "(", "weight", ",", "dimensions", ",", ":units", "=>", ":imperial", ",", ":container", "=>", ":variable", ")", "end" ]
Gets the activemerchant package based on the shipping package
[ "Gets", "the", "activemerchant", "package", "based", "on", "the", "shipping", "package" ]
7c112911318f94cc89dba86091903a3acaf0a833
https://github.com/williambarry007/caboose-cms/blob/7c112911318f94cc89dba86091903a3acaf0a833/app/models/caboose/invoice_package.rb#L59-L75
train
williambarry007/caboose-cms
app/models/caboose/shipping_package.rb
Caboose.ShippingPackage.boxes
def boxes(rigid_variants) stackable = {} nonstackable = [] rigid_variants.each do |v| sgid = v.product.stackable_group_id if sgid stackable[sgid] = [] if stackable[sgid].nil? stackable[sgid] << v else nonstackable << [v.length, v.width, v.height] end end stackable.each do |sgid, arr| sg = arr[0].product.stackable_group l = 0.0 w = 0.0 h = 0.0 arr.each do |v| if l+sg.extra_length >= sg.max_length || w+sg.extra_width >= sg.max_width || h+sg.extra_height >= sg.max_height nonstackable << [l, w, h] l = 0.0 w = 0.0 h = 0.0 end if l == 0.0 l = v.length w = v.width h = v.height else l = l + sg.extra_length w = w + sg.extra_width h = h + sg.extra_height end end nonstackable << [l, w, h] if l > 0 end return nonstackable end
ruby
def boxes(rigid_variants) stackable = {} nonstackable = [] rigid_variants.each do |v| sgid = v.product.stackable_group_id if sgid stackable[sgid] = [] if stackable[sgid].nil? stackable[sgid] << v else nonstackable << [v.length, v.width, v.height] end end stackable.each do |sgid, arr| sg = arr[0].product.stackable_group l = 0.0 w = 0.0 h = 0.0 arr.each do |v| if l+sg.extra_length >= sg.max_length || w+sg.extra_width >= sg.max_width || h+sg.extra_height >= sg.max_height nonstackable << [l, w, h] l = 0.0 w = 0.0 h = 0.0 end if l == 0.0 l = v.length w = v.width h = v.height else l = l + sg.extra_length w = w + sg.extra_width h = h + sg.extra_height end end nonstackable << [l, w, h] if l > 0 end return nonstackable end
[ "def", "boxes", "(", "rigid_variants", ")", "stackable", "=", "{", "}", "nonstackable", "=", "[", "]", "rigid_variants", ".", "each", "do", "|", "v", "|", "sgid", "=", "v", ".", "product", ".", "stackable_group_id", "if", "sgid", "stackable", "[", "sgid", "]", "=", "[", "]", "if", "stackable", "[", "sgid", "]", ".", "nil?", "stackable", "[", "sgid", "]", "<<", "v", "else", "nonstackable", "<<", "[", "v", ".", "length", ",", "v", ".", "width", ",", "v", ".", "height", "]", "end", "end", "stackable", ".", "each", "do", "|", "sgid", ",", "arr", "|", "sg", "=", "arr", "[", "0", "]", ".", "product", ".", "stackable_group", "l", "=", "0.0", "w", "=", "0.0", "h", "=", "0.0", "arr", ".", "each", "do", "|", "v", "|", "if", "l", "+", "sg", ".", "extra_length", ">=", "sg", ".", "max_length", "||", "w", "+", "sg", ".", "extra_width", ">=", "sg", ".", "max_width", "||", "h", "+", "sg", ".", "extra_height", ">=", "sg", ".", "max_height", "nonstackable", "<<", "[", "l", ",", "w", ",", "h", "]", "l", "=", "0.0", "w", "=", "0.0", "h", "=", "0.0", "end", "if", "l", "==", "0.0", "l", "=", "v", ".", "length", "w", "=", "v", ".", "width", "h", "=", "v", ".", "height", "else", "l", "=", "l", "+", "sg", ".", "extra_length", "w", "=", "w", "+", "sg", ".", "extra_width", "h", "=", "h", "+", "sg", ".", "extra_height", "end", "end", "nonstackable", "<<", "[", "l", ",", "w", ",", "h", "]", "if", "l", ">", "0", "end", "return", "nonstackable", "end" ]
Gets the 3d dimensions of the variants after they're stacked
[ "Gets", "the", "3d", "dimensions", "of", "the", "variants", "after", "they", "re", "stacked" ]
7c112911318f94cc89dba86091903a3acaf0a833
https://github.com/williambarry007/caboose-cms/blob/7c112911318f94cc89dba86091903a3acaf0a833/app/models/caboose/shipping_package.rb#L55-L94
train
williambarry007/caboose-cms
app/controllers/caboose/application_controller.rb
Caboose.ApplicationController.init_cart
def init_cart # Check if the cart ID is defined and that it exists in the database create_new_invoice = false if session[:cart_id] @invoice = Caboose::Invoice.where(:id => session[:cart_id]).first create_new_invoice = true if @invoice.nil? || @invoice.status != 'cart' else create_new_invoice = true end if create_new_invoice # Create an invoice to associate with the session @invoice = Caboose::Invoice.new @invoice.site_id = @site ? @site.id : nil @invoice.status = Caboose::Invoice::STATUS_CART @invoice.financial_status = Caboose::Invoice::STATUS_PENDING @invoice.date_created = DateTime.now @invoice.referring_site = request.env['HTTP_REFERER'] @invoice.landing_page = request.fullpath @invoice.landing_page_ref = params[:ref] || nil @invoice.payment_terms = @site.store_config.default_payment_terms @invoice.save InvoiceLog.create( :invoice_id => @invoice.id, :user_id => logged_in_user.id, :date_logged => DateTime.now.utc, :invoice_action => InvoiceLog::ACTION_INVOICE_CREATED ) # Save the cart ID in the session session[:cart_id] = @invoice.id end end
ruby
def init_cart # Check if the cart ID is defined and that it exists in the database create_new_invoice = false if session[:cart_id] @invoice = Caboose::Invoice.where(:id => session[:cart_id]).first create_new_invoice = true if @invoice.nil? || @invoice.status != 'cart' else create_new_invoice = true end if create_new_invoice # Create an invoice to associate with the session @invoice = Caboose::Invoice.new @invoice.site_id = @site ? @site.id : nil @invoice.status = Caboose::Invoice::STATUS_CART @invoice.financial_status = Caboose::Invoice::STATUS_PENDING @invoice.date_created = DateTime.now @invoice.referring_site = request.env['HTTP_REFERER'] @invoice.landing_page = request.fullpath @invoice.landing_page_ref = params[:ref] || nil @invoice.payment_terms = @site.store_config.default_payment_terms @invoice.save InvoiceLog.create( :invoice_id => @invoice.id, :user_id => logged_in_user.id, :date_logged => DateTime.now.utc, :invoice_action => InvoiceLog::ACTION_INVOICE_CREATED ) # Save the cart ID in the session session[:cart_id] = @invoice.id end end
[ "def", "init_cart", "create_new_invoice", "=", "false", "if", "session", "[", ":cart_id", "]", "@invoice", "=", "Caboose", "::", "Invoice", ".", "where", "(", ":id", "=>", "session", "[", ":cart_id", "]", ")", ".", "first", "create_new_invoice", "=", "true", "if", "@invoice", ".", "nil?", "||", "@invoice", ".", "status", "!=", "'cart'", "else", "create_new_invoice", "=", "true", "end", "if", "create_new_invoice", "@invoice", "=", "Caboose", "::", "Invoice", ".", "new", "@invoice", ".", "site_id", "=", "@site", "?", "@site", ".", "id", ":", "nil", "@invoice", ".", "status", "=", "Caboose", "::", "Invoice", "::", "STATUS_CART", "@invoice", ".", "financial_status", "=", "Caboose", "::", "Invoice", "::", "STATUS_PENDING", "@invoice", ".", "date_created", "=", "DateTime", ".", "now", "@invoice", ".", "referring_site", "=", "request", ".", "env", "[", "'HTTP_REFERER'", "]", "@invoice", ".", "landing_page", "=", "request", ".", "fullpath", "@invoice", ".", "landing_page_ref", "=", "params", "[", ":ref", "]", "||", "nil", "@invoice", ".", "payment_terms", "=", "@site", ".", "store_config", ".", "default_payment_terms", "@invoice", ".", "save", "InvoiceLog", ".", "create", "(", ":invoice_id", "=>", "@invoice", ".", "id", ",", ":user_id", "=>", "logged_in_user", ".", "id", ",", ":date_logged", "=>", "DateTime", ".", "now", ".", "utc", ",", ":invoice_action", "=>", "InvoiceLog", "::", "ACTION_INVOICE_CREATED", ")", "session", "[", ":cart_id", "]", "=", "@invoice", ".", "id", "end", "end" ]
Initialize the cart in the session
[ "Initialize", "the", "cart", "in", "the", "session" ]
7c112911318f94cc89dba86091903a3acaf0a833
https://github.com/williambarry007/caboose-cms/blob/7c112911318f94cc89dba86091903a3acaf0a833/app/controllers/caboose/application_controller.rb#L69-L101
train
williambarry007/caboose-cms
app/controllers/caboose/application_controller.rb
Caboose.ApplicationController.parse_url_params
def parse_url_params return if !Caboose.use_url_params url = "#{request.fullpath}" url[0] = "" if url.starts_with?('/') url = url.split('?')[0] if url.include?('?') arr = url.split('/') i = arr.count - 1 while i >= 1 do k = arr[i-1] v = arr[i] if v && v.length > 0 v = v.gsub('%20', ' ') params[k] = v end i = i-2 end end
ruby
def parse_url_params return if !Caboose.use_url_params url = "#{request.fullpath}" url[0] = "" if url.starts_with?('/') url = url.split('?')[0] if url.include?('?') arr = url.split('/') i = arr.count - 1 while i >= 1 do k = arr[i-1] v = arr[i] if v && v.length > 0 v = v.gsub('%20', ' ') params[k] = v end i = i-2 end end
[ "def", "parse_url_params", "return", "if", "!", "Caboose", ".", "use_url_params", "url", "=", "\"#{request.fullpath}\"", "url", "[", "0", "]", "=", "\"\"", "if", "url", ".", "starts_with?", "(", "'/'", ")", "url", "=", "url", ".", "split", "(", "'?'", ")", "[", "0", "]", "if", "url", ".", "include?", "(", "'?'", ")", "arr", "=", "url", ".", "split", "(", "'/'", ")", "i", "=", "arr", ".", "count", "-", "1", "while", "i", ">=", "1", "do", "k", "=", "arr", "[", "i", "-", "1", "]", "v", "=", "arr", "[", "i", "]", "if", "v", "&&", "v", ".", "length", ">", "0", "v", "=", "v", ".", "gsub", "(", "'%20'", ",", "' '", ")", "params", "[", "k", "]", "=", "v", "end", "i", "=", "i", "-", "2", "end", "end" ]
Parses any parameters in the URL and adds them to the params
[ "Parses", "any", "parameters", "in", "the", "URL", "and", "adds", "them", "to", "the", "params" ]
7c112911318f94cc89dba86091903a3acaf0a833
https://github.com/williambarry007/caboose-cms/blob/7c112911318f94cc89dba86091903a3acaf0a833/app/controllers/caboose/application_controller.rb#L112-L128
train
williambarry007/caboose-cms
app/controllers/caboose/application_controller.rb
Caboose.ApplicationController.login_user
def login_user(user, remember = false) session["app_user"] = Caboose::StdClass.new({ :id => user.id , :site_id => user.site_id , :first_name => user.first_name , :last_name => user.last_name , :username => user.username , :email => user.email }) cookies.permanent[:caboose_user_id] = user.id if remember end
ruby
def login_user(user, remember = false) session["app_user"] = Caboose::StdClass.new({ :id => user.id , :site_id => user.site_id , :first_name => user.first_name , :last_name => user.last_name , :username => user.username , :email => user.email }) cookies.permanent[:caboose_user_id] = user.id if remember end
[ "def", "login_user", "(", "user", ",", "remember", "=", "false", ")", "session", "[", "\"app_user\"", "]", "=", "Caboose", "::", "StdClass", ".", "new", "(", "{", ":id", "=>", "user", ".", "id", ",", ":site_id", "=>", "user", ".", "site_id", ",", ":first_name", "=>", "user", ".", "first_name", ",", ":last_name", "=>", "user", ".", "last_name", ",", ":username", "=>", "user", ".", "username", ",", ":email", "=>", "user", ".", "email", "}", ")", "cookies", ".", "permanent", "[", ":caboose_user_id", "]", "=", "user", ".", "id", "if", "remember", "end" ]
Logs in a user
[ "Logs", "in", "a", "user" ]
7c112911318f94cc89dba86091903a3acaf0a833
https://github.com/williambarry007/caboose-cms/blob/7c112911318f94cc89dba86091903a3acaf0a833/app/controllers/caboose/application_controller.rb#L142-L152
train
williambarry007/caboose-cms
app/controllers/caboose/application_controller.rb
Caboose.ApplicationController.logged_in?
def logged_in? validate_token validate_cookie return true if !session["app_user"].nil? && session["app_user"] != false && session["app_user"].id != -1 && session["app_user"].id != User.logged_out_user_id(@site.id) return false end
ruby
def logged_in? validate_token validate_cookie return true if !session["app_user"].nil? && session["app_user"] != false && session["app_user"].id != -1 && session["app_user"].id != User.logged_out_user_id(@site.id) return false end
[ "def", "logged_in?", "validate_token", "validate_cookie", "return", "true", "if", "!", "session", "[", "\"app_user\"", "]", ".", "nil?", "&&", "session", "[", "\"app_user\"", "]", "!=", "false", "&&", "session", "[", "\"app_user\"", "]", ".", "id", "!=", "-", "1", "&&", "session", "[", "\"app_user\"", "]", ".", "id", "!=", "User", ".", "logged_out_user_id", "(", "@site", ".", "id", ")", "return", "false", "end" ]
Returns whether or not a user is logged in
[ "Returns", "whether", "or", "not", "a", "user", "is", "logged", "in" ]
7c112911318f94cc89dba86091903a3acaf0a833
https://github.com/williambarry007/caboose-cms/blob/7c112911318f94cc89dba86091903a3acaf0a833/app/controllers/caboose/application_controller.rb#L155-L160
train