id
int32 0
24.9k
| 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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
14,300
|
Azure/azure-sdk-for-ruby
|
data/azure_graph_rbac/lib/1.6/generated/azure_graph_rbac/applications.rb
|
Azure::GraphRbac::V1_6.Applications.list_owners
|
def list_owners(application_object_id, custom_headers:nil)
response = list_owners_async(application_object_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
ruby
|
def list_owners(application_object_id, custom_headers:nil)
response = list_owners_async(application_object_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
[
"def",
"list_owners",
"(",
"application_object_id",
",",
"custom_headers",
":",
"nil",
")",
"response",
"=",
"list_owners_async",
"(",
"application_object_id",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"response",
".",
"body",
"unless",
"response",
".",
"nil?",
"end"
] |
Directory objects that are owners of the application.
The owners are a set of non-admin users who are allowed to modify this
object.
@param application_object_id [String] The object ID of the application for
which to get owners.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [DirectoryObjectListResult] operation results.
|
[
"Directory",
"objects",
"that",
"are",
"owners",
"of",
"the",
"application",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/data/azure_graph_rbac/lib/1.6/generated/azure_graph_rbac/applications.rb#L478-L481
|
14,301
|
Azure/azure-sdk-for-ruby
|
data/azure_graph_rbac/lib/1.6/generated/azure_graph_rbac/applications.rb
|
Azure::GraphRbac::V1_6.Applications.list_key_credentials
|
def list_key_credentials(application_object_id, custom_headers:nil)
response = list_key_credentials_async(application_object_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
ruby
|
def list_key_credentials(application_object_id, custom_headers:nil)
response = list_key_credentials_async(application_object_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
[
"def",
"list_key_credentials",
"(",
"application_object_id",
",",
"custom_headers",
":",
"nil",
")",
"response",
"=",
"list_key_credentials_async",
"(",
"application_object_id",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"response",
".",
"body",
"unless",
"response",
".",
"nil?",
"end"
] |
Get the keyCredentials associated with an application.
@param application_object_id [String] Application object ID.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [KeyCredentialListResult] operation results.
|
[
"Get",
"the",
"keyCredentials",
"associated",
"with",
"an",
"application",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/data/azure_graph_rbac/lib/1.6/generated/azure_graph_rbac/applications.rb#L671-L674
|
14,302
|
Azure/azure-sdk-for-ruby
|
data/azure_graph_rbac/lib/1.6/generated/azure_graph_rbac/applications.rb
|
Azure::GraphRbac::V1_6.Applications.update_key_credentials
|
def update_key_credentials(application_object_id, parameters, custom_headers:nil)
response = update_key_credentials_async(application_object_id, parameters, custom_headers:custom_headers).value!
nil
end
|
ruby
|
def update_key_credentials(application_object_id, parameters, custom_headers:nil)
response = update_key_credentials_async(application_object_id, parameters, custom_headers:custom_headers).value!
nil
end
|
[
"def",
"update_key_credentials",
"(",
"application_object_id",
",",
"parameters",
",",
"custom_headers",
":",
"nil",
")",
"response",
"=",
"update_key_credentials_async",
"(",
"application_object_id",
",",
"parameters",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"nil",
"end"
] |
Update the keyCredentials associated with an application.
@param application_object_id [String] Application object ID.
@param parameters [KeyCredentialsUpdateParameters] Parameters to update the
keyCredentials of an existing application.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
|
[
"Update",
"the",
"keyCredentials",
"associated",
"with",
"an",
"application",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/data/azure_graph_rbac/lib/1.6/generated/azure_graph_rbac/applications.rb#L760-L763
|
14,303
|
Azure/azure-sdk-for-ruby
|
data/azure_graph_rbac/lib/1.6/generated/azure_graph_rbac/applications.rb
|
Azure::GraphRbac::V1_6.Applications.list_password_credentials
|
def list_password_credentials(application_object_id, custom_headers:nil)
response = list_password_credentials_async(application_object_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
ruby
|
def list_password_credentials(application_object_id, custom_headers:nil)
response = list_password_credentials_async(application_object_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
[
"def",
"list_password_credentials",
"(",
"application_object_id",
",",
"custom_headers",
":",
"nil",
")",
"response",
"=",
"list_password_credentials_async",
"(",
"application_object_id",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"response",
".",
"body",
"unless",
"response",
".",
"nil?",
"end"
] |
Get the passwordCredentials associated with an application.
@param application_object_id [String] Application object ID.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [PasswordCredentialListResult] operation results.
|
[
"Get",
"the",
"passwordCredentials",
"associated",
"with",
"an",
"application",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/data/azure_graph_rbac/lib/1.6/generated/azure_graph_rbac/applications.rb#L850-L853
|
14,304
|
Azure/azure-sdk-for-ruby
|
data/azure_graph_rbac/lib/1.6/generated/azure_graph_rbac/applications.rb
|
Azure::GraphRbac::V1_6.Applications.update_password_credentials
|
def update_password_credentials(application_object_id, parameters, custom_headers:nil)
response = update_password_credentials_async(application_object_id, parameters, custom_headers:custom_headers).value!
nil
end
|
ruby
|
def update_password_credentials(application_object_id, parameters, custom_headers:nil)
response = update_password_credentials_async(application_object_id, parameters, custom_headers:custom_headers).value!
nil
end
|
[
"def",
"update_password_credentials",
"(",
"application_object_id",
",",
"parameters",
",",
"custom_headers",
":",
"nil",
")",
"response",
"=",
"update_password_credentials_async",
"(",
"application_object_id",
",",
"parameters",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"nil",
"end"
] |
Update passwordCredentials associated with an application.
@param application_object_id [String] Application object ID.
@param parameters [PasswordCredentialsUpdateParameters] Parameters to update
passwordCredentials of an existing application.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
|
[
"Update",
"passwordCredentials",
"associated",
"with",
"an",
"application",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/data/azure_graph_rbac/lib/1.6/generated/azure_graph_rbac/applications.rb#L939-L942
|
14,305
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_authorization/lib/2018-07-01-preview/generated/azure_mgmt_authorization/deny_assignments.rb
|
Azure::Authorization::Mgmt::V2018_07_01_preview.DenyAssignments.get_by_id
|
def get_by_id(deny_assignment_id, custom_headers:nil)
response = get_by_id_async(deny_assignment_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
ruby
|
def get_by_id(deny_assignment_id, custom_headers:nil)
response = get_by_id_async(deny_assignment_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
[
"def",
"get_by_id",
"(",
"deny_assignment_id",
",",
"custom_headers",
":",
"nil",
")",
"response",
"=",
"get_by_id_async",
"(",
"deny_assignment_id",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"response",
".",
"body",
"unless",
"response",
".",
"nil?",
"end"
] |
Gets a deny assignment by ID.
@param deny_assignment_id [String] The fully qualified deny assignment ID.
For example, use the format,
/subscriptions/{guid}/providers/Microsoft.Authorization/denyAssignments/{denyAssignmentId}
for subscription level deny assignments, or
/providers/Microsoft.Authorization/denyAssignments/{denyAssignmentId} for
tenant level deny assignments.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [DenyAssignment] operation results.
|
[
"Gets",
"a",
"deny",
"assignment",
"by",
"ID",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_authorization/lib/2018-07-01-preview/generated/azure_mgmt_authorization/deny_assignments.rb#L525-L528
|
14,306
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_iot_central/lib/2018-09-01/generated/azure_mgmt_iot_central/apps.rb
|
Azure::IotCentral::Mgmt::V2018_09_01.Apps.check_subdomain_availability
|
def check_subdomain_availability(operation_inputs, custom_headers:nil)
response = check_subdomain_availability_async(operation_inputs, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
ruby
|
def check_subdomain_availability(operation_inputs, custom_headers:nil)
response = check_subdomain_availability_async(operation_inputs, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
[
"def",
"check_subdomain_availability",
"(",
"operation_inputs",
",",
"custom_headers",
":",
"nil",
")",
"response",
"=",
"check_subdomain_availability_async",
"(",
"operation_inputs",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"response",
".",
"body",
"unless",
"response",
".",
"nil?",
"end"
] |
Check if an IoT Central application subdomain is available.
@param operation_inputs [OperationInputs] Set the name parameter in the
OperationInputs structure to the subdomain of the IoT Central application to
check.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [AppAvailabilityInfo] operation results.
|
[
"Check",
"if",
"an",
"IoT",
"Central",
"application",
"subdomain",
"is",
"available",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_iot_central/lib/2018-09-01/generated/azure_mgmt_iot_central/apps.rb#L552-L555
|
14,307
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_api_management/lib/2018-01-01/generated/azure_mgmt_api_management/notification_recipient_email.rb
|
Azure::ApiManagement::Mgmt::V2018_01_01.NotificationRecipientEmail.check_entity_exists_with_http_info
|
def check_entity_exists_with_http_info(resource_group_name, service_name, notification_name, email, custom_headers:nil)
check_entity_exists_async(resource_group_name, service_name, notification_name, email, custom_headers:custom_headers).value!
end
|
ruby
|
def check_entity_exists_with_http_info(resource_group_name, service_name, notification_name, email, custom_headers:nil)
check_entity_exists_async(resource_group_name, service_name, notification_name, email, custom_headers:custom_headers).value!
end
|
[
"def",
"check_entity_exists_with_http_info",
"(",
"resource_group_name",
",",
"service_name",
",",
"notification_name",
",",
"email",
",",
"custom_headers",
":",
"nil",
")",
"check_entity_exists_async",
"(",
"resource_group_name",
",",
"service_name",
",",
"notification_name",
",",
"email",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"end"
] |
Determine if Notification Recipient Email subscribed to the notification.
@param resource_group_name [String] The name of the resource group.
@param service_name [String] The name of the API Management service.
@param notification_name [NotificationName] Notification Name Identifier.
Possible values include: 'RequestPublisherNotificationMessage',
'PurchasePublisherNotificationMessage', 'NewApplicationNotificationMessage',
'BCC', 'NewIssuePublisherNotificationMessage', 'AccountClosedPublisher',
'QuotaLimitApproachingPublisherNotificationMessage'
@param email [String] Email identifier.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
[
"Determine",
"if",
"Notification",
"Recipient",
"Email",
"subscribed",
"to",
"the",
"notification",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_api_management/lib/2018-01-01/generated/azure_mgmt_api_management/notification_recipient_email.rb#L175-L177
|
14,308
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_api_management/lib/2018-01-01/generated/azure_mgmt_api_management/notification_recipient_email.rb
|
Azure::ApiManagement::Mgmt::V2018_01_01.NotificationRecipientEmail.create_or_update_with_http_info
|
def create_or_update_with_http_info(resource_group_name, service_name, notification_name, email, custom_headers:nil)
create_or_update_async(resource_group_name, service_name, notification_name, email, custom_headers:custom_headers).value!
end
|
ruby
|
def create_or_update_with_http_info(resource_group_name, service_name, notification_name, email, custom_headers:nil)
create_or_update_async(resource_group_name, service_name, notification_name, email, custom_headers:custom_headers).value!
end
|
[
"def",
"create_or_update_with_http_info",
"(",
"resource_group_name",
",",
"service_name",
",",
"notification_name",
",",
"email",
",",
"custom_headers",
":",
"nil",
")",
"create_or_update_async",
"(",
"resource_group_name",
",",
"service_name",
",",
"notification_name",
",",
"email",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"end"
] |
Adds the Email address to the list of Recipients for the Notification.
@param resource_group_name [String] The name of the resource group.
@param service_name [String] The name of the API Management service.
@param notification_name [NotificationName] Notification Name Identifier.
Possible values include: 'RequestPublisherNotificationMessage',
'PurchasePublisherNotificationMessage', 'NewApplicationNotificationMessage',
'BCC', 'NewIssuePublisherNotificationMessage', 'AccountClosedPublisher',
'QuotaLimitApproachingPublisherNotificationMessage'
@param email [String] Email identifier.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
[
"Adds",
"the",
"Email",
"address",
"to",
"the",
"list",
"of",
"Recipients",
"for",
"the",
"Notification",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_api_management/lib/2018-01-01/generated/azure_mgmt_api_management/notification_recipient_email.rb#L281-L283
|
14,309
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_api_management/lib/2018-01-01/generated/azure_mgmt_api_management/notification_recipient_email.rb
|
Azure::ApiManagement::Mgmt::V2018_01_01.NotificationRecipientEmail.delete_with_http_info
|
def delete_with_http_info(resource_group_name, service_name, notification_name, email, custom_headers:nil)
delete_async(resource_group_name, service_name, notification_name, email, custom_headers:custom_headers).value!
end
|
ruby
|
def delete_with_http_info(resource_group_name, service_name, notification_name, email, custom_headers:nil)
delete_async(resource_group_name, service_name, notification_name, email, custom_headers:custom_headers).value!
end
|
[
"def",
"delete_with_http_info",
"(",
"resource_group_name",
",",
"service_name",
",",
"notification_name",
",",
"email",
",",
"custom_headers",
":",
"nil",
")",
"delete_async",
"(",
"resource_group_name",
",",
"service_name",
",",
"notification_name",
",",
"email",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"end"
] |
Removes the email from the list of Notification.
@param resource_group_name [String] The name of the resource group.
@param service_name [String] The name of the API Management service.
@param notification_name [NotificationName] Notification Name Identifier.
Possible values include: 'RequestPublisherNotificationMessage',
'PurchasePublisherNotificationMessage', 'NewApplicationNotificationMessage',
'BCC', 'NewIssuePublisherNotificationMessage', 'AccountClosedPublisher',
'QuotaLimitApproachingPublisherNotificationMessage'
@param email [String] Email identifier.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
[
"Removes",
"the",
"email",
"from",
"the",
"list",
"of",
"Notification",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_api_management/lib/2018-01-01/generated/azure_mgmt_api_management/notification_recipient_email.rb#L405-L407
|
14,310
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_network/lib/2018-07-01/generated/azure_mgmt_network/network_interfaces.rb
|
Azure::Network::Mgmt::V2018_07_01.NetworkInterfaces.begin_update_tags_with_http_info
|
def begin_update_tags_with_http_info(resource_group_name, network_interface_name, parameters, custom_headers:nil)
begin_update_tags_async(resource_group_name, network_interface_name, parameters, custom_headers:custom_headers).value!
end
|
ruby
|
def begin_update_tags_with_http_info(resource_group_name, network_interface_name, parameters, custom_headers:nil)
begin_update_tags_async(resource_group_name, network_interface_name, parameters, custom_headers:custom_headers).value!
end
|
[
"def",
"begin_update_tags_with_http_info",
"(",
"resource_group_name",
",",
"network_interface_name",
",",
"parameters",
",",
"custom_headers",
":",
"nil",
")",
"begin_update_tags_async",
"(",
"resource_group_name",
",",
"network_interface_name",
",",
"parameters",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"end"
] |
Updates a network interface tags.
@param resource_group_name [String] The name of the resource group.
@param network_interface_name [String] The name of the network interface.
@param parameters [TagsObject] Parameters supplied to update network
interface tags.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
[
"Updates",
"a",
"network",
"interface",
"tags",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_network/lib/2018-07-01/generated/azure_mgmt_network/network_interfaces.rb#L731-L733
|
14,311
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_resources/lib/2016-02-01/generated/azure_mgmt_resources/providers.rb
|
Azure::Resources::Mgmt::V2016_02_01.Providers.unregister
|
def unregister(resource_provider_namespace, custom_headers:nil)
response = unregister_async(resource_provider_namespace, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
ruby
|
def unregister(resource_provider_namespace, custom_headers:nil)
response = unregister_async(resource_provider_namespace, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
[
"def",
"unregister",
"(",
"resource_provider_namespace",
",",
"custom_headers",
":",
"nil",
")",
"response",
"=",
"unregister_async",
"(",
"resource_provider_namespace",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"response",
".",
"body",
"unless",
"response",
".",
"nil?",
"end"
] |
Unregisters provider from a subscription.
@param resource_provider_namespace [String] Namespace of the resource
provider.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [Provider] operation results.
|
[
"Unregisters",
"provider",
"from",
"a",
"subscription",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_resources/lib/2016-02-01/generated/azure_mgmt_resources/providers.rb#L34-L37
|
14,312
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_resources/lib/2016-02-01/generated/azure_mgmt_resources/providers.rb
|
Azure::Resources::Mgmt::V2016_02_01.Providers.register
|
def register(resource_provider_namespace, custom_headers:nil)
response = register_async(resource_provider_namespace, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
ruby
|
def register(resource_provider_namespace, custom_headers:nil)
response = register_async(resource_provider_namespace, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
[
"def",
"register",
"(",
"resource_provider_namespace",
",",
"custom_headers",
":",
"nil",
")",
"response",
"=",
"register_async",
"(",
"resource_provider_namespace",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"response",
".",
"body",
"unless",
"response",
".",
"nil?",
"end"
] |
Registers provider to be used with a subscription.
@param resource_provider_namespace [String] Namespace of the resource
provider.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [Provider] operation results.
|
[
"Registers",
"provider",
"to",
"be",
"used",
"with",
"a",
"subscription",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_resources/lib/2016-02-01/generated/azure_mgmt_resources/providers.rb#L125-L128
|
14,313
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_resources/lib/2016-02-01/generated/azure_mgmt_resources/providers.rb
|
Azure::Resources::Mgmt::V2016_02_01.Providers.get_with_http_info
|
def get_with_http_info(resource_provider_namespace, expand:nil, custom_headers:nil)
get_async(resource_provider_namespace, expand:expand, custom_headers:custom_headers).value!
end
|
ruby
|
def get_with_http_info(resource_provider_namespace, expand:nil, custom_headers:nil)
get_async(resource_provider_namespace, expand:expand, custom_headers:custom_headers).value!
end
|
[
"def",
"get_with_http_info",
"(",
"resource_provider_namespace",
",",
"expand",
":",
"nil",
",",
"custom_headers",
":",
"nil",
")",
"get_async",
"(",
"resource_provider_namespace",
",",
"expand",
":",
"expand",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"end"
] |
Gets a resource provider.
@param resource_provider_namespace [String] Namespace of the resource
provider.
@param expand [String] The $expand query parameter. e.g. To include property
aliases in response, use $expand=resourceTypes/aliases.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
[
"Gets",
"a",
"resource",
"provider",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_resources/lib/2016-02-01/generated/azure_mgmt_resources/providers.rb#L331-L333
|
14,314
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_logic/lib/2016-06-01/generated/azure_mgmt_logic/certificates.rb
|
Azure::Logic::Mgmt::V2016_06_01.Certificates.get_with_http_info
|
def get_with_http_info(resource_group_name, integration_account_name, certificate_name, custom_headers:nil)
get_async(resource_group_name, integration_account_name, certificate_name, custom_headers:custom_headers).value!
end
|
ruby
|
def get_with_http_info(resource_group_name, integration_account_name, certificate_name, custom_headers:nil)
get_async(resource_group_name, integration_account_name, certificate_name, custom_headers:custom_headers).value!
end
|
[
"def",
"get_with_http_info",
"(",
"resource_group_name",
",",
"integration_account_name",
",",
"certificate_name",
",",
"custom_headers",
":",
"nil",
")",
"get_async",
"(",
"resource_group_name",
",",
"integration_account_name",
",",
"certificate_name",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"end"
] |
Gets an integration account certificate.
@param resource_group_name [String] The resource group name.
@param integration_account_name [String] The integration account name.
@param certificate_name [String] The integration account certificate name.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
[
"Gets",
"an",
"integration",
"account",
"certificate",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_logic/lib/2016-06-01/generated/azure_mgmt_logic/certificates.rb#L146-L148
|
14,315
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_logic/lib/2016-06-01/generated/azure_mgmt_logic/certificates.rb
|
Azure::Logic::Mgmt::V2016_06_01.Certificates.delete_with_http_info
|
def delete_with_http_info(resource_group_name, integration_account_name, certificate_name, custom_headers:nil)
delete_async(resource_group_name, integration_account_name, certificate_name, custom_headers:custom_headers).value!
end
|
ruby
|
def delete_with_http_info(resource_group_name, integration_account_name, certificate_name, custom_headers:nil)
delete_async(resource_group_name, integration_account_name, certificate_name, custom_headers:custom_headers).value!
end
|
[
"def",
"delete_with_http_info",
"(",
"resource_group_name",
",",
"integration_account_name",
",",
"certificate_name",
",",
"custom_headers",
":",
"nil",
")",
"delete_async",
"(",
"resource_group_name",
",",
"integration_account_name",
",",
"certificate_name",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"end"
] |
Deletes an integration account certificate.
@param resource_group_name [String] The resource group name.
@param integration_account_name [String] The integration account name.
@param certificate_name [String] The integration account certificate name.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
[
"Deletes",
"an",
"integration",
"account",
"certificate",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_logic/lib/2016-06-01/generated/azure_mgmt_logic/certificates.rb#L361-L363
|
14,316
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_network/lib/2019-02-01/generated/azure_mgmt_network/load_balancer_outbound_rules.rb
|
Azure::Network::Mgmt::V2019_02_01.LoadBalancerOutboundRules.get_with_http_info
|
def get_with_http_info(resource_group_name, load_balancer_name, outbound_rule_name, custom_headers:nil)
get_async(resource_group_name, load_balancer_name, outbound_rule_name, custom_headers:custom_headers).value!
end
|
ruby
|
def get_with_http_info(resource_group_name, load_balancer_name, outbound_rule_name, custom_headers:nil)
get_async(resource_group_name, load_balancer_name, outbound_rule_name, custom_headers:custom_headers).value!
end
|
[
"def",
"get_with_http_info",
"(",
"resource_group_name",
",",
"load_balancer_name",
",",
"outbound_rule_name",
",",
"custom_headers",
":",
"nil",
")",
"get_async",
"(",
"resource_group_name",
",",
"load_balancer_name",
",",
"outbound_rule_name",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"end"
] |
Gets the specified load balancer outbound rule.
@param resource_group_name [String] The name of the resource group.
@param load_balancer_name [String] The name of the load balancer.
@param outbound_rule_name [String] The name of the outbound rule.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
[
"Gets",
"the",
"specified",
"load",
"balancer",
"outbound",
"rule",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_network/lib/2019-02-01/generated/azure_mgmt_network/load_balancer_outbound_rules.rb#L143-L145
|
14,317
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_policy/lib/2015-10-01-preview/generated/azure_mgmt_policy/policy_assignments.rb
|
Azure::Policy::Mgmt::V2015_10_01_preview.PolicyAssignments.create_with_http_info
|
def create_with_http_info(scope, policy_assignment_name, parameters, custom_headers:nil)
create_async(scope, policy_assignment_name, parameters, custom_headers:custom_headers).value!
end
|
ruby
|
def create_with_http_info(scope, policy_assignment_name, parameters, custom_headers:nil)
create_async(scope, policy_assignment_name, parameters, custom_headers:custom_headers).value!
end
|
[
"def",
"create_with_http_info",
"(",
"scope",
",",
"policy_assignment_name",
",",
"parameters",
",",
"custom_headers",
":",
"nil",
")",
"create_async",
"(",
"scope",
",",
"policy_assignment_name",
",",
"parameters",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"end"
] |
Creates a policy assignment.
Policy assignments are inherited by child resources. For example, when you
apply a policy to a resource group that policy is assigned to all resources
in the group.
@param scope [String] The scope of the policy assignment.
@param policy_assignment_name [String] The name of the policy assignment.
@param parameters [PolicyAssignment] Parameters for the policy assignment.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
[
"Creates",
"a",
"policy",
"assignment",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_policy/lib/2015-10-01-preview/generated/azure_mgmt_policy/policy_assignments.rb#L155-L157
|
14,318
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_policy/lib/2015-10-01-preview/generated/azure_mgmt_policy/policy_assignments.rb
|
Azure::Policy::Mgmt::V2015_10_01_preview.PolicyAssignments.delete_by_id
|
def delete_by_id(policy_assignment_id, custom_headers:nil)
response = delete_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
ruby
|
def delete_by_id(policy_assignment_id, custom_headers:nil)
response = delete_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
[
"def",
"delete_by_id",
"(",
"policy_assignment_id",
",",
"custom_headers",
":",
"nil",
")",
"response",
"=",
"delete_by_id_async",
"(",
"policy_assignment_id",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"response",
".",
"body",
"unless",
"response",
".",
"nil?",
"end"
] |
Deletes a policy assignment by ID.
When providing a scope for the assignment, use
'/subscriptions/{subscription-id}/' for subscriptions,
'/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
resource groups, and
'/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
for resources.
@param policy_assignment_id [String] The ID of the policy assignment to
delete. Use the format
'/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [PolicyAssignment] operation results.
|
[
"Deletes",
"a",
"policy",
"assignment",
"by",
"ID",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_policy/lib/2015-10-01-preview/generated/azure_mgmt_policy/policy_assignments.rb#L653-L656
|
14,319
|
Azure/azure-sdk-for-ruby
|
management/azure_mgmt_policy/lib/2015-10-01-preview/generated/azure_mgmt_policy/policy_assignments.rb
|
Azure::Policy::Mgmt::V2015_10_01_preview.PolicyAssignments.get_by_id
|
def get_by_id(policy_assignment_id, custom_headers:nil)
response = get_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
ruby
|
def get_by_id(policy_assignment_id, custom_headers:nil)
response = get_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end
|
[
"def",
"get_by_id",
"(",
"policy_assignment_id",
",",
"custom_headers",
":",
"nil",
")",
"response",
"=",
"get_by_id_async",
"(",
"policy_assignment_id",
",",
"custom_headers",
":custom_headers",
")",
".",
"value!",
"response",
".",
"body",
"unless",
"response",
".",
"nil?",
"end"
] |
Gets a policy assignment by ID.
When providing a scope for the assignment, use
'/subscriptions/{subscription-id}/' for subscriptions,
'/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}' for
resource groups, and
'/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider-namespace}/{resource-type}/{resource-name}'
for resources.
@param policy_assignment_id [String] The ID of the policy assignment to get.
Use the format
'/{scope}/providers/Microsoft.Authorization/policyAssignments/{policy-assignment-name}'.
@param custom_headers [Hash{String => String}] A hash of custom headers that
will be added to the HTTP request.
@return [PolicyAssignment] operation results.
|
[
"Gets",
"a",
"policy",
"assignment",
"by",
"ID",
"."
] |
78eedacf8f8cbd65c2d8a2af421405eaa4373d8e
|
https://github.com/Azure/azure-sdk-for-ruby/blob/78eedacf8f8cbd65c2d8a2af421405eaa4373d8e/management/azure_mgmt_policy/lib/2015-10-01-preview/generated/azure_mgmt_policy/policy_assignments.rb#L898-L901
|
14,320
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/numeric_value.rb
|
RequestLogAnalyzer::Tracker.NumericValue.prepare
|
def prepare
fail "No value field set up for numeric tracker #{inspect}" unless options[:value]
fail "No categorizer set up for numeric tracker #{inspect}" unless options[:category]
unless options[:multiple]
@categorizer = create_lambda(options[:category])
@valueizer = create_lambda(options[:value])
end
@number_of_buckets = options[:number_of_buckets] || 1000
@min_bucket_value = options[:min_bucket_value] ? options[:min_bucket_value].to_f : 0.000001
@max_bucket_value = options[:max_bucket_value] ? options[:max_bucket_value].to_f : 1_000_000_000
# precalculate the bucket size
@bucket_size = (Math.log(@max_bucket_value) - Math.log(@min_bucket_value)) / @number_of_buckets.to_f
@categories = {}
end
|
ruby
|
def prepare
fail "No value field set up for numeric tracker #{inspect}" unless options[:value]
fail "No categorizer set up for numeric tracker #{inspect}" unless options[:category]
unless options[:multiple]
@categorizer = create_lambda(options[:category])
@valueizer = create_lambda(options[:value])
end
@number_of_buckets = options[:number_of_buckets] || 1000
@min_bucket_value = options[:min_bucket_value] ? options[:min_bucket_value].to_f : 0.000001
@max_bucket_value = options[:max_bucket_value] ? options[:max_bucket_value].to_f : 1_000_000_000
# precalculate the bucket size
@bucket_size = (Math.log(@max_bucket_value) - Math.log(@min_bucket_value)) / @number_of_buckets.to_f
@categories = {}
end
|
[
"def",
"prepare",
"fail",
"\"No value field set up for numeric tracker #{inspect}\"",
"unless",
"options",
"[",
":value",
"]",
"fail",
"\"No categorizer set up for numeric tracker #{inspect}\"",
"unless",
"options",
"[",
":category",
"]",
"unless",
"options",
"[",
":multiple",
"]",
"@categorizer",
"=",
"create_lambda",
"(",
"options",
"[",
":category",
"]",
")",
"@valueizer",
"=",
"create_lambda",
"(",
"options",
"[",
":value",
"]",
")",
"end",
"@number_of_buckets",
"=",
"options",
"[",
":number_of_buckets",
"]",
"||",
"1000",
"@min_bucket_value",
"=",
"options",
"[",
":min_bucket_value",
"]",
"?",
"options",
"[",
":min_bucket_value",
"]",
".",
"to_f",
":",
"0.000001",
"@max_bucket_value",
"=",
"options",
"[",
":max_bucket_value",
"]",
"?",
"options",
"[",
":max_bucket_value",
"]",
".",
"to_f",
":",
"1_000_000_000",
"# precalculate the bucket size",
"@bucket_size",
"=",
"(",
"Math",
".",
"log",
"(",
"@max_bucket_value",
")",
"-",
"Math",
".",
"log",
"(",
"@min_bucket_value",
")",
")",
"/",
"@number_of_buckets",
".",
"to_f",
"@categories",
"=",
"{",
"}",
"end"
] |
Sets up the numeric value tracker. It will check whether the value and category
options are set that are used to extract and categorize the values during
parsing. Two lambda procedures are created for these tasks
|
[
"Sets",
"up",
"the",
"numeric",
"value",
"tracker",
".",
"It",
"will",
"check",
"whether",
"the",
"value",
"and",
"category",
"options",
"are",
"set",
"that",
"are",
"used",
"to",
"extract",
"and",
"categorize",
"the",
"values",
"during",
"parsing",
".",
"Two",
"lambda",
"procedures",
"are",
"created",
"for",
"these",
"tasks"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/numeric_value.rb#L8-L25
|
14,321
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/numeric_value.rb
|
RequestLogAnalyzer::Tracker.NumericValue.update
|
def update(request)
if options[:multiple]
found_categories = request.every(options[:category])
found_values = request.every(options[:value])
fail 'Capture mismatch for multiple values in a request' unless found_categories.length == found_values.length
found_categories.each_with_index do |cat, index|
update_statistics(cat, found_values[index]) if cat && found_values[index].is_a?(Numeric)
end
else
category = @categorizer.call(request)
value = @valueizer.call(request)
update_statistics(category, value) if (value.is_a?(Numeric) || value.is_a?(Array)) && category
end
end
|
ruby
|
def update(request)
if options[:multiple]
found_categories = request.every(options[:category])
found_values = request.every(options[:value])
fail 'Capture mismatch for multiple values in a request' unless found_categories.length == found_values.length
found_categories.each_with_index do |cat, index|
update_statistics(cat, found_values[index]) if cat && found_values[index].is_a?(Numeric)
end
else
category = @categorizer.call(request)
value = @valueizer.call(request)
update_statistics(category, value) if (value.is_a?(Numeric) || value.is_a?(Array)) && category
end
end
|
[
"def",
"update",
"(",
"request",
")",
"if",
"options",
"[",
":multiple",
"]",
"found_categories",
"=",
"request",
".",
"every",
"(",
"options",
"[",
":category",
"]",
")",
"found_values",
"=",
"request",
".",
"every",
"(",
"options",
"[",
":value",
"]",
")",
"fail",
"'Capture mismatch for multiple values in a request'",
"unless",
"found_categories",
".",
"length",
"==",
"found_values",
".",
"length",
"found_categories",
".",
"each_with_index",
"do",
"|",
"cat",
",",
"index",
"|",
"update_statistics",
"(",
"cat",
",",
"found_values",
"[",
"index",
"]",
")",
"if",
"cat",
"&&",
"found_values",
"[",
"index",
"]",
".",
"is_a?",
"(",
"Numeric",
")",
"end",
"else",
"category",
"=",
"@categorizer",
".",
"call",
"(",
"request",
")",
"value",
"=",
"@valueizer",
".",
"call",
"(",
"request",
")",
"update_statistics",
"(",
"category",
",",
"value",
")",
"if",
"(",
"value",
".",
"is_a?",
"(",
"Numeric",
")",
"||",
"value",
".",
"is_a?",
"(",
"Array",
")",
")",
"&&",
"category",
"end",
"end"
] |
Get the value information from the request and store it in the respective categories.
If a request can contain multiple usable values for this tracker, the :multiple option
should be set to true. In this case, all the values and respective categories will be
read from the request using the #every method from the fields given in the :value and
:category option.
If the request contains only one suitable value and the :multiple is not set, it will
read the single value and category from the fields provided in the :value and :category
option, or calculate it with any lambda procedure that is assigned to these options. The
request will be passed to procedure as input for the calculation.
@param [RequestLogAnalyzer::Request] request The request to get the information from.
|
[
"Get",
"the",
"value",
"information",
"from",
"the",
"request",
"and",
"store",
"it",
"in",
"the",
"respective",
"categories",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/numeric_value.rb#L40-L54
|
14,322
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/numeric_value.rb
|
RequestLogAnalyzer::Tracker.NumericValue.display_value
|
def display_value(value)
return '- ' if value.nil?
return '0 ' if value.zero?
case [Math.log10(value.abs).floor, 0].max
when 0...4 then '%d ' % value
when 4...7 then '%dk' % (value / 1000)
when 7...10 then '%dM' % (value / 1_000_000)
when 10...13 then '%dG' % (value / 1_000_000_000)
when 13...16 then '%dT' % (value / 1_000_000_000_000)
else '%dP' % (value / 1_000_000_000_000_000)
end
end
|
ruby
|
def display_value(value)
return '- ' if value.nil?
return '0 ' if value.zero?
case [Math.log10(value.abs).floor, 0].max
when 0...4 then '%d ' % value
when 4...7 then '%dk' % (value / 1000)
when 7...10 then '%dM' % (value / 1_000_000)
when 10...13 then '%dG' % (value / 1_000_000_000)
when 13...16 then '%dT' % (value / 1_000_000_000_000)
else '%dP' % (value / 1_000_000_000_000_000)
end
end
|
[
"def",
"display_value",
"(",
"value",
")",
"return",
"'- '",
"if",
"value",
".",
"nil?",
"return",
"'0 '",
"if",
"value",
".",
"zero?",
"case",
"[",
"Math",
".",
"log10",
"(",
"value",
".",
"abs",
")",
".",
"floor",
",",
"0",
"]",
".",
"max",
"when",
"0",
"...",
"4",
"then",
"'%d '",
"%",
"value",
"when",
"4",
"...",
"7",
"then",
"'%dk'",
"%",
"(",
"value",
"/",
"1000",
")",
"when",
"7",
"...",
"10",
"then",
"'%dM'",
"%",
"(",
"value",
"/",
"1_000_000",
")",
"when",
"10",
"...",
"13",
"then",
"'%dG'",
"%",
"(",
"value",
"/",
"1_000_000_000",
")",
"when",
"13",
"...",
"16",
"then",
"'%dT'",
"%",
"(",
"value",
"/",
"1_000_000_000_000",
")",
"else",
"'%dP'",
"%",
"(",
"value",
"/",
"1_000_000_000_000_000",
")",
"end",
"end"
] |
Display a value
|
[
"Display",
"a",
"value"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/numeric_value.rb#L73-L85
|
14,323
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/numeric_value.rb
|
RequestLogAnalyzer::Tracker.NumericValue.title
|
def title
@title ||= begin
if options[:title]
options[:title]
else
title_builder = ''
title_builder << "#{options[:value]} " if options[:value].is_a?(Symbol)
title_builder << (options[:category].is_a?(Symbol) ? "per #{options[:category]}" : 'per request')
title_builder
end
end
end
|
ruby
|
def title
@title ||= begin
if options[:title]
options[:title]
else
title_builder = ''
title_builder << "#{options[:value]} " if options[:value].is_a?(Symbol)
title_builder << (options[:category].is_a?(Symbol) ? "per #{options[:category]}" : 'per request')
title_builder
end
end
end
|
[
"def",
"title",
"@title",
"||=",
"begin",
"if",
"options",
"[",
":title",
"]",
"options",
"[",
":title",
"]",
"else",
"title_builder",
"=",
"''",
"title_builder",
"<<",
"\"#{options[:value]} \"",
"if",
"options",
"[",
":value",
"]",
".",
"is_a?",
"(",
"Symbol",
")",
"title_builder",
"<<",
"(",
"options",
"[",
":category",
"]",
".",
"is_a?",
"(",
"Symbol",
")",
"?",
"\"per #{options[:category]}\"",
":",
"'per request'",
")",
"title_builder",
"end",
"end",
"end"
] |
Returns the title of this tracker for reports
|
[
"Returns",
"the",
"title",
"of",
"this",
"tracker",
"for",
"reports"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/numeric_value.rb#L104-L115
|
14,324
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/numeric_value.rb
|
RequestLogAnalyzer::Tracker.NumericValue.to_yaml_object
|
def to_yaml_object
return nil if @categories.empty?
@categories.each do |cat, info|
info[:stddev] = stddev(cat)
info[:median] = median(cat) if info[:buckets]
info[:interval_95_percent] = percentile_interval(cat, 95) if info[:buckets]
end
@categories
end
|
ruby
|
def to_yaml_object
return nil if @categories.empty?
@categories.each do |cat, info|
info[:stddev] = stddev(cat)
info[:median] = median(cat) if info[:buckets]
info[:interval_95_percent] = percentile_interval(cat, 95) if info[:buckets]
end
@categories
end
|
[
"def",
"to_yaml_object",
"return",
"nil",
"if",
"@categories",
".",
"empty?",
"@categories",
".",
"each",
"do",
"|",
"cat",
",",
"info",
"|",
"info",
"[",
":stddev",
"]",
"=",
"stddev",
"(",
"cat",
")",
"info",
"[",
":median",
"]",
"=",
"median",
"(",
"cat",
")",
"if",
"info",
"[",
":buckets",
"]",
"info",
"[",
":interval_95_percent",
"]",
"=",
"percentile_interval",
"(",
"cat",
",",
"95",
")",
"if",
"info",
"[",
":buckets",
"]",
"end",
"@categories",
"end"
] |
Returns all the categories and the tracked duration as a hash than can be exported to YAML
|
[
"Returns",
"all",
"the",
"categories",
"and",
"the",
"tracked",
"duration",
"as",
"a",
"hash",
"than",
"can",
"be",
"exported",
"to",
"YAML"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/numeric_value.rb#L118-L126
|
14,325
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/numeric_value.rb
|
RequestLogAnalyzer::Tracker.NumericValue.bucket_index
|
def bucket_index(value)
return 0 if value < @min_bucket_value
return @number_of_buckets - 1 if value >= @max_bucket_value
((Math.log(value) - Math.log(@min_bucket_value)) / @bucket_size).floor
end
|
ruby
|
def bucket_index(value)
return 0 if value < @min_bucket_value
return @number_of_buckets - 1 if value >= @max_bucket_value
((Math.log(value) - Math.log(@min_bucket_value)) / @bucket_size).floor
end
|
[
"def",
"bucket_index",
"(",
"value",
")",
"return",
"0",
"if",
"value",
"<",
"@min_bucket_value",
"return",
"@number_of_buckets",
"-",
"1",
"if",
"value",
">=",
"@max_bucket_value",
"(",
"(",
"Math",
".",
"log",
"(",
"value",
")",
"-",
"Math",
".",
"log",
"(",
"@min_bucket_value",
")",
")",
"/",
"@bucket_size",
")",
".",
"floor",
"end"
] |
Returns the bucket index for a value
|
[
"Returns",
"the",
"bucket",
"index",
"for",
"a",
"value"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/numeric_value.rb#L129-L134
|
14,326
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/numeric_value.rb
|
RequestLogAnalyzer::Tracker.NumericValue.bucket_value
|
def bucket_value(index, type = nil)
case type
when :begin, :start, :lower, :lower_bound then bucket_lower_bound(index)
when :end, :finish, :upper, :upper_bound then bucket_upper_bound(index)
else bucket_average_value(index)
end
end
|
ruby
|
def bucket_value(index, type = nil)
case type
when :begin, :start, :lower, :lower_bound then bucket_lower_bound(index)
when :end, :finish, :upper, :upper_bound then bucket_upper_bound(index)
else bucket_average_value(index)
end
end
|
[
"def",
"bucket_value",
"(",
"index",
",",
"type",
"=",
"nil",
")",
"case",
"type",
"when",
":begin",
",",
":start",
",",
":lower",
",",
":lower_bound",
"then",
"bucket_lower_bound",
"(",
"index",
")",
"when",
":end",
",",
":finish",
",",
":upper",
",",
":upper_bound",
"then",
"bucket_upper_bound",
"(",
"index",
")",
"else",
"bucket_average_value",
"(",
"index",
")",
"end",
"end"
] |
Returns a single value representing a bucket.
|
[
"Returns",
"a",
"single",
"value",
"representing",
"a",
"bucket",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/numeric_value.rb#L152-L158
|
14,327
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/numeric_value.rb
|
RequestLogAnalyzer::Tracker.NumericValue.percentile_index
|
def percentile_index(category, x, inclusive = false)
total_encountered = 0
@categories[category][:buckets].each_with_index do |count, index|
total_encountered += count
percentage = ((total_encountered.to_f / hits(category).to_f) * 100).floor
return index if (inclusive && percentage >= x) || (!inclusive && percentage > x)
end
end
|
ruby
|
def percentile_index(category, x, inclusive = false)
total_encountered = 0
@categories[category][:buckets].each_with_index do |count, index|
total_encountered += count
percentage = ((total_encountered.to_f / hits(category).to_f) * 100).floor
return index if (inclusive && percentage >= x) || (!inclusive && percentage > x)
end
end
|
[
"def",
"percentile_index",
"(",
"category",
",",
"x",
",",
"inclusive",
"=",
"false",
")",
"total_encountered",
"=",
"0",
"@categories",
"[",
"category",
"]",
"[",
":buckets",
"]",
".",
"each_with_index",
"do",
"|",
"count",
",",
"index",
"|",
"total_encountered",
"+=",
"count",
"percentage",
"=",
"(",
"(",
"total_encountered",
".",
"to_f",
"/",
"hits",
"(",
"category",
")",
".",
"to_f",
")",
"*",
"100",
")",
".",
"floor",
"return",
"index",
"if",
"(",
"inclusive",
"&&",
"percentage",
">=",
"x",
")",
"||",
"(",
"!",
"inclusive",
"&&",
"percentage",
">",
"x",
")",
"end",
"end"
] |
Returns the upper bound value that would include x% of the hits.
|
[
"Returns",
"the",
"upper",
"bound",
"value",
"that",
"would",
"include",
"x%",
"of",
"the",
"hits",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/numeric_value.rb#L171-L178
|
14,328
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/numeric_value.rb
|
RequestLogAnalyzer::Tracker.NumericValue.percentile_interval
|
def percentile_interval(category, x)
case x
when Range
lower, upper = percentile_indices(category, x.begin, x.end)
Range.new(bucket_lower_bound(lower), bucket_upper_bound(upper))
when Numeric
percentile_interval(category, Range.new((100 - x) / 2, (100 - (100 - x) / 2)))
else
fail 'What does it mean?'
end
end
|
ruby
|
def percentile_interval(category, x)
case x
when Range
lower, upper = percentile_indices(category, x.begin, x.end)
Range.new(bucket_lower_bound(lower), bucket_upper_bound(upper))
when Numeric
percentile_interval(category, Range.new((100 - x) / 2, (100 - (100 - x) / 2)))
else
fail 'What does it mean?'
end
end
|
[
"def",
"percentile_interval",
"(",
"category",
",",
"x",
")",
"case",
"x",
"when",
"Range",
"lower",
",",
"upper",
"=",
"percentile_indices",
"(",
"category",
",",
"x",
".",
"begin",
",",
"x",
".",
"end",
")",
"Range",
".",
"new",
"(",
"bucket_lower_bound",
"(",
"lower",
")",
",",
"bucket_upper_bound",
"(",
"upper",
")",
")",
"when",
"Numeric",
"percentile_interval",
"(",
"category",
",",
"Range",
".",
"new",
"(",
"(",
"100",
"-",
"x",
")",
"/",
"2",
",",
"(",
"100",
"-",
"(",
"100",
"-",
"x",
")",
"/",
"2",
")",
")",
")",
"else",
"fail",
"'What does it mean?'",
"end",
"end"
] |
Returns a percentile interval, i.e. the lower bound and the upper bound of the values
that represent the x%-interval for the bucketized dataset.
A 90% interval means that 5% of the values would have been lower than the lower bound and
5% would have been higher than the upper bound, leaving 90% of the values within the bounds.
You can also provide a Range to specify the lower bound and upper bound percentages (e.g. 5..95).
|
[
"Returns",
"a",
"percentile",
"interval",
"i",
".",
"e",
".",
"the",
"lower",
"bound",
"and",
"the",
"upper",
"bound",
"of",
"the",
"values",
"that",
"represent",
"the",
"x%",
"-",
"interval",
"for",
"the",
"bucketized",
"dataset",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/numeric_value.rb#L209-L219
|
14,329
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/numeric_value.rb
|
RequestLogAnalyzer::Tracker.NumericValue.statistics_header
|
def statistics_header(options)
[
{ title: options[:title], width: :rest },
{ title: 'Hits', align: :right, highlight: (options[:highlight] == :hits), min_width: 4 },
{ title: 'Sum', align: :right, highlight: (options[:highlight] == :sum), min_width: 6 },
{ title: 'Mean', align: :right, highlight: (options[:highlight] == :mean), min_width: 6 },
{ title: 'StdDev', align: :right, highlight: (options[:highlight] == :stddev), min_width: 6 },
{ title: 'Min', align: :right, highlight: (options[:highlight] == :min), min_width: 6 },
{ title: 'Max', align: :right, highlight: (options[:highlight] == :max), min_width: 6 },
{ title: '95 %tile', align: :right, highlight: (options[:highlight] == :percentile_interval), min_width: 11 }
]
end
|
ruby
|
def statistics_header(options)
[
{ title: options[:title], width: :rest },
{ title: 'Hits', align: :right, highlight: (options[:highlight] == :hits), min_width: 4 },
{ title: 'Sum', align: :right, highlight: (options[:highlight] == :sum), min_width: 6 },
{ title: 'Mean', align: :right, highlight: (options[:highlight] == :mean), min_width: 6 },
{ title: 'StdDev', align: :right, highlight: (options[:highlight] == :stddev), min_width: 6 },
{ title: 'Min', align: :right, highlight: (options[:highlight] == :min), min_width: 6 },
{ title: 'Max', align: :right, highlight: (options[:highlight] == :max), min_width: 6 },
{ title: '95 %tile', align: :right, highlight: (options[:highlight] == :percentile_interval), min_width: 11 }
]
end
|
[
"def",
"statistics_header",
"(",
"options",
")",
"[",
"{",
"title",
":",
"options",
"[",
":title",
"]",
",",
"width",
":",
":rest",
"}",
",",
"{",
"title",
":",
"'Hits'",
",",
"align",
":",
":right",
",",
"highlight",
":",
"(",
"options",
"[",
":highlight",
"]",
"==",
":hits",
")",
",",
"min_width",
":",
"4",
"}",
",",
"{",
"title",
":",
"'Sum'",
",",
"align",
":",
":right",
",",
"highlight",
":",
"(",
"options",
"[",
":highlight",
"]",
"==",
":sum",
")",
",",
"min_width",
":",
"6",
"}",
",",
"{",
"title",
":",
"'Mean'",
",",
"align",
":",
":right",
",",
"highlight",
":",
"(",
"options",
"[",
":highlight",
"]",
"==",
":mean",
")",
",",
"min_width",
":",
"6",
"}",
",",
"{",
"title",
":",
"'StdDev'",
",",
"align",
":",
":right",
",",
"highlight",
":",
"(",
"options",
"[",
":highlight",
"]",
"==",
":stddev",
")",
",",
"min_width",
":",
"6",
"}",
",",
"{",
"title",
":",
"'Min'",
",",
"align",
":",
":right",
",",
"highlight",
":",
"(",
"options",
"[",
":highlight",
"]",
"==",
":min",
")",
",",
"min_width",
":",
"6",
"}",
",",
"{",
"title",
":",
"'Max'",
",",
"align",
":",
":right",
",",
"highlight",
":",
"(",
"options",
"[",
":highlight",
"]",
"==",
":max",
")",
",",
"min_width",
":",
"6",
"}",
",",
"{",
"title",
":",
"'95 %tile'",
",",
"align",
":",
":right",
",",
"highlight",
":",
"(",
"options",
"[",
":highlight",
"]",
"==",
":percentile_interval",
")",
",",
"min_width",
":",
"11",
"}",
"]",
"end"
] |
Returns the column header for a statistics table to report on the statistics result
|
[
"Returns",
"the",
"column",
"header",
"for",
"a",
"statistics",
"table",
"to",
"report",
"on",
"the",
"statistics",
"result"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/numeric_value.rb#L311-L322
|
14,330
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/numeric_value.rb
|
RequestLogAnalyzer::Tracker.NumericValue.statistics_row
|
def statistics_row(cat)
[cat, hits(cat), display_value(sum(cat)), display_value(mean(cat)), display_value(stddev(cat)),
display_value(min(cat)), display_value(max(cat)),
display_value(percentile_interval(cat, 95).begin) + '-' + display_value(percentile_interval(cat, 95).end)]
end
|
ruby
|
def statistics_row(cat)
[cat, hits(cat), display_value(sum(cat)), display_value(mean(cat)), display_value(stddev(cat)),
display_value(min(cat)), display_value(max(cat)),
display_value(percentile_interval(cat, 95).begin) + '-' + display_value(percentile_interval(cat, 95).end)]
end
|
[
"def",
"statistics_row",
"(",
"cat",
")",
"[",
"cat",
",",
"hits",
"(",
"cat",
")",
",",
"display_value",
"(",
"sum",
"(",
"cat",
")",
")",
",",
"display_value",
"(",
"mean",
"(",
"cat",
")",
")",
",",
"display_value",
"(",
"stddev",
"(",
"cat",
")",
")",
",",
"display_value",
"(",
"min",
"(",
"cat",
")",
")",
",",
"display_value",
"(",
"max",
"(",
"cat",
")",
")",
",",
"display_value",
"(",
"percentile_interval",
"(",
"cat",
",",
"95",
")",
".",
"begin",
")",
"+",
"'-'",
"+",
"display_value",
"(",
"percentile_interval",
"(",
"cat",
",",
"95",
")",
".",
"end",
")",
"]",
"end"
] |
Returns a row of statistics information for a report table, given a category
|
[
"Returns",
"a",
"row",
"of",
"statistics",
"information",
"for",
"a",
"report",
"table",
"given",
"a",
"category"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/numeric_value.rb#L325-L329
|
14,331
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/source/log_parser.rb
|
RequestLogAnalyzer::Source.LogParser.decompress_file?
|
def decompress_file?(filename)
nice_command = 'nice -n 5'
return "#{nice_command} gunzip -c -d #{filename}" if filename.match(/\.tar.gz$/) || filename.match(/\.tgz$/) || filename.match(/\.gz$/)
return "#{nice_command} bunzip2 -c -d #{filename}" if filename.match(/\.bz2$/)
return "#{nice_command} unzip -p #{filename}" if filename.match(/\.zip$/)
''
end
|
ruby
|
def decompress_file?(filename)
nice_command = 'nice -n 5'
return "#{nice_command} gunzip -c -d #{filename}" if filename.match(/\.tar.gz$/) || filename.match(/\.tgz$/) || filename.match(/\.gz$/)
return "#{nice_command} bunzip2 -c -d #{filename}" if filename.match(/\.bz2$/)
return "#{nice_command} unzip -p #{filename}" if filename.match(/\.zip$/)
''
end
|
[
"def",
"decompress_file?",
"(",
"filename",
")",
"nice_command",
"=",
"'nice -n 5'",
"return",
"\"#{nice_command} gunzip -c -d #{filename}\"",
"if",
"filename",
".",
"match",
"(",
"/",
"\\.",
"/",
")",
"||",
"filename",
".",
"match",
"(",
"/",
"\\.",
"/",
")",
"||",
"filename",
".",
"match",
"(",
"/",
"\\.",
"/",
")",
"return",
"\"#{nice_command} bunzip2 -c -d #{filename}\"",
"if",
"filename",
".",
"match",
"(",
"/",
"\\.",
"/",
")",
"return",
"\"#{nice_command} unzip -p #{filename}\"",
"if",
"filename",
".",
"match",
"(",
"/",
"\\.",
"/",
")",
"''",
"end"
] |
Check if a file has a compressed extention in the filename.
If recognized, return the command string used to decompress the file
|
[
"Check",
"if",
"a",
"file",
"has",
"a",
"compressed",
"extention",
"in",
"the",
"filename",
".",
"If",
"recognized",
"return",
"the",
"command",
"string",
"used",
"to",
"decompress",
"the",
"file"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/source/log_parser.rb#L97-L105
|
14,332
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/source/log_parser.rb
|
RequestLogAnalyzer::Source.LogParser.parse_file
|
def parse_file(file, options = {}, &block)
if File.directory?(file)
parse_files(Dir["#{ file }/*"], options, &block)
return
end
@current_source = File.expand_path(file)
@source_changes_handler.call(:started, @current_source) if @source_changes_handler
if decompress_file?(file).empty?
@progress_handler = @dormant_progress_handler
@progress_handler.call(:started, file) if @progress_handler
File.open(file, 'rb') { |f| parse_io(f, options, &block) }
@progress_handler.call(:finished, file) if @progress_handler
@progress_handler = nil
@processed_files.push(@current_source.dup)
else
IO.popen(decompress_file?(file), 'rb') { |f| parse_io(f, options, &block) }
end
@source_changes_handler.call(:finished, @current_source) if @source_changes_handler
@current_source = nil
end
|
ruby
|
def parse_file(file, options = {}, &block)
if File.directory?(file)
parse_files(Dir["#{ file }/*"], options, &block)
return
end
@current_source = File.expand_path(file)
@source_changes_handler.call(:started, @current_source) if @source_changes_handler
if decompress_file?(file).empty?
@progress_handler = @dormant_progress_handler
@progress_handler.call(:started, file) if @progress_handler
File.open(file, 'rb') { |f| parse_io(f, options, &block) }
@progress_handler.call(:finished, file) if @progress_handler
@progress_handler = nil
@processed_files.push(@current_source.dup)
else
IO.popen(decompress_file?(file), 'rb') { |f| parse_io(f, options, &block) }
end
@source_changes_handler.call(:finished, @current_source) if @source_changes_handler
@current_source = nil
end
|
[
"def",
"parse_file",
"(",
"file",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"if",
"File",
".",
"directory?",
"(",
"file",
")",
"parse_files",
"(",
"Dir",
"[",
"\"#{ file }/*\"",
"]",
",",
"options",
",",
"block",
")",
"return",
"end",
"@current_source",
"=",
"File",
".",
"expand_path",
"(",
"file",
")",
"@source_changes_handler",
".",
"call",
"(",
":started",
",",
"@current_source",
")",
"if",
"@source_changes_handler",
"if",
"decompress_file?",
"(",
"file",
")",
".",
"empty?",
"@progress_handler",
"=",
"@dormant_progress_handler",
"@progress_handler",
".",
"call",
"(",
":started",
",",
"file",
")",
"if",
"@progress_handler",
"File",
".",
"open",
"(",
"file",
",",
"'rb'",
")",
"{",
"|",
"f",
"|",
"parse_io",
"(",
"f",
",",
"options",
",",
"block",
")",
"}",
"@progress_handler",
".",
"call",
"(",
":finished",
",",
"file",
")",
"if",
"@progress_handler",
"@progress_handler",
"=",
"nil",
"@processed_files",
".",
"push",
"(",
"@current_source",
".",
"dup",
")",
"else",
"IO",
".",
"popen",
"(",
"decompress_file?",
"(",
"file",
")",
",",
"'rb'",
")",
"{",
"|",
"f",
"|",
"parse_io",
"(",
"f",
",",
"options",
",",
"block",
")",
"}",
"end",
"@source_changes_handler",
".",
"call",
"(",
":finished",
",",
"@current_source",
")",
"if",
"@source_changes_handler",
"@current_source",
"=",
"nil",
"end"
] |
Parses a log file. Creates an IO stream for the provided file, and sends it to parse_io for
further handling. This method supports progress updates that can be used to display a progressbar
If the logfile is compressed, it is uncompressed to stdout and read.
TODO: Check if IO.popen encounters problems with the given command line.
TODO: Fix progress bar that is broken for IO.popen, as it returns a single string.
<tt>file</tt>:: The file that should be parsed.
<tt>options</tt>:: A Hash of options that will be pased to parse_io.
|
[
"Parses",
"a",
"log",
"file",
".",
"Creates",
"an",
"IO",
"stream",
"for",
"the",
"provided",
"file",
"and",
"sends",
"it",
"to",
"parse_io",
"for",
"further",
"handling",
".",
"This",
"method",
"supports",
"progress",
"updates",
"that",
"can",
"be",
"used",
"to",
"display",
"a",
"progressbar"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/source/log_parser.rb#L116-L144
|
14,333
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/source/log_parser.rb
|
RequestLogAnalyzer::Source.LogParser.update_current_request
|
def update_current_request(request_data, &block) # :yields: request
if alternative_header_line?(request_data)
if @current_request
@current_request << request_data
else
@current_request = @file_format.request(request_data)
end
elsif header_line?(request_data)
if @current_request
case options[:parse_strategy]
when 'assume-correct'
handle_request(@current_request, &block)
@current_request = @file_format.request(request_data)
when 'cautious'
@skipped_lines += 1
warn(:unclosed_request, "Encountered header line (#{request_data[:line_definition].name.inspect}), but previous request was not closed!")
@current_request = nil # remove all data that was parsed, skip next request as well.
end
elsif footer_line?(request_data)
handle_request(@file_format.request(request_data), &block)
else
@current_request = @file_format.request(request_data)
end
else
if @current_request
@current_request << request_data
if footer_line?(request_data)
handle_request(@current_request, &block) # yield @current_request
@current_request = nil
end
else
@skipped_lines += 1
warn(:no_current_request, "Parseable line (#{request_data[:line_definition].name.inspect}) found outside of a request!")
end
end
end
|
ruby
|
def update_current_request(request_data, &block) # :yields: request
if alternative_header_line?(request_data)
if @current_request
@current_request << request_data
else
@current_request = @file_format.request(request_data)
end
elsif header_line?(request_data)
if @current_request
case options[:parse_strategy]
when 'assume-correct'
handle_request(@current_request, &block)
@current_request = @file_format.request(request_data)
when 'cautious'
@skipped_lines += 1
warn(:unclosed_request, "Encountered header line (#{request_data[:line_definition].name.inspect}), but previous request was not closed!")
@current_request = nil # remove all data that was parsed, skip next request as well.
end
elsif footer_line?(request_data)
handle_request(@file_format.request(request_data), &block)
else
@current_request = @file_format.request(request_data)
end
else
if @current_request
@current_request << request_data
if footer_line?(request_data)
handle_request(@current_request, &block) # yield @current_request
@current_request = nil
end
else
@skipped_lines += 1
warn(:no_current_request, "Parseable line (#{request_data[:line_definition].name.inspect}) found outside of a request!")
end
end
end
|
[
"def",
"update_current_request",
"(",
"request_data",
",",
"&",
"block",
")",
"# :yields: request",
"if",
"alternative_header_line?",
"(",
"request_data",
")",
"if",
"@current_request",
"@current_request",
"<<",
"request_data",
"else",
"@current_request",
"=",
"@file_format",
".",
"request",
"(",
"request_data",
")",
"end",
"elsif",
"header_line?",
"(",
"request_data",
")",
"if",
"@current_request",
"case",
"options",
"[",
":parse_strategy",
"]",
"when",
"'assume-correct'",
"handle_request",
"(",
"@current_request",
",",
"block",
")",
"@current_request",
"=",
"@file_format",
".",
"request",
"(",
"request_data",
")",
"when",
"'cautious'",
"@skipped_lines",
"+=",
"1",
"warn",
"(",
":unclosed_request",
",",
"\"Encountered header line (#{request_data[:line_definition].name.inspect}), but previous request was not closed!\"",
")",
"@current_request",
"=",
"nil",
"# remove all data that was parsed, skip next request as well.",
"end",
"elsif",
"footer_line?",
"(",
"request_data",
")",
"handle_request",
"(",
"@file_format",
".",
"request",
"(",
"request_data",
")",
",",
"block",
")",
"else",
"@current_request",
"=",
"@file_format",
".",
"request",
"(",
"request_data",
")",
"end",
"else",
"if",
"@current_request",
"@current_request",
"<<",
"request_data",
"if",
"footer_line?",
"(",
"request_data",
")",
"handle_request",
"(",
"@current_request",
",",
"block",
")",
"# yield @current_request",
"@current_request",
"=",
"nil",
"end",
"else",
"@skipped_lines",
"+=",
"1",
"warn",
"(",
":no_current_request",
",",
"\"Parseable line (#{request_data[:line_definition].name.inspect}) found outside of a request!\"",
")",
"end",
"end",
"end"
] |
Combines the different lines of a request into a single Request object. It will start a
new request when a header line is encountered en will emit the request when a footer line
is encountered.
Combining the lines is done using heuristics. Problems can occur in this process. The
current parse strategy defines how these cases are handled.
When using the 'assume-correct' parse strategy (default):
- Every line that is parsed before a header line is ignored as it cannot be included in
any request. It will emit a :no_current_request warning.
- If a header line is found before the previous requests was closed, the previous request
will be yielded and a new request will be started.
When using the 'cautious' parse strategy:
- Every line that is parsed before a header line is ignored as it cannot be included in
any request. It will emit a :no_current_request warning.
- A header line that is parsed before a request is closed by a footer line, is a sign of
an unproperly ordered file. All data that is gathered for the request until then is
discarded and the next request is ignored as well. An :unclosed_request warning is
emitted.
<tt>request_data</tt>:: A hash of data that was parsed from the last line.
|
[
"Combines",
"the",
"different",
"lines",
"of",
"a",
"request",
"into",
"a",
"single",
"Request",
"object",
".",
"It",
"will",
"start",
"a",
"new",
"request",
"when",
"a",
"header",
"line",
"is",
"encountered",
"en",
"will",
"emit",
"the",
"request",
"when",
"a",
"footer",
"line",
"is",
"encountered",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/source/log_parser.rb#L285-L320
|
14,334
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/source/log_parser.rb
|
RequestLogAnalyzer::Source.LogParser.handle_request
|
def handle_request(request, &_block) # :yields: :request, request
@parsed_requests += 1
request.validate
accepted = block_given? ? yield(request) : true
@skipped_requests += 1 unless accepted
end
|
ruby
|
def handle_request(request, &_block) # :yields: :request, request
@parsed_requests += 1
request.validate
accepted = block_given? ? yield(request) : true
@skipped_requests += 1 unless accepted
end
|
[
"def",
"handle_request",
"(",
"request",
",",
"&",
"_block",
")",
"# :yields: :request, request",
"@parsed_requests",
"+=",
"1",
"request",
".",
"validate",
"accepted",
"=",
"block_given?",
"?",
"yield",
"(",
"request",
")",
":",
"true",
"@skipped_requests",
"+=",
"1",
"unless",
"accepted",
"end"
] |
Handles the parsed request by sending it into the pipeline.
- It will call RequestLogAnalyzer::Request#validate on the request instance
- It will send the request into the pipeline, checking whether it was accepted by all the filters.
- It will update the parsed_requests and skipped_requests variables accordingly
<tt>request</tt>:: The parsed request instance (RequestLogAnalyzer::Request)
|
[
"Handles",
"the",
"parsed",
"request",
"by",
"sending",
"it",
"into",
"the",
"pipeline",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/source/log_parser.rb#L329-L334
|
14,335
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/file_format.rb
|
RequestLogAnalyzer::FileFormat.CommonRegularExpressions.hostname_or_ip_address
|
def hostname_or_ip_address(blank = false)
regexp = Regexp.union(hostname, ip_address)
add_blank_option(regexp, blank)
end
|
ruby
|
def hostname_or_ip_address(blank = false)
regexp = Regexp.union(hostname, ip_address)
add_blank_option(regexp, blank)
end
|
[
"def",
"hostname_or_ip_address",
"(",
"blank",
"=",
"false",
")",
"regexp",
"=",
"Regexp",
".",
"union",
"(",
"hostname",
",",
"ip_address",
")",
"add_blank_option",
"(",
"regexp",
",",
"blank",
")",
"end"
] |
Creates a regular expression to match a hostname or ip address
|
[
"Creates",
"a",
"regular",
"expression",
"to",
"match",
"a",
"hostname",
"or",
"ip",
"address"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/file_format.rb#L134-L137
|
14,336
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/file_format.rb
|
RequestLogAnalyzer::FileFormat.CommonRegularExpressions.timestamp
|
def timestamp(format_string, blank = false)
regexp = ''
format_string.scan(/([^%]*)(?:%([A-Za-z%]))?/) do |literal, variable|
regexp << Regexp.quote(literal)
if variable
if TIMESTAMP_PARTS.key?(variable)
regexp << TIMESTAMP_PARTS[variable]
else
fail "Unknown variable: %#{variable}"
end
end
end
add_blank_option(Regexp.new(regexp), blank)
end
|
ruby
|
def timestamp(format_string, blank = false)
regexp = ''
format_string.scan(/([^%]*)(?:%([A-Za-z%]))?/) do |literal, variable|
regexp << Regexp.quote(literal)
if variable
if TIMESTAMP_PARTS.key?(variable)
regexp << TIMESTAMP_PARTS[variable]
else
fail "Unknown variable: %#{variable}"
end
end
end
add_blank_option(Regexp.new(regexp), blank)
end
|
[
"def",
"timestamp",
"(",
"format_string",
",",
"blank",
"=",
"false",
")",
"regexp",
"=",
"''",
"format_string",
".",
"scan",
"(",
"/",
"/",
")",
"do",
"|",
"literal",
",",
"variable",
"|",
"regexp",
"<<",
"Regexp",
".",
"quote",
"(",
"literal",
")",
"if",
"variable",
"if",
"TIMESTAMP_PARTS",
".",
"key?",
"(",
"variable",
")",
"regexp",
"<<",
"TIMESTAMP_PARTS",
"[",
"variable",
"]",
"else",
"fail",
"\"Unknown variable: %#{variable}\"",
"end",
"end",
"end",
"add_blank_option",
"(",
"Regexp",
".",
"new",
"(",
"regexp",
")",
",",
"blank",
")",
"end"
] |
Create a regular expression for a timestamp, generated by a strftime call.
Provide the format string to construct a matching regular expression.
Set blank to true to allow and empty string, or set blank to a string to set
a substitute for the nil value.
|
[
"Create",
"a",
"regular",
"expression",
"for",
"a",
"timestamp",
"generated",
"by",
"a",
"strftime",
"call",
".",
"Provide",
"the",
"format",
"string",
"to",
"construct",
"a",
"matching",
"regular",
"expression",
".",
"Set",
"blank",
"to",
"true",
"to",
"allow",
"and",
"empty",
"string",
"or",
"set",
"blank",
"to",
"a",
"string",
"to",
"set",
"a",
"substitute",
"for",
"the",
"nil",
"value",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/file_format.rb#L143-L157
|
14,337
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/file_format.rb
|
RequestLogAnalyzer::FileFormat.CommonRegularExpressions.add_blank_option
|
def add_blank_option(regexp, blank)
case blank
when String then Regexp.union(regexp, Regexp.new(Regexp.quote(blank)))
when true then Regexp.union(regexp, //)
else regexp
end
end
|
ruby
|
def add_blank_option(regexp, blank)
case blank
when String then Regexp.union(regexp, Regexp.new(Regexp.quote(blank)))
when true then Regexp.union(regexp, //)
else regexp
end
end
|
[
"def",
"add_blank_option",
"(",
"regexp",
",",
"blank",
")",
"case",
"blank",
"when",
"String",
"then",
"Regexp",
".",
"union",
"(",
"regexp",
",",
"Regexp",
".",
"new",
"(",
"Regexp",
".",
"quote",
"(",
"blank",
")",
")",
")",
"when",
"true",
"then",
"Regexp",
".",
"union",
"(",
"regexp",
",",
"/",
"/",
")",
"else",
"regexp",
"end",
"end"
] |
Allow the field to be blank if this option is given. This can be true to
allow an empty string or a string alternative for the nil value.
|
[
"Allow",
"the",
"field",
"to",
"be",
"blank",
"if",
"this",
"option",
"is",
"given",
".",
"This",
"can",
"be",
"true",
"to",
"allow",
"an",
"empty",
"string",
"or",
"a",
"string",
"alternative",
"for",
"the",
"nil",
"value",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/file_format.rb#L184-L190
|
14,338
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/file_format.rb
|
RequestLogAnalyzer::FileFormat.Base.valid_line_definitions?
|
def valid_line_definitions?
line_definitions.any? { |(_, ld)| ld.header } && line_definitions.any? { |(_, ld)| ld.footer }
end
|
ruby
|
def valid_line_definitions?
line_definitions.any? { |(_, ld)| ld.header } && line_definitions.any? { |(_, ld)| ld.footer }
end
|
[
"def",
"valid_line_definitions?",
"line_definitions",
".",
"any?",
"{",
"|",
"(",
"_",
",",
"ld",
")",
"|",
"ld",
".",
"header",
"}",
"&&",
"line_definitions",
".",
"any?",
"{",
"|",
"(",
"_",
",",
"ld",
")",
"|",
"ld",
".",
"footer",
"}",
"end"
] |
Checks whether the line definitions form a valid language.
A file format should have at least a header and a footer line type
|
[
"Checks",
"whether",
"the",
"line",
"definitions",
"form",
"a",
"valid",
"language",
".",
"A",
"file",
"format",
"should",
"have",
"at",
"least",
"a",
"header",
"and",
"a",
"footer",
"line",
"type"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/file_format.rb#L277-L279
|
14,339
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/file_format.rb
|
RequestLogAnalyzer::FileFormat.Base.parse_line
|
def parse_line(line, &warning_handler)
line_definitions.each do |_lt, definition|
match = definition.matches(line, &warning_handler)
return match if match
end
nil
end
|
ruby
|
def parse_line(line, &warning_handler)
line_definitions.each do |_lt, definition|
match = definition.matches(line, &warning_handler)
return match if match
end
nil
end
|
[
"def",
"parse_line",
"(",
"line",
",",
"&",
"warning_handler",
")",
"line_definitions",
".",
"each",
"do",
"|",
"_lt",
",",
"definition",
"|",
"match",
"=",
"definition",
".",
"matches",
"(",
"line",
",",
"warning_handler",
")",
"return",
"match",
"if",
"match",
"end",
"nil",
"end"
] |
Parses a line by trying to parse it using every line definition in this file format
|
[
"Parses",
"a",
"line",
"by",
"trying",
"to",
"parse",
"it",
"using",
"every",
"line",
"definition",
"in",
"this",
"file",
"format"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/file_format.rb#L297-L304
|
14,340
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/aggregator/summarizer.rb
|
RequestLogAnalyzer::Aggregator.Summarizer.to_yaml
|
def to_yaml
require 'yaml'
trackers_export = @trackers.reduce({}) do |export, tracker|
export[tracker.title] = tracker.to_yaml_object; export
end
YAML.dump(trackers_export)
end
|
ruby
|
def to_yaml
require 'yaml'
trackers_export = @trackers.reduce({}) do |export, tracker|
export[tracker.title] = tracker.to_yaml_object; export
end
YAML.dump(trackers_export)
end
|
[
"def",
"to_yaml",
"require",
"'yaml'",
"trackers_export",
"=",
"@trackers",
".",
"reduce",
"(",
"{",
"}",
")",
"do",
"|",
"export",
",",
"tracker",
"|",
"export",
"[",
"tracker",
".",
"title",
"]",
"=",
"tracker",
".",
"to_yaml_object",
";",
"export",
"end",
"YAML",
".",
"dump",
"(",
"trackers_export",
")",
"end"
] |
Exports all the tracker results to YAML. It will call the to_yaml_object method
for every tracker and combines these into a single YAML export.
|
[
"Exports",
"all",
"the",
"tracker",
"results",
"to",
"YAML",
".",
"It",
"will",
"call",
"the",
"to_yaml_object",
"method",
"for",
"every",
"tracker",
"and",
"combines",
"these",
"into",
"a",
"single",
"YAML",
"export",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/aggregator/summarizer.rb#L80-L86
|
14,341
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/frequency.rb
|
RequestLogAnalyzer::Tracker.Frequency.prepare
|
def prepare
options[:category] = options[:value] if options[:value] && !options[:category]
fail "No categorizer set up for category tracker #{inspect}" unless options[:category]
@categorizer = create_lambda(options[:category]) unless options[:multiple]
# Initialize the categories. Use the list of category names to
@categories = {}
options[:all_categories].each { |cat| @categories[cat] = 0 } if options[:all_categories].is_a?(Enumerable)
end
|
ruby
|
def prepare
options[:category] = options[:value] if options[:value] && !options[:category]
fail "No categorizer set up for category tracker #{inspect}" unless options[:category]
@categorizer = create_lambda(options[:category]) unless options[:multiple]
# Initialize the categories. Use the list of category names to
@categories = {}
options[:all_categories].each { |cat| @categories[cat] = 0 } if options[:all_categories].is_a?(Enumerable)
end
|
[
"def",
"prepare",
"options",
"[",
":category",
"]",
"=",
"options",
"[",
":value",
"]",
"if",
"options",
"[",
":value",
"]",
"&&",
"!",
"options",
"[",
":category",
"]",
"fail",
"\"No categorizer set up for category tracker #{inspect}\"",
"unless",
"options",
"[",
":category",
"]",
"@categorizer",
"=",
"create_lambda",
"(",
"options",
"[",
":category",
"]",
")",
"unless",
"options",
"[",
":multiple",
"]",
"# Initialize the categories. Use the list of category names to",
"@categories",
"=",
"{",
"}",
"options",
"[",
":all_categories",
"]",
".",
"each",
"{",
"|",
"cat",
"|",
"@categories",
"[",
"cat",
"]",
"=",
"0",
"}",
"if",
"options",
"[",
":all_categories",
"]",
".",
"is_a?",
"(",
"Enumerable",
")",
"end"
] |
Check if categories are set up
|
[
"Check",
"if",
"categories",
"are",
"set",
"up"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/frequency.rb#L26-L35
|
14,342
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker.rb
|
RequestLogAnalyzer::Tracker.Base.setup_should_update_checks!
|
def setup_should_update_checks!
@should_update_checks = []
@should_update_checks.push(lambda { |request| request.has_line_type?(options[:line_type]) }) if options[:line_type]
@should_update_checks.push(options[:if]) if options[:if].respond_to?(:call)
@should_update_checks.push(lambda { |request| request[options[:if]] }) if options[:if].is_a?(Symbol)
@should_update_checks.push(lambda { |request| !options[:unless].call(request) }) if options[:unless].respond_to?(:call)
@should_update_checks.push(lambda { |request| !request[options[:unless]] }) if options[:unless].is_a?(Symbol)
end
|
ruby
|
def setup_should_update_checks!
@should_update_checks = []
@should_update_checks.push(lambda { |request| request.has_line_type?(options[:line_type]) }) if options[:line_type]
@should_update_checks.push(options[:if]) if options[:if].respond_to?(:call)
@should_update_checks.push(lambda { |request| request[options[:if]] }) if options[:if].is_a?(Symbol)
@should_update_checks.push(lambda { |request| !options[:unless].call(request) }) if options[:unless].respond_to?(:call)
@should_update_checks.push(lambda { |request| !request[options[:unless]] }) if options[:unless].is_a?(Symbol)
end
|
[
"def",
"setup_should_update_checks!",
"@should_update_checks",
"=",
"[",
"]",
"@should_update_checks",
".",
"push",
"(",
"lambda",
"{",
"|",
"request",
"|",
"request",
".",
"has_line_type?",
"(",
"options",
"[",
":line_type",
"]",
")",
"}",
")",
"if",
"options",
"[",
":line_type",
"]",
"@should_update_checks",
".",
"push",
"(",
"options",
"[",
":if",
"]",
")",
"if",
"options",
"[",
":if",
"]",
".",
"respond_to?",
"(",
":call",
")",
"@should_update_checks",
".",
"push",
"(",
"lambda",
"{",
"|",
"request",
"|",
"request",
"[",
"options",
"[",
":if",
"]",
"]",
"}",
")",
"if",
"options",
"[",
":if",
"]",
".",
"is_a?",
"(",
"Symbol",
")",
"@should_update_checks",
".",
"push",
"(",
"lambda",
"{",
"|",
"request",
"|",
"!",
"options",
"[",
":unless",
"]",
".",
"call",
"(",
"request",
")",
"}",
")",
"if",
"options",
"[",
":unless",
"]",
".",
"respond_to?",
"(",
":call",
")",
"@should_update_checks",
".",
"push",
"(",
"lambda",
"{",
"|",
"request",
"|",
"!",
"request",
"[",
"options",
"[",
":unless",
"]",
"]",
"}",
")",
"if",
"options",
"[",
":unless",
"]",
".",
"is_a?",
"(",
"Symbol",
")",
"end"
] |
Initialize the class
Note that the options are only applicable if should_update? is not overwritten
by the inheriting class.
=== Options
* <tt>:if</tt> Handle request if this proc is true for the handled request.
* <tt>:unless</tt> Handle request if this proc is false for the handled request.
* <tt>:line_type</tt> Line type this tracker will accept.
Sets up the tracker's should_update? checks.
|
[
"Initialize",
"the",
"class",
"Note",
"that",
"the",
"options",
"are",
"only",
"applicable",
"if",
"should_update?",
"is",
"not",
"overwritten",
"by",
"the",
"inheriting",
"class",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker.rb#L28-L35
|
14,343
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker.rb
|
RequestLogAnalyzer::Tracker.Base.create_lambda
|
def create_lambda(arg)
case arg
when Proc then arg
when Symbol then lambda { |request| request[arg] }
else fail "Canot create a lambda expression from this argument: #{arg.inspect}!"
end
end
|
ruby
|
def create_lambda(arg)
case arg
when Proc then arg
when Symbol then lambda { |request| request[arg] }
else fail "Canot create a lambda expression from this argument: #{arg.inspect}!"
end
end
|
[
"def",
"create_lambda",
"(",
"arg",
")",
"case",
"arg",
"when",
"Proc",
"then",
"arg",
"when",
"Symbol",
"then",
"lambda",
"{",
"|",
"request",
"|",
"request",
"[",
"arg",
"]",
"}",
"else",
"fail",
"\"Canot create a lambda expression from this argument: #{arg.inspect}!\"",
"end",
"end"
] |
Creates a lambda expression to return a static field from a request. If the
argument already is a lambda exprssion, it will simply return the argument.
|
[
"Creates",
"a",
"lambda",
"expression",
"to",
"return",
"a",
"static",
"field",
"from",
"a",
"request",
".",
"If",
"the",
"argument",
"already",
"is",
"a",
"lambda",
"exprssion",
"it",
"will",
"simply",
"return",
"the",
"argument",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker.rb#L39-L45
|
14,344
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/line_definition.rb
|
RequestLogAnalyzer.LineDefinition.match_for
|
def match_for(line, request, &warning_handler)
if match_info = matches(line, &warning_handler)
convert_captured_values(match_info[:captures], request)
else
false
end
end
|
ruby
|
def match_for(line, request, &warning_handler)
if match_info = matches(line, &warning_handler)
convert_captured_values(match_info[:captures], request)
else
false
end
end
|
[
"def",
"match_for",
"(",
"line",
",",
"request",
",",
"&",
"warning_handler",
")",
"if",
"match_info",
"=",
"matches",
"(",
"line",
",",
"warning_handler",
")",
"convert_captured_values",
"(",
"match_info",
"[",
":captures",
"]",
",",
"request",
")",
"else",
"false",
"end",
"end"
] |
matches the line and converts the captured values using the request's
convert_value function.
|
[
"matches",
"the",
"line",
"and",
"converts",
"the",
"captured",
"values",
"using",
"the",
"request",
"s",
"convert_value",
"function",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/line_definition.rb#L104-L110
|
14,345
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/request.rb
|
RequestLogAnalyzer.Request.add_parsed_line
|
def add_parsed_line(parsed_line)
value_hash = parsed_line[:line_definition].convert_captured_values(parsed_line[:captures], self)
value_hash[:line_type] = parsed_line[:line_definition].name
value_hash[:lineno] = parsed_line[:lineno]
value_hash[:source] = parsed_line[:source]
value_hash[:compound] = parsed_line[:line_definition].compound
add_line_hash(value_hash)
end
|
ruby
|
def add_parsed_line(parsed_line)
value_hash = parsed_line[:line_definition].convert_captured_values(parsed_line[:captures], self)
value_hash[:line_type] = parsed_line[:line_definition].name
value_hash[:lineno] = parsed_line[:lineno]
value_hash[:source] = parsed_line[:source]
value_hash[:compound] = parsed_line[:line_definition].compound
add_line_hash(value_hash)
end
|
[
"def",
"add_parsed_line",
"(",
"parsed_line",
")",
"value_hash",
"=",
"parsed_line",
"[",
":line_definition",
"]",
".",
"convert_captured_values",
"(",
"parsed_line",
"[",
":captures",
"]",
",",
"self",
")",
"value_hash",
"[",
":line_type",
"]",
"=",
"parsed_line",
"[",
":line_definition",
"]",
".",
"name",
"value_hash",
"[",
":lineno",
"]",
"=",
"parsed_line",
"[",
":lineno",
"]",
"value_hash",
"[",
":source",
"]",
"=",
"parsed_line",
"[",
":source",
"]",
"value_hash",
"[",
":compound",
"]",
"=",
"parsed_line",
"[",
":line_definition",
"]",
".",
"compound",
"add_line_hash",
"(",
"value_hash",
")",
"end"
] |
Adds another line to the request when it is parsed in the LogParser.
The line should be provided as a hash with the attributes line_definition, :captures,
:lineno and :source set. This function is called from LogParser.
|
[
"Adds",
"another",
"line",
"to",
"the",
"request",
"when",
"it",
"is",
"parsed",
"in",
"the",
"LogParser",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/request.rb#L133-L140
|
14,346
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/request.rb
|
RequestLogAnalyzer.Request.add_line_hash
|
def add_line_hash(value_hash)
@lines << value_hash
if value_hash[:compound]
value_hash.each do |key, value|
if value_hash[:compound].include?(key)
@attributes[key] = [] if @attributes[key].nil?
@attributes[key] = [@attributes[key]] unless @attributes[key].is_a?(Array)
@attributes[key] << value
else
@attributes[key] = value unless key == :compound || @attributes[key]
end
end
else
@attributes = value_hash.merge(@attributes)
end
end
|
ruby
|
def add_line_hash(value_hash)
@lines << value_hash
if value_hash[:compound]
value_hash.each do |key, value|
if value_hash[:compound].include?(key)
@attributes[key] = [] if @attributes[key].nil?
@attributes[key] = [@attributes[key]] unless @attributes[key].is_a?(Array)
@attributes[key] << value
else
@attributes[key] = value unless key == :compound || @attributes[key]
end
end
else
@attributes = value_hash.merge(@attributes)
end
end
|
[
"def",
"add_line_hash",
"(",
"value_hash",
")",
"@lines",
"<<",
"value_hash",
"if",
"value_hash",
"[",
":compound",
"]",
"value_hash",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"if",
"value_hash",
"[",
":compound",
"]",
".",
"include?",
"(",
"key",
")",
"@attributes",
"[",
"key",
"]",
"=",
"[",
"]",
"if",
"@attributes",
"[",
"key",
"]",
".",
"nil?",
"@attributes",
"[",
"key",
"]",
"=",
"[",
"@attributes",
"[",
"key",
"]",
"]",
"unless",
"@attributes",
"[",
"key",
"]",
".",
"is_a?",
"(",
"Array",
")",
"@attributes",
"[",
"key",
"]",
"<<",
"value",
"else",
"@attributes",
"[",
"key",
"]",
"=",
"value",
"unless",
"key",
"==",
":compound",
"||",
"@attributes",
"[",
"key",
"]",
"end",
"end",
"else",
"@attributes",
"=",
"value_hash",
".",
"merge",
"(",
"@attributes",
")",
"end",
"end"
] |
Adds another line to the request using a plain hash.
The line should be provides as a hash of the fields parsed from the line.
|
[
"Adds",
"another",
"line",
"to",
"the",
"request",
"using",
"a",
"plain",
"hash",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/request.rb#L145-L160
|
14,347
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/request.rb
|
RequestLogAnalyzer.Request.has_line_type?
|
def has_line_type?(line_type)
return true if @lines.length == 1 && @lines[0][:line_type] == line_type.to_sym
@lines.find { |l| l[:line_type] == line_type.to_sym }
end
|
ruby
|
def has_line_type?(line_type)
return true if @lines.length == 1 && @lines[0][:line_type] == line_type.to_sym
@lines.find { |l| l[:line_type] == line_type.to_sym }
end
|
[
"def",
"has_line_type?",
"(",
"line_type",
")",
"return",
"true",
"if",
"@lines",
".",
"length",
"==",
"1",
"&&",
"@lines",
"[",
"0",
"]",
"[",
":line_type",
"]",
"==",
"line_type",
".",
"to_sym",
"@lines",
".",
"find",
"{",
"|",
"l",
"|",
"l",
"[",
":line_type",
"]",
"==",
"line_type",
".",
"to_sym",
"}",
"end"
] |
Checks whether the given line type was parsed from the log file for this request
|
[
"Checks",
"whether",
"the",
"given",
"line",
"type",
"was",
"parsed",
"from",
"the",
"log",
"file",
"for",
"this",
"request"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/request.rb#L169-L172
|
14,348
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/request.rb
|
RequestLogAnalyzer.Request.every
|
def every(field)
@lines.reduce([]) { |result, fields| result << fields[field] if fields.key?(field); result }
end
|
ruby
|
def every(field)
@lines.reduce([]) { |result, fields| result << fields[field] if fields.key?(field); result }
end
|
[
"def",
"every",
"(",
"field",
")",
"@lines",
".",
"reduce",
"(",
"[",
"]",
")",
"{",
"|",
"result",
",",
"fields",
"|",
"result",
"<<",
"fields",
"[",
"field",
"]",
"if",
"fields",
".",
"key?",
"(",
"field",
")",
";",
"result",
"}",
"end"
] |
Returns an array of all the "field" values that were captured for this request
|
[
"Returns",
"an",
"array",
"of",
"all",
"the",
"field",
"values",
"that",
"were",
"captured",
"for",
"this",
"request"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/request.rb#L186-L188
|
14,349
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/request.rb
|
RequestLogAnalyzer.Request.completed?
|
def completed?
header_found, footer_found = false, false
@lines.each do |line|
line_def = file_format.line_definitions[line[:line_type]]
header_found = true if line_def.header
footer_found = true if line_def.footer
end
header_found && footer_found
end
|
ruby
|
def completed?
header_found, footer_found = false, false
@lines.each do |line|
line_def = file_format.line_definitions[line[:line_type]]
header_found = true if line_def.header
footer_found = true if line_def.footer
end
header_found && footer_found
end
|
[
"def",
"completed?",
"header_found",
",",
"footer_found",
"=",
"false",
",",
"false",
"@lines",
".",
"each",
"do",
"|",
"line",
"|",
"line_def",
"=",
"file_format",
".",
"line_definitions",
"[",
"line",
"[",
":line_type",
"]",
"]",
"header_found",
"=",
"true",
"if",
"line_def",
".",
"header",
"footer_found",
"=",
"true",
"if",
"line_def",
".",
"footer",
"end",
"header_found",
"&&",
"footer_found",
"end"
] |
Checks whether this request is completed. A completed request contains both a parsed header
line and a parsed footer line. Not that calling this function in single line mode will always
return false.
|
[
"Checks",
"whether",
"this",
"request",
"is",
"completed",
".",
"A",
"completed",
"request",
"contains",
"both",
"a",
"parsed",
"header",
"line",
"and",
"a",
"parsed",
"footer",
"line",
".",
"Not",
"that",
"calling",
"this",
"function",
"in",
"single",
"line",
"mode",
"will",
"always",
"return",
"false",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/request.rb#L199-L207
|
14,350
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/traffic.rb
|
RequestLogAnalyzer::Tracker.Traffic.prepare
|
def prepare
options[:value] = options[:traffic] if options[:traffic]
options[:total] = true
super
@number_of_buckets = options[:number_of_buckets] || 1000
@min_bucket_value = options[:min_bucket_value] ? options[:min_bucket_value].to_f : 1
@max_bucket_value = options[:max_bucket_value] ? options[:max_bucket_value].to_f : 1_000_000_000_000
# precalculate the bucket size
@bucket_size = (Math.log(@max_bucket_value) - Math.log(@min_bucket_value)) / @number_of_buckets.to_f
end
|
ruby
|
def prepare
options[:value] = options[:traffic] if options[:traffic]
options[:total] = true
super
@number_of_buckets = options[:number_of_buckets] || 1000
@min_bucket_value = options[:min_bucket_value] ? options[:min_bucket_value].to_f : 1
@max_bucket_value = options[:max_bucket_value] ? options[:max_bucket_value].to_f : 1_000_000_000_000
# precalculate the bucket size
@bucket_size = (Math.log(@max_bucket_value) - Math.log(@min_bucket_value)) / @number_of_buckets.to_f
end
|
[
"def",
"prepare",
"options",
"[",
":value",
"]",
"=",
"options",
"[",
":traffic",
"]",
"if",
"options",
"[",
":traffic",
"]",
"options",
"[",
":total",
"]",
"=",
"true",
"super",
"@number_of_buckets",
"=",
"options",
"[",
":number_of_buckets",
"]",
"||",
"1000",
"@min_bucket_value",
"=",
"options",
"[",
":min_bucket_value",
"]",
"?",
"options",
"[",
":min_bucket_value",
"]",
".",
"to_f",
":",
"1",
"@max_bucket_value",
"=",
"options",
"[",
":max_bucket_value",
"]",
"?",
"options",
"[",
":max_bucket_value",
"]",
".",
"to_f",
":",
"1_000_000_000_000",
"# precalculate the bucket size",
"@bucket_size",
"=",
"(",
"Math",
".",
"log",
"(",
"@max_bucket_value",
")",
"-",
"Math",
".",
"log",
"(",
"@min_bucket_value",
")",
")",
"/",
"@number_of_buckets",
".",
"to_f",
"end"
] |
Check if duration and catagory option have been received,
|
[
"Check",
"if",
"duration",
"and",
"catagory",
"option",
"have",
"been",
"received"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/traffic.rb#L13-L24
|
14,351
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/filter/field.rb
|
RequestLogAnalyzer::Filter.Field.filter
|
def filter(request)
found_field = request.every(@field).any? { |value| @value === value.to_s }
return nil if !found_field && @mode == :select
return nil if found_field && @mode == :reject
request
end
|
ruby
|
def filter(request)
found_field = request.every(@field).any? { |value| @value === value.to_s }
return nil if !found_field && @mode == :select
return nil if found_field && @mode == :reject
request
end
|
[
"def",
"filter",
"(",
"request",
")",
"found_field",
"=",
"request",
".",
"every",
"(",
"@field",
")",
".",
"any?",
"{",
"|",
"value",
"|",
"@value",
"===",
"value",
".",
"to_s",
"}",
"return",
"nil",
"if",
"!",
"found_field",
"&&",
"@mode",
"==",
":select",
"return",
"nil",
"if",
"found_field",
"&&",
"@mode",
"==",
":reject",
"request",
"end"
] |
Keep request if @mode == :select and request has the field and value.
Drop request if @mode == :reject and request has the field and value.
Returns nil otherwise.
<tt>request</tt> Request Object
|
[
"Keep",
"request",
"if"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/filter/field.rb#L32-L37
|
14,352
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/output/html.rb
|
RequestLogAnalyzer::Output.HTML.header
|
def header
@io.content_type = content_type if @io.respond_to?(:content_type)
@io << '<html>'
@io << tag(:head) do |headers|
headers << tag(:title, 'Request-log-analyzer report')
headers << tag(:style, '
body {
font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
background: #E6EAE9;
padding-left:20px;
padding-top:20px;
padding-bottom:20px;
}
a {
color: #c75f3e;
}
.color_bar {
border: 1px solid;
height:10px;
background: #CAE8EA;
}
.rla-report-table {
width: 700px;
padding: 0;
margin: 0;
padding-bottom:10px;
}
caption {
padding: 0 0 5px 0;
width: 700px;
font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
text-align: right;
}
th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(images/bg_header.jpg) no-repeat;
}
td {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
td.alt {
background: #F5FAFA;
color: #797268;
}
', type: 'text/css')
end
@io << '<body>'
@io << tag(:h1, 'Request-log-analyzer summary report')
@io << tag(:p, "Version #{RequestLogAnalyzer::VERSION} - written by Willem van Bergen and Bart ten Brinke")
end
|
ruby
|
def header
@io.content_type = content_type if @io.respond_to?(:content_type)
@io << '<html>'
@io << tag(:head) do |headers|
headers << tag(:title, 'Request-log-analyzer report')
headers << tag(:style, '
body {
font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
background: #E6EAE9;
padding-left:20px;
padding-top:20px;
padding-bottom:20px;
}
a {
color: #c75f3e;
}
.color_bar {
border: 1px solid;
height:10px;
background: #CAE8EA;
}
.rla-report-table {
width: 700px;
padding: 0;
margin: 0;
padding-bottom:10px;
}
caption {
padding: 0 0 5px 0;
width: 700px;
font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
text-align: right;
}
th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(images/bg_header.jpg) no-repeat;
}
td {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
td.alt {
background: #F5FAFA;
color: #797268;
}
', type: 'text/css')
end
@io << '<body>'
@io << tag(:h1, 'Request-log-analyzer summary report')
@io << tag(:p, "Version #{RequestLogAnalyzer::VERSION} - written by Willem van Bergen and Bart ten Brinke")
end
|
[
"def",
"header",
"@io",
".",
"content_type",
"=",
"content_type",
"if",
"@io",
".",
"respond_to?",
"(",
":content_type",
")",
"@io",
"<<",
"'<html>'",
"@io",
"<<",
"tag",
"(",
":head",
")",
"do",
"|",
"headers",
"|",
"headers",
"<<",
"tag",
"(",
":title",
",",
"'Request-log-analyzer report'",
")",
"headers",
"<<",
"tag",
"(",
":style",
",",
"'\n body {\n \tfont: normal 11px auto \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;\n \tcolor: #4f6b72;\n \tbackground: #E6EAE9;\n \tpadding-left:20px;\n \tpadding-top:20px;\n \tpadding-bottom:20px;\n }\n\n a {\n \tcolor: #c75f3e;\n }\n\n .color_bar {\n border: 1px solid;\n height:10px;\n \tbackground: #CAE8EA;\n }\n\n .rla-report-table {\n \twidth: 700px;\n \tpadding: 0;\n \tmargin: 0;\n \tpadding-bottom:10px;\n }\n\n caption {\n \tpadding: 0 0 5px 0;\n \twidth: 700px;\n \tfont: italic 11px \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;\n \ttext-align: right;\n }\n\n th {\n \tfont: bold 11px \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;\n \tcolor: #4f6b72;\n \tborder-right: 1px solid #C1DAD7;\n \tborder-bottom: 1px solid #C1DAD7;\n \tborder-top: 1px solid #C1DAD7;\n \tletter-spacing: 2px;\n \ttext-transform: uppercase;\n \ttext-align: left;\n \tpadding: 6px 6px 6px 12px;\n \tbackground: #CAE8EA url(images/bg_header.jpg) no-repeat;\n }\n\n td {\n \tfont: bold 11px \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;\n \tborder-right: 1px solid #C1DAD7;\n \tborder-bottom: 1px solid #C1DAD7;\n \tbackground: #fff;\n \tpadding: 6px 6px 6px 12px;\n \tcolor: #4f6b72;\n }\n\n td.alt {\n \tbackground: #F5FAFA;\n \tcolor: #797268;\n }\n '",
",",
"type",
":",
"'text/css'",
")",
"end",
"@io",
"<<",
"'<body>'",
"@io",
"<<",
"tag",
"(",
":h1",
",",
"'Request-log-analyzer summary report'",
")",
"@io",
"<<",
"tag",
"(",
":p",
",",
"\"Version #{RequestLogAnalyzer::VERSION} - written by Willem van Bergen and Bart ten Brinke\"",
")",
"end"
] |
Genrate HTML header and associated stylesheet
|
[
"Genrate",
"HTML",
"header",
"and",
"associated",
"stylesheet"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/output/html.rb#L76-L147
|
14,353
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/controller.rb
|
RequestLogAnalyzer.Controller.handle_source_change
|
def handle_source_change(change, filename)
@aggregators.each { |agg| agg.source_change(change, File.expand_path(filename, Dir.pwd)) }
end
|
ruby
|
def handle_source_change(change, filename)
@aggregators.each { |agg| agg.source_change(change, File.expand_path(filename, Dir.pwd)) }
end
|
[
"def",
"handle_source_change",
"(",
"change",
",",
"filename",
")",
"@aggregators",
".",
"each",
"{",
"|",
"agg",
"|",
"agg",
".",
"source_change",
"(",
"change",
",",
"File",
".",
"expand_path",
"(",
"filename",
",",
"Dir",
".",
"pwd",
")",
")",
"}",
"end"
] |
Source change handler
|
[
"Source",
"change",
"handler"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/controller.rb#L282-L284
|
14,354
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/controller.rb
|
RequestLogAnalyzer.Controller.add_filter
|
def add_filter(filter, filter_options = {})
filter = RequestLogAnalyzer::Filter.const_get(RequestLogAnalyzer.to_camelcase(filter)) if filter.is_a?(Symbol)
@filters << filter.new(source.file_format, @options.merge(filter_options))
end
|
ruby
|
def add_filter(filter, filter_options = {})
filter = RequestLogAnalyzer::Filter.const_get(RequestLogAnalyzer.to_camelcase(filter)) if filter.is_a?(Symbol)
@filters << filter.new(source.file_format, @options.merge(filter_options))
end
|
[
"def",
"add_filter",
"(",
"filter",
",",
"filter_options",
"=",
"{",
"}",
")",
"filter",
"=",
"RequestLogAnalyzer",
"::",
"Filter",
".",
"const_get",
"(",
"RequestLogAnalyzer",
".",
"to_camelcase",
"(",
"filter",
")",
")",
"if",
"filter",
".",
"is_a?",
"(",
"Symbol",
")",
"@filters",
"<<",
"filter",
".",
"new",
"(",
"source",
".",
"file_format",
",",
"@options",
".",
"merge",
"(",
"filter_options",
")",
")",
"end"
] |
Adds a request filter to the controller.
|
[
"Adds",
"a",
"request",
"filter",
"to",
"the",
"controller",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/controller.rb#L296-L299
|
14,355
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/controller.rb
|
RequestLogAnalyzer.Controller.filter_request
|
def filter_request(request)
@filters.each do |filter|
request = filter.filter(request)
return nil if request.nil?
end
request
end
|
ruby
|
def filter_request(request)
@filters.each do |filter|
request = filter.filter(request)
return nil if request.nil?
end
request
end
|
[
"def",
"filter_request",
"(",
"request",
")",
"@filters",
".",
"each",
"do",
"|",
"filter",
"|",
"request",
"=",
"filter",
".",
"filter",
"(",
"request",
")",
"return",
"nil",
"if",
"request",
".",
"nil?",
"end",
"request",
"end"
] |
Push a request through the entire filterchain (@filters).
<tt>request</tt> The request to filter.
Returns the filtered request or nil.
|
[
"Push",
"a",
"request",
"through",
"the",
"entire",
"filterchain",
"("
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/controller.rb#L304-L310
|
14,356
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/controller.rb
|
RequestLogAnalyzer.Controller.aggregate_request
|
def aggregate_request(request)
return false unless request
@aggregators.each { |agg| agg.aggregate(request) }
true
end
|
ruby
|
def aggregate_request(request)
return false unless request
@aggregators.each { |agg| agg.aggregate(request) }
true
end
|
[
"def",
"aggregate_request",
"(",
"request",
")",
"return",
"false",
"unless",
"request",
"@aggregators",
".",
"each",
"{",
"|",
"agg",
"|",
"agg",
".",
"aggregate",
"(",
"request",
")",
"}",
"true",
"end"
] |
Push a request to all the aggregators (@aggregators).
<tt>request</tt> The request to push to the aggregators.
|
[
"Push",
"a",
"request",
"to",
"all",
"the",
"aggregators",
"("
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/controller.rb#L314-L318
|
14,357
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/controller.rb
|
RequestLogAnalyzer.Controller.run!
|
def run!
# @aggregators.each{|agg| p agg}
@aggregators.each { |agg| agg.prepare }
install_signal_handlers
@source.each_request do |request|
break if @interrupted
aggregate_request(filter_request(request))
end
@aggregators.each { |agg| agg.finalize }
@output.header
@aggregators.each { |agg| agg.report(@output) }
@output.footer
@source.finalize
if @output.io.is_a?(File)
unless @options[:silent]
puts
puts 'Report written to: ' + File.expand_path(@output.io.path)
puts 'Need an expert to analyze your application?'
puts 'Mail to contact@railsdoctors.com or visit us at http://railsdoctors.com'
puts 'Thanks for using request-log-analyzer!'
end
@output.io.close
elsif @output.io.is_a?(RequestLogAnalyzer::Mailer)
@output.io.mail
end
end
|
ruby
|
def run!
# @aggregators.each{|agg| p agg}
@aggregators.each { |agg| agg.prepare }
install_signal_handlers
@source.each_request do |request|
break if @interrupted
aggregate_request(filter_request(request))
end
@aggregators.each { |agg| agg.finalize }
@output.header
@aggregators.each { |agg| agg.report(@output) }
@output.footer
@source.finalize
if @output.io.is_a?(File)
unless @options[:silent]
puts
puts 'Report written to: ' + File.expand_path(@output.io.path)
puts 'Need an expert to analyze your application?'
puts 'Mail to contact@railsdoctors.com or visit us at http://railsdoctors.com'
puts 'Thanks for using request-log-analyzer!'
end
@output.io.close
elsif @output.io.is_a?(RequestLogAnalyzer::Mailer)
@output.io.mail
end
end
|
[
"def",
"run!",
"# @aggregators.each{|agg| p agg}",
"@aggregators",
".",
"each",
"{",
"|",
"agg",
"|",
"agg",
".",
"prepare",
"}",
"install_signal_handlers",
"@source",
".",
"each_request",
"do",
"|",
"request",
"|",
"break",
"if",
"@interrupted",
"aggregate_request",
"(",
"filter_request",
"(",
"request",
")",
")",
"end",
"@aggregators",
".",
"each",
"{",
"|",
"agg",
"|",
"agg",
".",
"finalize",
"}",
"@output",
".",
"header",
"@aggregators",
".",
"each",
"{",
"|",
"agg",
"|",
"agg",
".",
"report",
"(",
"@output",
")",
"}",
"@output",
".",
"footer",
"@source",
".",
"finalize",
"if",
"@output",
".",
"io",
".",
"is_a?",
"(",
"File",
")",
"unless",
"@options",
"[",
":silent",
"]",
"puts",
"puts",
"'Report written to: '",
"+",
"File",
".",
"expand_path",
"(",
"@output",
".",
"io",
".",
"path",
")",
"puts",
"'Need an expert to analyze your application?'",
"puts",
"'Mail to contact@railsdoctors.com or visit us at http://railsdoctors.com'",
"puts",
"'Thanks for using request-log-analyzer!'",
"end",
"@output",
".",
"io",
".",
"close",
"elsif",
"@output",
".",
"io",
".",
"is_a?",
"(",
"RequestLogAnalyzer",
"::",
"Mailer",
")",
"@output",
".",
"io",
".",
"mail",
"end",
"end"
] |
Runs RequestLogAnalyzer
1. Call prepare on every aggregator
2. Generate requests from source object
3. Filter out unwanted requests
4. Call aggregate for remaning requests on every aggregator
4. Call finalize on every aggregator
5. Call report on every aggregator
6. Finalize Source
|
[
"Runs",
"RequestLogAnalyzer",
"1",
".",
"Call",
"prepare",
"on",
"every",
"aggregator",
"2",
".",
"Generate",
"requests",
"from",
"source",
"object",
"3",
".",
"Filter",
"out",
"unwanted",
"requests",
"4",
".",
"Call",
"aggregate",
"for",
"remaning",
"requests",
"on",
"every",
"aggregator",
"4",
".",
"Call",
"finalize",
"on",
"every",
"aggregator",
"5",
".",
"Call",
"report",
"on",
"every",
"aggregator",
"6",
".",
"Finalize",
"Source"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/controller.rb#L328-L359
|
14,358
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/tracker/duration.rb
|
RequestLogAnalyzer::Tracker.Duration.display_value
|
def display_value(time)
case time
when nil then '-'
when 0...1 then '%0ims' % (time * 1000)
when 1...60 then '%0.02fs' % time
when 60...3600 then '%dm%02ds' % [time / 60, (time % 60).round]
else '%dh%02dm%02ds' % [time / 3600, (time % 3600) / 60, (time % 60).round]
end
end
|
ruby
|
def display_value(time)
case time
when nil then '-'
when 0...1 then '%0ims' % (time * 1000)
when 1...60 then '%0.02fs' % time
when 60...3600 then '%dm%02ds' % [time / 60, (time % 60).round]
else '%dh%02dm%02ds' % [time / 3600, (time % 3600) / 60, (time % 60).round]
end
end
|
[
"def",
"display_value",
"(",
"time",
")",
"case",
"time",
"when",
"nil",
"then",
"'-'",
"when",
"0",
"...",
"1",
"then",
"'%0ims'",
"%",
"(",
"time",
"*",
"1000",
")",
"when",
"1",
"...",
"60",
"then",
"'%0.02fs'",
"%",
"time",
"when",
"60",
"...",
"3600",
"then",
"'%dm%02ds'",
"%",
"[",
"time",
"/",
"60",
",",
"(",
"time",
"%",
"60",
")",
".",
"round",
"]",
"else",
"'%dh%02dm%02ds'",
"%",
"[",
"time",
"/",
"3600",
",",
"(",
"time",
"%",
"3600",
")",
"/",
"60",
",",
"(",
"time",
"%",
"60",
")",
".",
"round",
"]",
"end",
"end"
] |
Display a duration
|
[
"Display",
"a",
"duration"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/tracker/duration.rb#L36-L44
|
14,359
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/aggregator/database_inserter.rb
|
RequestLogAnalyzer::Aggregator.DatabaseInserter.prepare
|
def prepare
require 'request_log_analyzer/database'
@sources = {}
@database = RequestLogAnalyzer::Database.new(options[:database])
@database.file_format = source.file_format
database.drop_database_schema! if options[:reset_database]
database.create_database_schema!
end
|
ruby
|
def prepare
require 'request_log_analyzer/database'
@sources = {}
@database = RequestLogAnalyzer::Database.new(options[:database])
@database.file_format = source.file_format
database.drop_database_schema! if options[:reset_database]
database.create_database_schema!
end
|
[
"def",
"prepare",
"require",
"'request_log_analyzer/database'",
"@sources",
"=",
"{",
"}",
"@database",
"=",
"RequestLogAnalyzer",
"::",
"Database",
".",
"new",
"(",
"options",
"[",
":database",
"]",
")",
"@database",
".",
"file_format",
"=",
"source",
".",
"file_format",
"database",
".",
"drop_database_schema!",
"if",
"options",
"[",
":reset_database",
"]",
"database",
".",
"create_database_schema!",
"end"
] |
Establishes a connection to the database and creates the necessary database schema for the
current file format
|
[
"Establishes",
"a",
"connection",
"to",
"the",
"database",
"and",
"creates",
"the",
"necessary",
"database",
"schema",
"for",
"the",
"current",
"file",
"format"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/aggregator/database_inserter.rb#L18-L27
|
14,360
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/aggregator/database_inserter.rb
|
RequestLogAnalyzer::Aggregator.DatabaseInserter.aggregate
|
def aggregate(request)
@request_object = RequestLogAnalyzer::Database::Request.new(first_lineno: request.first_lineno, last_lineno: request.last_lineno)
request.lines.each do |line|
class_columns = database.get_class(line[:line_type]).column_names.reject { |column| %w(id source_id request_id).include?(column) }
attributes = Hash[*line.select { |(key, _)| class_columns.include?(key.to_s) }.flatten]
# Fix encoding patch for 1.9.2
attributes.each do |k, v|
attributes[k] = v.force_encoding('UTF-8') if v.is_a?(String)
end
@request_object.send("#{line[:line_type]}_lines").build(attributes)
end
@request_object.save!
rescue SQLite3::SQLException => e
raise Interrupt, e.message
end
|
ruby
|
def aggregate(request)
@request_object = RequestLogAnalyzer::Database::Request.new(first_lineno: request.first_lineno, last_lineno: request.last_lineno)
request.lines.each do |line|
class_columns = database.get_class(line[:line_type]).column_names.reject { |column| %w(id source_id request_id).include?(column) }
attributes = Hash[*line.select { |(key, _)| class_columns.include?(key.to_s) }.flatten]
# Fix encoding patch for 1.9.2
attributes.each do |k, v|
attributes[k] = v.force_encoding('UTF-8') if v.is_a?(String)
end
@request_object.send("#{line[:line_type]}_lines").build(attributes)
end
@request_object.save!
rescue SQLite3::SQLException => e
raise Interrupt, e.message
end
|
[
"def",
"aggregate",
"(",
"request",
")",
"@request_object",
"=",
"RequestLogAnalyzer",
"::",
"Database",
"::",
"Request",
".",
"new",
"(",
"first_lineno",
":",
"request",
".",
"first_lineno",
",",
"last_lineno",
":",
"request",
".",
"last_lineno",
")",
"request",
".",
"lines",
".",
"each",
"do",
"|",
"line",
"|",
"class_columns",
"=",
"database",
".",
"get_class",
"(",
"line",
"[",
":line_type",
"]",
")",
".",
"column_names",
".",
"reject",
"{",
"|",
"column",
"|",
"%w(",
"id",
"source_id",
"request_id",
")",
".",
"include?",
"(",
"column",
")",
"}",
"attributes",
"=",
"Hash",
"[",
"line",
".",
"select",
"{",
"|",
"(",
"key",
",",
"_",
")",
"|",
"class_columns",
".",
"include?",
"(",
"key",
".",
"to_s",
")",
"}",
".",
"flatten",
"]",
"# Fix encoding patch for 1.9.2",
"attributes",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"attributes",
"[",
"k",
"]",
"=",
"v",
".",
"force_encoding",
"(",
"'UTF-8'",
")",
"if",
"v",
".",
"is_a?",
"(",
"String",
")",
"end",
"@request_object",
".",
"send",
"(",
"\"#{line[:line_type]}_lines\"",
")",
".",
"build",
"(",
"attributes",
")",
"end",
"@request_object",
".",
"save!",
"rescue",
"SQLite3",
"::",
"SQLException",
"=>",
"e",
"raise",
"Interrupt",
",",
"e",
".",
"message",
"end"
] |
Aggregates a request into the database
This will create a record in the requests table and create a record for every line that has been parsed,
in which the captured values will be stored.
|
[
"Aggregates",
"a",
"request",
"into",
"the",
"database",
"This",
"will",
"create",
"a",
"record",
"in",
"the",
"requests",
"table",
"and",
"create",
"a",
"record",
"for",
"every",
"line",
"that",
"has",
"been",
"parsed",
"in",
"which",
"the",
"captured",
"values",
"will",
"be",
"stored",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/aggregator/database_inserter.rb#L32-L48
|
14,361
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/aggregator/database_inserter.rb
|
RequestLogAnalyzer::Aggregator.DatabaseInserter.warning
|
def warning(type, message, lineno)
RequestLogAnalyzer::Database::Warning.create!(warning_type: type.to_s, message: message, lineno: lineno)
end
|
ruby
|
def warning(type, message, lineno)
RequestLogAnalyzer::Database::Warning.create!(warning_type: type.to_s, message: message, lineno: lineno)
end
|
[
"def",
"warning",
"(",
"type",
",",
"message",
",",
"lineno",
")",
"RequestLogAnalyzer",
"::",
"Database",
"::",
"Warning",
".",
"create!",
"(",
"warning_type",
":",
"type",
".",
"to_s",
",",
"message",
":",
"message",
",",
"lineno",
":",
"lineno",
")",
"end"
] |
Records w warining in the warnings table.
|
[
"Records",
"w",
"warining",
"in",
"the",
"warnings",
"table",
"."
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/aggregator/database_inserter.rb#L58-L60
|
14,362
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/aggregator/database_inserter.rb
|
RequestLogAnalyzer::Aggregator.DatabaseInserter.source_change
|
def source_change(change, filename)
if File.exist?(filename)
case change
when :started
@sources[filename] = RequestLogAnalyzer::Database::Source.create!(filename: filename)
when :finished
@sources[filename].update_attributes!(filesize: File.size(filename), mtime: File.mtime(filename))
end
end
end
|
ruby
|
def source_change(change, filename)
if File.exist?(filename)
case change
when :started
@sources[filename] = RequestLogAnalyzer::Database::Source.create!(filename: filename)
when :finished
@sources[filename].update_attributes!(filesize: File.size(filename), mtime: File.mtime(filename))
end
end
end
|
[
"def",
"source_change",
"(",
"change",
",",
"filename",
")",
"if",
"File",
".",
"exist?",
"(",
"filename",
")",
"case",
"change",
"when",
":started",
"@sources",
"[",
"filename",
"]",
"=",
"RequestLogAnalyzer",
"::",
"Database",
"::",
"Source",
".",
"create!",
"(",
"filename",
":",
"filename",
")",
"when",
":finished",
"@sources",
"[",
"filename",
"]",
".",
"update_attributes!",
"(",
"filesize",
":",
"File",
".",
"size",
"(",
"filename",
")",
",",
"mtime",
":",
"File",
".",
"mtime",
"(",
"filename",
")",
")",
"end",
"end",
"end"
] |
Records source changes in the sources table
|
[
"Records",
"source",
"changes",
"in",
"the",
"sources",
"table"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/aggregator/database_inserter.rb#L63-L72
|
14,363
|
wvanbergen/request-log-analyzer
|
lib/request_log_analyzer/aggregator/database_inserter.rb
|
RequestLogAnalyzer::Aggregator.DatabaseInserter.report
|
def report(output)
output.title('Request database created')
output << "A database file has been created with all parsed request information.\n"
output << "#{@request_count} requests have been added to the database.\n"
output << "\n"
output << "To open a Ruby console to inspect the database, run the following command.\n"
output << output.colorize(" $ request-log-analyzer console -d #{options[:database]}\n", :bold)
output << "\n"
end
|
ruby
|
def report(output)
output.title('Request database created')
output << "A database file has been created with all parsed request information.\n"
output << "#{@request_count} requests have been added to the database.\n"
output << "\n"
output << "To open a Ruby console to inspect the database, run the following command.\n"
output << output.colorize(" $ request-log-analyzer console -d #{options[:database]}\n", :bold)
output << "\n"
end
|
[
"def",
"report",
"(",
"output",
")",
"output",
".",
"title",
"(",
"'Request database created'",
")",
"output",
"<<",
"\"A database file has been created with all parsed request information.\\n\"",
"output",
"<<",
"\"#{@request_count} requests have been added to the database.\\n\"",
"output",
"<<",
"\"\\n\"",
"output",
"<<",
"\"To open a Ruby console to inspect the database, run the following command.\\n\"",
"output",
"<<",
"output",
".",
"colorize",
"(",
"\" $ request-log-analyzer console -d #{options[:database]}\\n\"",
",",
":bold",
")",
"output",
"<<",
"\"\\n\"",
"end"
] |
Prints a short report of what has been inserted into the database
|
[
"Prints",
"a",
"short",
"report",
"of",
"what",
"has",
"been",
"inserted",
"into",
"the",
"database"
] |
b83865d440278583ac8e4901bb33878244fd7c75
|
https://github.com/wvanbergen/request-log-analyzer/blob/b83865d440278583ac8e4901bb33878244fd7c75/lib/request_log_analyzer/aggregator/database_inserter.rb#L75-L84
|
14,364
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/set.rb
|
ActiveScaffold::DataStructures.Set.add
|
def add(*args)
args.flatten! # allow [] as a param
args.each do |arg|
arg = arg.to_sym if arg.is_a? String
@set << arg unless @set.include? arg # avoid duplicates
end
end
|
ruby
|
def add(*args)
args.flatten! # allow [] as a param
args.each do |arg|
arg = arg.to_sym if arg.is_a? String
@set << arg unless @set.include? arg # avoid duplicates
end
end
|
[
"def",
"add",
"(",
"*",
"args",
")",
"args",
".",
"flatten!",
"# allow [] as a param",
"args",
".",
"each",
"do",
"|",
"arg",
"|",
"arg",
"=",
"arg",
".",
"to_sym",
"if",
"arg",
".",
"is_a?",
"String",
"@set",
"<<",
"arg",
"unless",
"@set",
".",
"include?",
"arg",
"# avoid duplicates",
"end",
"end"
] |
the way to add items to the set.
|
[
"the",
"way",
"to",
"add",
"items",
"to",
"the",
"set",
"."
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/set.rb#L20-L26
|
14,365
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/set.rb
|
ActiveScaffold::DataStructures.Set.exclude
|
def exclude(*args)
args.flatten! # allow [] as a param
args.collect!(&:to_sym) # symbolize the args
# check respond_to? :to_sym, ActionColumns doesn't respond to to_sym
@set.reject! { |c| c.respond_to?(:to_sym) && args.include?(c.to_sym) } # reject all items specified
end
|
ruby
|
def exclude(*args)
args.flatten! # allow [] as a param
args.collect!(&:to_sym) # symbolize the args
# check respond_to? :to_sym, ActionColumns doesn't respond to to_sym
@set.reject! { |c| c.respond_to?(:to_sym) && args.include?(c.to_sym) } # reject all items specified
end
|
[
"def",
"exclude",
"(",
"*",
"args",
")",
"args",
".",
"flatten!",
"# allow [] as a param",
"args",
".",
"collect!",
"(",
":to_sym",
")",
"# symbolize the args",
"# check respond_to? :to_sym, ActionColumns doesn't respond to to_sym",
"@set",
".",
"reject!",
"{",
"|",
"c",
"|",
"c",
".",
"respond_to?",
"(",
":to_sym",
")",
"&&",
"args",
".",
"include?",
"(",
"c",
".",
"to_sym",
")",
"}",
"# reject all items specified",
"end"
] |
the way to remove items from the set.
|
[
"the",
"way",
"to",
"remove",
"items",
"from",
"the",
"set",
"."
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/set.rb#L30-L35
|
14,366
|
activescaffold/active_scaffold
|
lib/active_scaffold/attribute_params.rb
|
ActiveScaffold.AttributeParams.attributes_hash_is_empty?
|
def attributes_hash_is_empty?(hash, klass)
hash.all? do |key, value|
# convert any possible multi-parameter attributes like 'created_at(5i)' to simply 'created_at'
column_name = key.to_s.split('(', 2)[0]
# datetimes will always have a value. so we ignore them when checking whether the hash is empty.
# this could be a bad idea. but the current situation (excess record entry) seems worse.
next true if mulitpart_ignored?(key, klass)
# defaults are pre-filled on the form. we can't use them to determine if the user intends a new row.
# booleans always have value, so they are ignored if not changed from default
next true if default_value?(column_name, klass, value)
if params_hash? value
attributes_hash_is_empty?(value, klass)
elsif value.is_a?(Array)
value.all?(&:blank?)
else
value.respond_to?(:empty?) ? value.empty? : false
end
end
end
|
ruby
|
def attributes_hash_is_empty?(hash, klass)
hash.all? do |key, value|
# convert any possible multi-parameter attributes like 'created_at(5i)' to simply 'created_at'
column_name = key.to_s.split('(', 2)[0]
# datetimes will always have a value. so we ignore them when checking whether the hash is empty.
# this could be a bad idea. but the current situation (excess record entry) seems worse.
next true if mulitpart_ignored?(key, klass)
# defaults are pre-filled on the form. we can't use them to determine if the user intends a new row.
# booleans always have value, so they are ignored if not changed from default
next true if default_value?(column_name, klass, value)
if params_hash? value
attributes_hash_is_empty?(value, klass)
elsif value.is_a?(Array)
value.all?(&:blank?)
else
value.respond_to?(:empty?) ? value.empty? : false
end
end
end
|
[
"def",
"attributes_hash_is_empty?",
"(",
"hash",
",",
"klass",
")",
"hash",
".",
"all?",
"do",
"|",
"key",
",",
"value",
"|",
"# convert any possible multi-parameter attributes like 'created_at(5i)' to simply 'created_at'",
"column_name",
"=",
"key",
".",
"to_s",
".",
"split",
"(",
"'('",
",",
"2",
")",
"[",
"0",
"]",
"# datetimes will always have a value. so we ignore them when checking whether the hash is empty.",
"# this could be a bad idea. but the current situation (excess record entry) seems worse.",
"next",
"true",
"if",
"mulitpart_ignored?",
"(",
"key",
",",
"klass",
")",
"# defaults are pre-filled on the form. we can't use them to determine if the user intends a new row.",
"# booleans always have value, so they are ignored if not changed from default",
"next",
"true",
"if",
"default_value?",
"(",
"column_name",
",",
"klass",
",",
"value",
")",
"if",
"params_hash?",
"value",
"attributes_hash_is_empty?",
"(",
"value",
",",
"klass",
")",
"elsif",
"value",
".",
"is_a?",
"(",
"Array",
")",
"value",
".",
"all?",
"(",
":blank?",
")",
"else",
"value",
".",
"respond_to?",
"(",
":empty?",
")",
"?",
"value",
".",
"empty?",
":",
"false",
"end",
"end",
"end"
] |
Determines whether the given attributes hash is "empty".
This isn't a literal emptiness - it's an attempt to discern whether the user intended it to be empty or not.
|
[
"Determines",
"whether",
"the",
"given",
"attributes",
"hash",
"is",
"empty",
".",
"This",
"isn",
"t",
"a",
"literal",
"emptiness",
"-",
"it",
"s",
"an",
"attempt",
"to",
"discern",
"whether",
"the",
"user",
"intended",
"it",
"to",
"be",
"empty",
"or",
"not",
"."
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/attribute_params.rb#L294-L315
|
14,367
|
activescaffold/active_scaffold
|
lib/active_scaffold/actions/nested.rb
|
ActiveScaffold::Actions::Nested.ChildMethods.do_add_existing
|
def do_add_existing
parent_record = nested_parent_record(:update)
@record = active_scaffold_config.model.find(params[:associated_id])
if parent_record && @record
parent_record.send(nested.association.name) << @record
parent_record.save
else
false
end
end
|
ruby
|
def do_add_existing
parent_record = nested_parent_record(:update)
@record = active_scaffold_config.model.find(params[:associated_id])
if parent_record && @record
parent_record.send(nested.association.name) << @record
parent_record.save
else
false
end
end
|
[
"def",
"do_add_existing",
"parent_record",
"=",
"nested_parent_record",
"(",
":update",
")",
"@record",
"=",
"active_scaffold_config",
".",
"model",
".",
"find",
"(",
"params",
"[",
":associated_id",
"]",
")",
"if",
"parent_record",
"&&",
"@record",
"parent_record",
".",
"send",
"(",
"nested",
".",
"association",
".",
"name",
")",
"<<",
"@record",
"parent_record",
".",
"save",
"else",
"false",
"end",
"end"
] |
The actual "add_existing" algorithm
|
[
"The",
"actual",
"add_existing",
"algorithm"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/actions/nested.rb#L238-L247
|
14,368
|
activescaffold/active_scaffold
|
lib/active_scaffold/extensions/action_view_rendering.rb
|
ActiveScaffold.RenderingHelper.render
|
def render(*args, &block)
if args.first.is_a?(Hash) && args.first[:active_scaffold]
render_embedded args.first
elsif args.first == :super
@_view_paths ||= lookup_context.view_paths.clone
@_last_template ||= lookup_context.last_template
parts = @virtual_path.split('/')
template = parts.pop
prefix = parts.join('/')
options = args[1] || {}
options[:locals] ||= {}
if view_stack.last
options[:locals] = view_stack.last[:locals].merge!(options[:locals]) if view_stack.last[:locals]
options[:object] ||= view_stack.last[:object] if view_stack.last[:object]
end
options[:template] = template
# if prefix is active_scaffold_overrides we must try to render with this prefix in following paths
if prefix != 'active_scaffold_overrides'
options[:prefixes] = lookup_context.prefixes.drop((lookup_context.prefixes.find_index(prefix) || -1) + 1)
else
options[:prefixes] = ['active_scaffold_overrides']
last_view_path = File.expand_path(File.dirname(File.dirname(lookup_context.last_template.inspect)), Rails.root)
lookup_context.view_paths = view_paths.drop(view_paths.find_index { |path| path.to_s == last_view_path } + 1)
end
result = super options
lookup_context.view_paths = @_view_paths if @_view_paths
lookup_context.last_template = @_last_template if @_last_template
result
else
@_view_paths ||= lookup_context.view_paths.clone
last_template = lookup_context.last_template
current_view = if args[0].is_a?(Hash)
{:locals => args[0][:locals], :object => args[0][:object]}
else # call is render 'partial', locals_hash
{:locals => args[1]}
end
view_stack << current_view if current_view
lookup_context.view_paths = @_view_paths # reset view_paths in case a view render :super, and then render :partial
result = super
view_stack.pop if current_view.present?
lookup_context.last_template = last_template
result
end
end
|
ruby
|
def render(*args, &block)
if args.first.is_a?(Hash) && args.first[:active_scaffold]
render_embedded args.first
elsif args.first == :super
@_view_paths ||= lookup_context.view_paths.clone
@_last_template ||= lookup_context.last_template
parts = @virtual_path.split('/')
template = parts.pop
prefix = parts.join('/')
options = args[1] || {}
options[:locals] ||= {}
if view_stack.last
options[:locals] = view_stack.last[:locals].merge!(options[:locals]) if view_stack.last[:locals]
options[:object] ||= view_stack.last[:object] if view_stack.last[:object]
end
options[:template] = template
# if prefix is active_scaffold_overrides we must try to render with this prefix in following paths
if prefix != 'active_scaffold_overrides'
options[:prefixes] = lookup_context.prefixes.drop((lookup_context.prefixes.find_index(prefix) || -1) + 1)
else
options[:prefixes] = ['active_scaffold_overrides']
last_view_path = File.expand_path(File.dirname(File.dirname(lookup_context.last_template.inspect)), Rails.root)
lookup_context.view_paths = view_paths.drop(view_paths.find_index { |path| path.to_s == last_view_path } + 1)
end
result = super options
lookup_context.view_paths = @_view_paths if @_view_paths
lookup_context.last_template = @_last_template if @_last_template
result
else
@_view_paths ||= lookup_context.view_paths.clone
last_template = lookup_context.last_template
current_view = if args[0].is_a?(Hash)
{:locals => args[0][:locals], :object => args[0][:object]}
else # call is render 'partial', locals_hash
{:locals => args[1]}
end
view_stack << current_view if current_view
lookup_context.view_paths = @_view_paths # reset view_paths in case a view render :super, and then render :partial
result = super
view_stack.pop if current_view.present?
lookup_context.last_template = last_template
result
end
end
|
[
"def",
"render",
"(",
"*",
"args",
",",
"&",
"block",
")",
"if",
"args",
".",
"first",
".",
"is_a?",
"(",
"Hash",
")",
"&&",
"args",
".",
"first",
"[",
":active_scaffold",
"]",
"render_embedded",
"args",
".",
"first",
"elsif",
"args",
".",
"first",
"==",
":super",
"@_view_paths",
"||=",
"lookup_context",
".",
"view_paths",
".",
"clone",
"@_last_template",
"||=",
"lookup_context",
".",
"last_template",
"parts",
"=",
"@virtual_path",
".",
"split",
"(",
"'/'",
")",
"template",
"=",
"parts",
".",
"pop",
"prefix",
"=",
"parts",
".",
"join",
"(",
"'/'",
")",
"options",
"=",
"args",
"[",
"1",
"]",
"||",
"{",
"}",
"options",
"[",
":locals",
"]",
"||=",
"{",
"}",
"if",
"view_stack",
".",
"last",
"options",
"[",
":locals",
"]",
"=",
"view_stack",
".",
"last",
"[",
":locals",
"]",
".",
"merge!",
"(",
"options",
"[",
":locals",
"]",
")",
"if",
"view_stack",
".",
"last",
"[",
":locals",
"]",
"options",
"[",
":object",
"]",
"||=",
"view_stack",
".",
"last",
"[",
":object",
"]",
"if",
"view_stack",
".",
"last",
"[",
":object",
"]",
"end",
"options",
"[",
":template",
"]",
"=",
"template",
"# if prefix is active_scaffold_overrides we must try to render with this prefix in following paths",
"if",
"prefix",
"!=",
"'active_scaffold_overrides'",
"options",
"[",
":prefixes",
"]",
"=",
"lookup_context",
".",
"prefixes",
".",
"drop",
"(",
"(",
"lookup_context",
".",
"prefixes",
".",
"find_index",
"(",
"prefix",
")",
"||",
"-",
"1",
")",
"+",
"1",
")",
"else",
"options",
"[",
":prefixes",
"]",
"=",
"[",
"'active_scaffold_overrides'",
"]",
"last_view_path",
"=",
"File",
".",
"expand_path",
"(",
"File",
".",
"dirname",
"(",
"File",
".",
"dirname",
"(",
"lookup_context",
".",
"last_template",
".",
"inspect",
")",
")",
",",
"Rails",
".",
"root",
")",
"lookup_context",
".",
"view_paths",
"=",
"view_paths",
".",
"drop",
"(",
"view_paths",
".",
"find_index",
"{",
"|",
"path",
"|",
"path",
".",
"to_s",
"==",
"last_view_path",
"}",
"+",
"1",
")",
"end",
"result",
"=",
"super",
"options",
"lookup_context",
".",
"view_paths",
"=",
"@_view_paths",
"if",
"@_view_paths",
"lookup_context",
".",
"last_template",
"=",
"@_last_template",
"if",
"@_last_template",
"result",
"else",
"@_view_paths",
"||=",
"lookup_context",
".",
"view_paths",
".",
"clone",
"last_template",
"=",
"lookup_context",
".",
"last_template",
"current_view",
"=",
"if",
"args",
"[",
"0",
"]",
".",
"is_a?",
"(",
"Hash",
")",
"{",
":locals",
"=>",
"args",
"[",
"0",
"]",
"[",
":locals",
"]",
",",
":object",
"=>",
"args",
"[",
"0",
"]",
"[",
":object",
"]",
"}",
"else",
"# call is render 'partial', locals_hash",
"{",
":locals",
"=>",
"args",
"[",
"1",
"]",
"}",
"end",
"view_stack",
"<<",
"current_view",
"if",
"current_view",
"lookup_context",
".",
"view_paths",
"=",
"@_view_paths",
"# reset view_paths in case a view render :super, and then render :partial",
"result",
"=",
"super",
"view_stack",
".",
"pop",
"if",
"current_view",
".",
"present?",
"lookup_context",
".",
"last_template",
"=",
"last_template",
"result",
"end",
"end"
] |
Adds two rendering options.
==render :super
This syntax skips all template overrides and goes directly to the provided ActiveScaffold templates.
Useful if you want to wrap an existing template. Just call super!
==render :active_scaffold => #{controller.to_s}, options = {}+
Lets you embed an ActiveScaffold by referencing the controller where it's configured.
You may specify options[:constraints] for the embedded scaffold. These constraints have three effects:
* the scaffold's only displays records matching the constraint
* all new records created will be assigned the constrained values
* constrained columns will be hidden (they're pretty boring at this point)
You may also specify options[:conditions] for the embedded scaffold. These only do 1/3 of what
constraints do (they only limit search results). Any format accepted by ActiveRecord::Base.find is valid.
Defining options[:label] lets you completely customize the list title for the embedded scaffold.
options[:xhr] force to load embedded scaffold with AJAX even when render_component gem is installed.
|
[
"Adds",
"two",
"rendering",
"options",
"."
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/extensions/action_view_rendering.rb#L38-L82
|
14,369
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/action_link.rb
|
ActiveScaffold::DataStructures.ActionLink.initialize_copy
|
def initialize_copy(action_link)
self.parameters = parameters.clone if action_link.instance_variable_get(:@parameters)
self.html_options = html_options.clone if action_link.instance_variable_get(:@html_options)
end
|
ruby
|
def initialize_copy(action_link)
self.parameters = parameters.clone if action_link.instance_variable_get(:@parameters)
self.html_options = html_options.clone if action_link.instance_variable_get(:@html_options)
end
|
[
"def",
"initialize_copy",
"(",
"action_link",
")",
"self",
".",
"parameters",
"=",
"parameters",
".",
"clone",
"if",
"action_link",
".",
"instance_variable_get",
"(",
":@parameters",
")",
"self",
".",
"html_options",
"=",
"html_options",
".",
"clone",
"if",
"action_link",
".",
"instance_variable_get",
"(",
":@html_options",
")",
"end"
] |
provides a quick way to set any property of the object from a hash
|
[
"provides",
"a",
"quick",
"way",
"to",
"set",
"any",
"property",
"of",
"the",
"object",
"from",
"a",
"hash"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/action_link.rb#L31-L34
|
14,370
|
activescaffold/active_scaffold
|
lib/active_scaffold/config/nested.rb
|
ActiveScaffold::Config.Nested.add_link
|
def add_link(attribute, options = {})
column = @core.columns[attribute.to_sym]
raise ArgumentError, "unknown column #{attribute}" if column.nil?
raise ArgumentError, "column #{attribute} is not an association" if column.association.nil?
label =
if column.association.polymorphic?
column.label
else
column.association.klass.model_name.human(:count => column.association.singular? ? 1 : 2, :default => column.association.klass.name.pluralize)
end
options.reverse_merge! :security_method => :nested_authorized?, :label => label
action_group = options.delete(:action_group) || self.action_group
action_link = @core.link_for_association(column, options)
@core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
action_link
end
|
ruby
|
def add_link(attribute, options = {})
column = @core.columns[attribute.to_sym]
raise ArgumentError, "unknown column #{attribute}" if column.nil?
raise ArgumentError, "column #{attribute} is not an association" if column.association.nil?
label =
if column.association.polymorphic?
column.label
else
column.association.klass.model_name.human(:count => column.association.singular? ? 1 : 2, :default => column.association.klass.name.pluralize)
end
options.reverse_merge! :security_method => :nested_authorized?, :label => label
action_group = options.delete(:action_group) || self.action_group
action_link = @core.link_for_association(column, options)
@core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
action_link
end
|
[
"def",
"add_link",
"(",
"attribute",
",",
"options",
"=",
"{",
"}",
")",
"column",
"=",
"@core",
".",
"columns",
"[",
"attribute",
".",
"to_sym",
"]",
"raise",
"ArgumentError",
",",
"\"unknown column #{attribute}\"",
"if",
"column",
".",
"nil?",
"raise",
"ArgumentError",
",",
"\"column #{attribute} is not an association\"",
"if",
"column",
".",
"association",
".",
"nil?",
"label",
"=",
"if",
"column",
".",
"association",
".",
"polymorphic?",
"column",
".",
"label",
"else",
"column",
".",
"association",
".",
"klass",
".",
"model_name",
".",
"human",
"(",
":count",
"=>",
"column",
".",
"association",
".",
"singular?",
"?",
"1",
":",
"2",
",",
":default",
"=>",
"column",
".",
"association",
".",
"klass",
".",
"name",
".",
"pluralize",
")",
"end",
"options",
".",
"reverse_merge!",
":security_method",
"=>",
":nested_authorized?",
",",
":label",
"=>",
"label",
"action_group",
"=",
"options",
".",
"delete",
"(",
":action_group",
")",
"||",
"self",
".",
"action_group",
"action_link",
"=",
"@core",
".",
"link_for_association",
"(",
"column",
",",
"options",
")",
"@core",
".",
"action_links",
".",
"add_to_group",
"(",
"action_link",
",",
"action_group",
")",
"unless",
"action_link",
".",
"nil?",
"action_link",
"end"
] |
Add a nested ActionLink
|
[
"Add",
"a",
"nested",
"ActionLink"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/config/nested.rb#L26-L42
|
14,371
|
activescaffold/active_scaffold
|
lib/active_scaffold/actions/create.rb
|
ActiveScaffold::Actions.Create.do_create
|
def do_create(options = {})
attributes = options[:attributes] || params[:record]
active_scaffold_config.model.transaction do
@record = update_record_from_params(new_model, active_scaffold_config.create.columns, attributes)
apply_constraints_to_record(@record, :allow_autosave => true)
create_association_with_parent(@record) if nested?
before_create_save(@record)
# errors to @record can be added by update_record_from_params when association fails to set and ActiveRecord::RecordNotSaved is raised
self.successful = [@record.keeping_errors { @record.valid? }, @record.associated_valid?].all? # this syntax avoids a short-circuit
create_save(@record) unless options[:skip_save]
end
rescue ActiveRecord::ActiveRecordError => ex
flash[:error] = ex.message
self.successful = false
@record ||= new_model # ensure @record exists or display form will fail
end
|
ruby
|
def do_create(options = {})
attributes = options[:attributes] || params[:record]
active_scaffold_config.model.transaction do
@record = update_record_from_params(new_model, active_scaffold_config.create.columns, attributes)
apply_constraints_to_record(@record, :allow_autosave => true)
create_association_with_parent(@record) if nested?
before_create_save(@record)
# errors to @record can be added by update_record_from_params when association fails to set and ActiveRecord::RecordNotSaved is raised
self.successful = [@record.keeping_errors { @record.valid? }, @record.associated_valid?].all? # this syntax avoids a short-circuit
create_save(@record) unless options[:skip_save]
end
rescue ActiveRecord::ActiveRecordError => ex
flash[:error] = ex.message
self.successful = false
@record ||= new_model # ensure @record exists or display form will fail
end
|
[
"def",
"do_create",
"(",
"options",
"=",
"{",
"}",
")",
"attributes",
"=",
"options",
"[",
":attributes",
"]",
"||",
"params",
"[",
":record",
"]",
"active_scaffold_config",
".",
"model",
".",
"transaction",
"do",
"@record",
"=",
"update_record_from_params",
"(",
"new_model",
",",
"active_scaffold_config",
".",
"create",
".",
"columns",
",",
"attributes",
")",
"apply_constraints_to_record",
"(",
"@record",
",",
":allow_autosave",
"=>",
"true",
")",
"create_association_with_parent",
"(",
"@record",
")",
"if",
"nested?",
"before_create_save",
"(",
"@record",
")",
"# errors to @record can be added by update_record_from_params when association fails to set and ActiveRecord::RecordNotSaved is raised",
"self",
".",
"successful",
"=",
"[",
"@record",
".",
"keeping_errors",
"{",
"@record",
".",
"valid?",
"}",
",",
"@record",
".",
"associated_valid?",
"]",
".",
"all?",
"# this syntax avoids a short-circuit",
"create_save",
"(",
"@record",
")",
"unless",
"options",
"[",
":skip_save",
"]",
"end",
"rescue",
"ActiveRecord",
"::",
"ActiveRecordError",
"=>",
"ex",
"flash",
"[",
":error",
"]",
"=",
"ex",
".",
"message",
"self",
".",
"successful",
"=",
"false",
"@record",
"||=",
"new_model",
"# ensure @record exists or display form will fail",
"end"
] |
A somewhat complex method to actually create a new record. The complexity is from support for subforms and associated records.
If you want to customize this behavior, consider using the +before_create_save+ and +after_create_save+ callbacks.
|
[
"A",
"somewhat",
"complex",
"method",
"to",
"actually",
"create",
"a",
"new",
"record",
".",
"The",
"complexity",
"is",
"from",
"support",
"for",
"subforms",
"and",
"associated",
"records",
".",
"If",
"you",
"want",
"to",
"customize",
"this",
"behavior",
"consider",
"using",
"the",
"+",
"before_create_save",
"+",
"and",
"+",
"after_create_save",
"+",
"callbacks",
"."
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/actions/create.rb#L93-L108
|
14,372
|
activescaffold/active_scaffold
|
lib/active_scaffold/config/core.rb
|
ActiveScaffold::Config.Core._configure_sti
|
def _configure_sti
column = model.inheritance_column
if sti_create_links
columns[column].form_ui ||= :hidden
else
columns[column].form_ui ||= :select
columns[column].options ||= {}
columns[column].options[:options] = sti_children.collect do |model_name|
[model_name.to_s.camelize.constantize.model_name.human, model_name.to_s.camelize]
end
end
end
|
ruby
|
def _configure_sti
column = model.inheritance_column
if sti_create_links
columns[column].form_ui ||= :hidden
else
columns[column].form_ui ||= :select
columns[column].options ||= {}
columns[column].options[:options] = sti_children.collect do |model_name|
[model_name.to_s.camelize.constantize.model_name.human, model_name.to_s.camelize]
end
end
end
|
[
"def",
"_configure_sti",
"column",
"=",
"model",
".",
"inheritance_column",
"if",
"sti_create_links",
"columns",
"[",
"column",
"]",
".",
"form_ui",
"||=",
":hidden",
"else",
"columns",
"[",
"column",
"]",
".",
"form_ui",
"||=",
":select",
"columns",
"[",
"column",
"]",
".",
"options",
"||=",
"{",
"}",
"columns",
"[",
"column",
"]",
".",
"options",
"[",
":options",
"]",
"=",
"sti_children",
".",
"collect",
"do",
"|",
"model_name",
"|",
"[",
"model_name",
".",
"to_s",
".",
"camelize",
".",
"constantize",
".",
"model_name",
".",
"human",
",",
"model_name",
".",
"to_s",
".",
"camelize",
"]",
"end",
"end",
"end"
] |
To be called after your finished configuration
|
[
"To",
"be",
"called",
"after",
"your",
"finished",
"configuration"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/config/core.rb#L208-L219
|
14,373
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/sorting.rb
|
ActiveScaffold::DataStructures.Sorting.add
|
def add(column_name, direction = nil)
direction ||= 'ASC'
direction = direction.to_s.upcase
column = get_column(column_name)
raise ArgumentError, "Could not find column #{column_name}" if column.nil?
raise ArgumentError, 'Sorting direction unknown' unless %i[ASC DESC].include? direction.to_sym
@clauses << [column, direction.untaint] if column.sortable?
raise ArgumentError, "Can't mix :method- and :sql-based sorting" if mixed_sorting?
end
|
ruby
|
def add(column_name, direction = nil)
direction ||= 'ASC'
direction = direction.to_s.upcase
column = get_column(column_name)
raise ArgumentError, "Could not find column #{column_name}" if column.nil?
raise ArgumentError, 'Sorting direction unknown' unless %i[ASC DESC].include? direction.to_sym
@clauses << [column, direction.untaint] if column.sortable?
raise ArgumentError, "Can't mix :method- and :sql-based sorting" if mixed_sorting?
end
|
[
"def",
"add",
"(",
"column_name",
",",
"direction",
"=",
"nil",
")",
"direction",
"||=",
"'ASC'",
"direction",
"=",
"direction",
".",
"to_s",
".",
"upcase",
"column",
"=",
"get_column",
"(",
"column_name",
")",
"raise",
"ArgumentError",
",",
"\"Could not find column #{column_name}\"",
"if",
"column",
".",
"nil?",
"raise",
"ArgumentError",
",",
"'Sorting direction unknown'",
"unless",
"%i[",
"ASC",
"DESC",
"]",
".",
"include?",
"direction",
".",
"to_sym",
"@clauses",
"<<",
"[",
"column",
",",
"direction",
".",
"untaint",
"]",
"if",
"column",
".",
"sortable?",
"raise",
"ArgumentError",
",",
"\"Can't mix :method- and :sql-based sorting\"",
"if",
"mixed_sorting?",
"end"
] |
add a clause to the sorting, assuming the column is sortable
|
[
"add",
"a",
"clause",
"to",
"the",
"sorting",
"assuming",
"the",
"column",
"is",
"sortable"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/sorting.rb#L37-L45
|
14,374
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/sorting.rb
|
ActiveScaffold::DataStructures.Sorting.clause
|
def clause(grouped_columns_calculations = nil)
return nil if sorts_by_method? || default_sorting?
# unless the sorting is by method, create the sql string
order = []
each do |sort_column, sort_direction|
next if constraint_columns.include? sort_column.name
sql = grouped_columns_calculations&.dig(sort_column.name) || sort_column.sort[:sql]
next if sql.blank?
sql = sql.to_sql if sql.respond_to?(:to_sql)
parts = Array(sql).map do |column|
mongoid? ? [column, sort_direction] : "#{column} #{sort_direction}"
end
order << parts
end
order << @primary_key_order_clause if @sorting_by_primary_key
order.flatten!(1)
order unless order.empty?
end
|
ruby
|
def clause(grouped_columns_calculations = nil)
return nil if sorts_by_method? || default_sorting?
# unless the sorting is by method, create the sql string
order = []
each do |sort_column, sort_direction|
next if constraint_columns.include? sort_column.name
sql = grouped_columns_calculations&.dig(sort_column.name) || sort_column.sort[:sql]
next if sql.blank?
sql = sql.to_sql if sql.respond_to?(:to_sql)
parts = Array(sql).map do |column|
mongoid? ? [column, sort_direction] : "#{column} #{sort_direction}"
end
order << parts
end
order << @primary_key_order_clause if @sorting_by_primary_key
order.flatten!(1)
order unless order.empty?
end
|
[
"def",
"clause",
"(",
"grouped_columns_calculations",
"=",
"nil",
")",
"return",
"nil",
"if",
"sorts_by_method?",
"||",
"default_sorting?",
"# unless the sorting is by method, create the sql string",
"order",
"=",
"[",
"]",
"each",
"do",
"|",
"sort_column",
",",
"sort_direction",
"|",
"next",
"if",
"constraint_columns",
".",
"include?",
"sort_column",
".",
"name",
"sql",
"=",
"grouped_columns_calculations",
"&.",
"dig",
"(",
"sort_column",
".",
"name",
")",
"||",
"sort_column",
".",
"sort",
"[",
":sql",
"]",
"next",
"if",
"sql",
".",
"blank?",
"sql",
"=",
"sql",
".",
"to_sql",
"if",
"sql",
".",
"respond_to?",
"(",
":to_sql",
")",
"parts",
"=",
"Array",
"(",
"sql",
")",
".",
"map",
"do",
"|",
"column",
"|",
"mongoid?",
"?",
"[",
"column",
",",
"sort_direction",
"]",
":",
"\"#{column} #{sort_direction}\"",
"end",
"order",
"<<",
"parts",
"end",
"order",
"<<",
"@primary_key_order_clause",
"if",
"@sorting_by_primary_key",
"order",
".",
"flatten!",
"(",
"1",
")",
"order",
"unless",
"order",
".",
"empty?",
"end"
] |
builds an order-by clause
|
[
"builds",
"an",
"order",
"-",
"by",
"clause"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/sorting.rb#L123-L143
|
14,375
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/sorting.rb
|
ActiveScaffold::DataStructures.Sorting.get_column
|
def get_column(name_or_column)
# it's a column
return name_or_column if name_or_column.is_a? ActiveScaffold::DataStructures::Column
# it's a name
name_or_column = name_or_column.to_s.split('.').last if name_or_column.to_s.include? '.'
@columns[name_or_column]
end
|
ruby
|
def get_column(name_or_column)
# it's a column
return name_or_column if name_or_column.is_a? ActiveScaffold::DataStructures::Column
# it's a name
name_or_column = name_or_column.to_s.split('.').last if name_or_column.to_s.include? '.'
@columns[name_or_column]
end
|
[
"def",
"get_column",
"(",
"name_or_column",
")",
"# it's a column",
"return",
"name_or_column",
"if",
"name_or_column",
".",
"is_a?",
"ActiveScaffold",
"::",
"DataStructures",
"::",
"Column",
"# it's a name",
"name_or_column",
"=",
"name_or_column",
".",
"to_s",
".",
"split",
"(",
"'.'",
")",
".",
"last",
"if",
"name_or_column",
".",
"to_s",
".",
"include?",
"'.'",
"@columns",
"[",
"name_or_column",
"]",
"end"
] |
possibly converts the given argument into a column object from @columns (if it's not already)
|
[
"possibly",
"converts",
"the",
"given",
"argument",
"into",
"a",
"column",
"object",
"from"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/sorting.rb#L154-L160
|
14,376
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/columns.rb
|
ActiveScaffold::DataStructures.Columns.add
|
def add(*args)
args.flatten! # allow [] as a param
args = args.collect(&:to_sym)
# make the columns inheritable
@_inheritable.concat(args)
# then add columns to @set (unless they already exist)
args.each { |a| @set << ActiveScaffold::DataStructures::Column.new(a.to_sym, @active_record_class) unless find_by_name(a) }
end
|
ruby
|
def add(*args)
args.flatten! # allow [] as a param
args = args.collect(&:to_sym)
# make the columns inheritable
@_inheritable.concat(args)
# then add columns to @set (unless they already exist)
args.each { |a| @set << ActiveScaffold::DataStructures::Column.new(a.to_sym, @active_record_class) unless find_by_name(a) }
end
|
[
"def",
"add",
"(",
"*",
"args",
")",
"args",
".",
"flatten!",
"# allow [] as a param",
"args",
"=",
"args",
".",
"collect",
"(",
":to_sym",
")",
"# make the columns inheritable",
"@_inheritable",
".",
"concat",
"(",
"args",
")",
"# then add columns to @set (unless they already exist)",
"args",
".",
"each",
"{",
"|",
"a",
"|",
"@set",
"<<",
"ActiveScaffold",
"::",
"DataStructures",
"::",
"Column",
".",
"new",
"(",
"a",
".",
"to_sym",
",",
"@active_record_class",
")",
"unless",
"find_by_name",
"(",
"a",
")",
"}",
"end"
] |
the way to add columns to the set. this is primarily useful for virtual columns.
note that this also makes columns inheritable
|
[
"the",
"way",
"to",
"add",
"columns",
"to",
"the",
"set",
".",
"this",
"is",
"primarily",
"useful",
"for",
"virtual",
"columns",
".",
"note",
"that",
"this",
"also",
"makes",
"columns",
"inheritable"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/columns.rb#L32-L40
|
14,377
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/column.rb
|
ActiveScaffold::DataStructures.Column.set_link
|
def set_link(action, options = {})
if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || (action.is_a? Proc)
@link = action
else
options[:label] ||= label
options[:position] ||= :after unless options.key?(:position)
options[:type] ||= :member
@link = ActiveScaffold::DataStructures::ActionLink.new(action, options)
end
end
|
ruby
|
def set_link(action, options = {})
if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || (action.is_a? Proc)
@link = action
else
options[:label] ||= label
options[:position] ||= :after unless options.key?(:position)
options[:type] ||= :member
@link = ActiveScaffold::DataStructures::ActionLink.new(action, options)
end
end
|
[
"def",
"set_link",
"(",
"action",
",",
"options",
"=",
"{",
"}",
")",
"if",
"action",
".",
"is_a?",
"(",
"ActiveScaffold",
"::",
"DataStructures",
"::",
"ActionLink",
")",
"||",
"(",
"action",
".",
"is_a?",
"Proc",
")",
"@link",
"=",
"action",
"else",
"options",
"[",
":label",
"]",
"||=",
"label",
"options",
"[",
":position",
"]",
"||=",
":after",
"unless",
"options",
".",
"key?",
"(",
":position",
")",
"options",
"[",
":type",
"]",
"||=",
":member",
"@link",
"=",
"ActiveScaffold",
"::",
"DataStructures",
"::",
"ActionLink",
".",
"new",
"(",
"action",
",",
"options",
")",
"end",
"end"
] |
associate an action_link with this column
|
[
"associate",
"an",
"action_link",
"with",
"this",
"column"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/column.rb#L156-L165
|
14,378
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/action_links.rb
|
ActiveScaffold::DataStructures.ActionLinks.add
|
def add(action, options = {})
link =
if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || action.is_a?(ActiveScaffold::DataStructures::ActionLinks)
action
else
options[:type] ||= default_type if default_type
ActiveScaffold::DataStructures::ActionLink.new(action, options)
end
# NOTE: this duplicate check should be done by defining the comparison operator for an Action data structure
existing = find_duplicate(link)
if existing
existing
else
# That s for backwards compatibility if we are in root of action_links
# we have to move actionlink into members or collection subgroup
group = (name == :root ? subgroup(link.type, link.type) : self)
group.add_to_set(link)
link
end
end
|
ruby
|
def add(action, options = {})
link =
if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || action.is_a?(ActiveScaffold::DataStructures::ActionLinks)
action
else
options[:type] ||= default_type if default_type
ActiveScaffold::DataStructures::ActionLink.new(action, options)
end
# NOTE: this duplicate check should be done by defining the comparison operator for an Action data structure
existing = find_duplicate(link)
if existing
existing
else
# That s for backwards compatibility if we are in root of action_links
# we have to move actionlink into members or collection subgroup
group = (name == :root ? subgroup(link.type, link.type) : self)
group.add_to_set(link)
link
end
end
|
[
"def",
"add",
"(",
"action",
",",
"options",
"=",
"{",
"}",
")",
"link",
"=",
"if",
"action",
".",
"is_a?",
"(",
"ActiveScaffold",
"::",
"DataStructures",
"::",
"ActionLink",
")",
"||",
"action",
".",
"is_a?",
"(",
"ActiveScaffold",
"::",
"DataStructures",
"::",
"ActionLinks",
")",
"action",
"else",
"options",
"[",
":type",
"]",
"||=",
"default_type",
"if",
"default_type",
"ActiveScaffold",
"::",
"DataStructures",
"::",
"ActionLink",
".",
"new",
"(",
"action",
",",
"options",
")",
"end",
"# NOTE: this duplicate check should be done by defining the comparison operator for an Action data structure",
"existing",
"=",
"find_duplicate",
"(",
"link",
")",
"if",
"existing",
"existing",
"else",
"# That s for backwards compatibility if we are in root of action_links",
"# we have to move actionlink into members or collection subgroup",
"group",
"=",
"(",
"name",
"==",
":root",
"?",
"subgroup",
"(",
"link",
".",
"type",
",",
"link",
".",
"type",
")",
":",
"self",
")",
"group",
".",
"add_to_set",
"(",
"link",
")",
"link",
"end",
"end"
] |
adds an ActionLink, creating one from the arguments if need be
|
[
"adds",
"an",
"ActionLink",
"creating",
"one",
"from",
"the",
"arguments",
"if",
"need",
"be"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/action_links.rb#L13-L33
|
14,379
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/action_links.rb
|
ActiveScaffold::DataStructures.ActionLinks.add_to_group
|
def add_to_group(link, group_name = nil)
add_to = root
add_to = group_name.split('.').inject(root) { |group, name| group.send(name) } if group_name
add_to << link unless link.nil?
end
|
ruby
|
def add_to_group(link, group_name = nil)
add_to = root
add_to = group_name.split('.').inject(root) { |group, name| group.send(name) } if group_name
add_to << link unless link.nil?
end
|
[
"def",
"add_to_group",
"(",
"link",
",",
"group_name",
"=",
"nil",
")",
"add_to",
"=",
"root",
"add_to",
"=",
"group_name",
".",
"split",
"(",
"'.'",
")",
".",
"inject",
"(",
"root",
")",
"{",
"|",
"group",
",",
"name",
"|",
"group",
".",
"send",
"(",
"name",
")",
"}",
"if",
"group_name",
"add_to",
"<<",
"link",
"unless",
"link",
".",
"nil?",
"end"
] |
adds a link to a specific group
groups are represented as a string separated by a dot
eg member.crud
|
[
"adds",
"a",
"link",
"to",
"a",
"specific",
"group",
"groups",
"are",
"represented",
"as",
"a",
"string",
"separated",
"by",
"a",
"dot",
"eg",
"member",
".",
"crud"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/action_links.rb#L43-L47
|
14,380
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/action_links.rb
|
ActiveScaffold::DataStructures.ActionLinks.[]
|
def [](val)
links = []
@set.each do |item|
if item.is_a?(ActiveScaffold::DataStructures::ActionLinks)
collected = item[val]
links << collected unless collected.nil?
elsif item.action.to_s == val.to_s
links << item
end
end
links.first
end
|
ruby
|
def [](val)
links = []
@set.each do |item|
if item.is_a?(ActiveScaffold::DataStructures::ActionLinks)
collected = item[val]
links << collected unless collected.nil?
elsif item.action.to_s == val.to_s
links << item
end
end
links.first
end
|
[
"def",
"[]",
"(",
"val",
")",
"links",
"=",
"[",
"]",
"@set",
".",
"each",
"do",
"|",
"item",
"|",
"if",
"item",
".",
"is_a?",
"(",
"ActiveScaffold",
"::",
"DataStructures",
"::",
"ActionLinks",
")",
"collected",
"=",
"item",
"[",
"val",
"]",
"links",
"<<",
"collected",
"unless",
"collected",
".",
"nil?",
"elsif",
"item",
".",
"action",
".",
"to_s",
"==",
"val",
".",
"to_s",
"links",
"<<",
"item",
"end",
"end",
"links",
".",
"first",
"end"
] |
finds an ActionLink by matching the action
|
[
"finds",
"an",
"ActionLink",
"by",
"matching",
"the",
"action"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/action_links.rb#L50-L61
|
14,381
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/action_links.rb
|
ActiveScaffold::DataStructures.ActionLinks.each
|
def each(options = {}, &block)
method = options[:reverse] ? :reverse_each : :each
@set.sort_by(&:weight).send(method) do |item|
if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) && !options[:groups]
item.each(options, &block)
elsif options[:include_set]
yield item, @set
else
yield item
end
end
end
|
ruby
|
def each(options = {}, &block)
method = options[:reverse] ? :reverse_each : :each
@set.sort_by(&:weight).send(method) do |item|
if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) && !options[:groups]
item.each(options, &block)
elsif options[:include_set]
yield item, @set
else
yield item
end
end
end
|
[
"def",
"each",
"(",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"method",
"=",
"options",
"[",
":reverse",
"]",
"?",
":reverse_each",
":",
":each",
"@set",
".",
"sort_by",
"(",
":weight",
")",
".",
"send",
"(",
"method",
")",
"do",
"|",
"item",
"|",
"if",
"item",
".",
"is_a?",
"(",
"ActiveScaffold",
"::",
"DataStructures",
"::",
"ActionLinks",
")",
"&&",
"!",
"options",
"[",
":groups",
"]",
"item",
".",
"each",
"(",
"options",
",",
"block",
")",
"elsif",
"options",
"[",
":include_set",
"]",
"yield",
"item",
",",
"@set",
"else",
"yield",
"item",
"end",
"end",
"end"
] |
iterates over the links, possibly by type
|
[
"iterates",
"over",
"the",
"links",
"possibly",
"by",
"type"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/action_links.rb#L98-L109
|
14,382
|
activescaffold/active_scaffold
|
lib/active_scaffold/data_structures/action_columns.rb
|
ActiveScaffold::DataStructures.ActionColumns.add_subgroup
|
def add_subgroup(label, &proc)
columns = ActiveScaffold::DataStructures::ActionColumns.new
columns.label = label
columns.action = action
columns.configure(&proc)
exclude columns.collect_columns
add columns
end
|
ruby
|
def add_subgroup(label, &proc)
columns = ActiveScaffold::DataStructures::ActionColumns.new
columns.label = label
columns.action = action
columns.configure(&proc)
exclude columns.collect_columns
add columns
end
|
[
"def",
"add_subgroup",
"(",
"label",
",",
"&",
"proc",
")",
"columns",
"=",
"ActiveScaffold",
"::",
"DataStructures",
"::",
"ActionColumns",
".",
"new",
"columns",
".",
"label",
"=",
"label",
"columns",
".",
"action",
"=",
"action",
"columns",
".",
"configure",
"(",
"proc",
")",
"exclude",
"columns",
".",
"collect_columns",
"add",
"columns",
"end"
] |
nests a subgroup in the column set
|
[
"nests",
"a",
"subgroup",
"in",
"the",
"column",
"set"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/data_structures/action_columns.rb#L38-L45
|
14,383
|
activescaffold/active_scaffold
|
lib/active_scaffold/actions/delete.rb
|
ActiveScaffold::Actions.Delete.do_destroy
|
def do_destroy(record)
record ||= destroy_find_record
begin
self.successful = record.destroy
rescue StandardError => exception
flash[:warning] = as_(:cant_destroy_record, :record => ERB::Util.h(record.to_label))
self.successful = false
logger.warn do
"\n\n#{exception.class} (#{exception.message}):\n " +
Rails.backtrace_cleaner.clean(exception.backtrace).join("\n ") +
"\n\n"
end
end
end
|
ruby
|
def do_destroy(record)
record ||= destroy_find_record
begin
self.successful = record.destroy
rescue StandardError => exception
flash[:warning] = as_(:cant_destroy_record, :record => ERB::Util.h(record.to_label))
self.successful = false
logger.warn do
"\n\n#{exception.class} (#{exception.message}):\n " +
Rails.backtrace_cleaner.clean(exception.backtrace).join("\n ") +
"\n\n"
end
end
end
|
[
"def",
"do_destroy",
"(",
"record",
")",
"record",
"||=",
"destroy_find_record",
"begin",
"self",
".",
"successful",
"=",
"record",
".",
"destroy",
"rescue",
"StandardError",
"=>",
"exception",
"flash",
"[",
":warning",
"]",
"=",
"as_",
"(",
":cant_destroy_record",
",",
":record",
"=>",
"ERB",
"::",
"Util",
".",
"h",
"(",
"record",
".",
"to_label",
")",
")",
"self",
".",
"successful",
"=",
"false",
"logger",
".",
"warn",
"do",
"\"\\n\\n#{exception.class} (#{exception.message}):\\n \"",
"+",
"Rails",
".",
"backtrace_cleaner",
".",
"clean",
"(",
"exception",
".",
"backtrace",
")",
".",
"join",
"(",
"\"\\n \"",
")",
"+",
"\"\\n\\n\"",
"end",
"end",
"end"
] |
A simple method to handle the actual destroying of a record
May be overridden to customize the behavior
|
[
"A",
"simple",
"method",
"to",
"handle",
"the",
"actual",
"destroying",
"of",
"a",
"record",
"May",
"be",
"overridden",
"to",
"customize",
"the",
"behavior"
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/actions/delete.rb#L40-L53
|
14,384
|
activescaffold/active_scaffold
|
lib/active_scaffold/constraints.rb
|
ActiveScaffold.Constraints.conditions_from_constraints
|
def conditions_from_constraints
hash_conditions = {}
conditions = [hash_conditions]
active_scaffold_constraints.each do |k, v|
column = active_scaffold_config.columns[k]
if column
# Assume this is a multi-level association constraint.
# example:
# data model: Park -> Den -> Bear
# constraint: :den => {:park => 5}
if params_hash? v
far_association = column.association.klass.reflect_on_association(v.keys.first)
field = far_association.klass.primary_key
table = far_association.table_name
active_scaffold_references.concat([{k => far_association.name}]) # e.g. {:den => :park}
hash_conditions.deep_merge!(table => {field => v.values.first})
# association column constraint
elsif column.association
join_from_association_constraint(column)
hash_conditions.deep_merge!(condition_from_association_constraint(column.association, v))
# regular column constraints
elsif column.searchable? && params[column.name] != v
active_scaffold_references.concat column.references if column.includes.present?
conditions << [column.search_sql.collect { |search_sql| "#{search_sql} = ?" }.join(' OR '), *([v] * column.search_sql.size)]
end
# unknown-to-activescaffold-but-real-database-column constraint
elsif active_scaffold_config.model.columns_hash[k.to_s] && params[column.name] != v
hash_conditions.deep_merge!(k => v)
else
raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, k), caller
end
end
conditions.reject(&:blank?)
end
|
ruby
|
def conditions_from_constraints
hash_conditions = {}
conditions = [hash_conditions]
active_scaffold_constraints.each do |k, v|
column = active_scaffold_config.columns[k]
if column
# Assume this is a multi-level association constraint.
# example:
# data model: Park -> Den -> Bear
# constraint: :den => {:park => 5}
if params_hash? v
far_association = column.association.klass.reflect_on_association(v.keys.first)
field = far_association.klass.primary_key
table = far_association.table_name
active_scaffold_references.concat([{k => far_association.name}]) # e.g. {:den => :park}
hash_conditions.deep_merge!(table => {field => v.values.first})
# association column constraint
elsif column.association
join_from_association_constraint(column)
hash_conditions.deep_merge!(condition_from_association_constraint(column.association, v))
# regular column constraints
elsif column.searchable? && params[column.name] != v
active_scaffold_references.concat column.references if column.includes.present?
conditions << [column.search_sql.collect { |search_sql| "#{search_sql} = ?" }.join(' OR '), *([v] * column.search_sql.size)]
end
# unknown-to-activescaffold-but-real-database-column constraint
elsif active_scaffold_config.model.columns_hash[k.to_s] && params[column.name] != v
hash_conditions.deep_merge!(k => v)
else
raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, k), caller
end
end
conditions.reject(&:blank?)
end
|
[
"def",
"conditions_from_constraints",
"hash_conditions",
"=",
"{",
"}",
"conditions",
"=",
"[",
"hash_conditions",
"]",
"active_scaffold_constraints",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"column",
"=",
"active_scaffold_config",
".",
"columns",
"[",
"k",
"]",
"if",
"column",
"# Assume this is a multi-level association constraint.",
"# example:",
"# data model: Park -> Den -> Bear",
"# constraint: :den => {:park => 5}",
"if",
"params_hash?",
"v",
"far_association",
"=",
"column",
".",
"association",
".",
"klass",
".",
"reflect_on_association",
"(",
"v",
".",
"keys",
".",
"first",
")",
"field",
"=",
"far_association",
".",
"klass",
".",
"primary_key",
"table",
"=",
"far_association",
".",
"table_name",
"active_scaffold_references",
".",
"concat",
"(",
"[",
"{",
"k",
"=>",
"far_association",
".",
"name",
"}",
"]",
")",
"# e.g. {:den => :park}",
"hash_conditions",
".",
"deep_merge!",
"(",
"table",
"=>",
"{",
"field",
"=>",
"v",
".",
"values",
".",
"first",
"}",
")",
"# association column constraint",
"elsif",
"column",
".",
"association",
"join_from_association_constraint",
"(",
"column",
")",
"hash_conditions",
".",
"deep_merge!",
"(",
"condition_from_association_constraint",
"(",
"column",
".",
"association",
",",
"v",
")",
")",
"# regular column constraints",
"elsif",
"column",
".",
"searchable?",
"&&",
"params",
"[",
"column",
".",
"name",
"]",
"!=",
"v",
"active_scaffold_references",
".",
"concat",
"column",
".",
"references",
"if",
"column",
".",
"includes",
".",
"present?",
"conditions",
"<<",
"[",
"column",
".",
"search_sql",
".",
"collect",
"{",
"|",
"search_sql",
"|",
"\"#{search_sql} = ?\"",
"}",
".",
"join",
"(",
"' OR '",
")",
",",
"(",
"[",
"v",
"]",
"*",
"column",
".",
"search_sql",
".",
"size",
")",
"]",
"end",
"# unknown-to-activescaffold-but-real-database-column constraint",
"elsif",
"active_scaffold_config",
".",
"model",
".",
"columns_hash",
"[",
"k",
".",
"to_s",
"]",
"&&",
"params",
"[",
"column",
".",
"name",
"]",
"!=",
"v",
"hash_conditions",
".",
"deep_merge!",
"(",
"k",
"=>",
"v",
")",
"else",
"raise",
"ActiveScaffold",
"::",
"MalformedConstraint",
",",
"constraint_error",
"(",
"active_scaffold_config",
".",
"model",
",",
"k",
")",
",",
"caller",
"end",
"end",
"conditions",
".",
"reject",
"(",
":blank?",
")",
"end"
] |
Returns search conditions based on the current scaffold constraints.
Supports constraints based on either a column name (in which case it checks for an association
or just uses the search_sql) or a database field name.
All of this work is primarily to support nested scaffolds in a manner generally useful for other
embedded scaffolds.
|
[
"Returns",
"search",
"conditions",
"based",
"on",
"the",
"current",
"scaffold",
"constraints",
"."
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/constraints.rb#L44-L80
|
14,385
|
activescaffold/active_scaffold
|
lib/active_scaffold/constraints.rb
|
ActiveScaffold.Constraints.condition_from_association_constraint
|
def condition_from_association_constraint(association, value)
# when the reverse association is a :belongs_to, the id for the associated object only exists as
# the primary_key on the other table. so for :has_one and :has_many (when the reverse is :belongs_to),
# we have to use the other model's primary_key.
#
# please see the relevant tests for concrete examples.
field =
if association.belongs_to?
association.foreign_key
else
association.klass.primary_key
end
table = association.belongs_to? ? active_scaffold_config.model.table_name : association.table_name
value = association.klass.find(value).send(association.primary_key) if association.primary_key
if association.polymorphic?
unless value.is_a?(Array) && value.size == 2
raise ActiveScaffold::MalformedConstraint, polymorphic_constraint_error(association), caller
end
condition = {table => {association.foreign_type => value[0], field => value[1]}}
else
condition = {table => {field.to_s => value}}
end
condition
end
|
ruby
|
def condition_from_association_constraint(association, value)
# when the reverse association is a :belongs_to, the id for the associated object only exists as
# the primary_key on the other table. so for :has_one and :has_many (when the reverse is :belongs_to),
# we have to use the other model's primary_key.
#
# please see the relevant tests for concrete examples.
field =
if association.belongs_to?
association.foreign_key
else
association.klass.primary_key
end
table = association.belongs_to? ? active_scaffold_config.model.table_name : association.table_name
value = association.klass.find(value).send(association.primary_key) if association.primary_key
if association.polymorphic?
unless value.is_a?(Array) && value.size == 2
raise ActiveScaffold::MalformedConstraint, polymorphic_constraint_error(association), caller
end
condition = {table => {association.foreign_type => value[0], field => value[1]}}
else
condition = {table => {field.to_s => value}}
end
condition
end
|
[
"def",
"condition_from_association_constraint",
"(",
"association",
",",
"value",
")",
"# when the reverse association is a :belongs_to, the id for the associated object only exists as",
"# the primary_key on the other table. so for :has_one and :has_many (when the reverse is :belongs_to),",
"# we have to use the other model's primary_key.",
"#",
"# please see the relevant tests for concrete examples.",
"field",
"=",
"if",
"association",
".",
"belongs_to?",
"association",
".",
"foreign_key",
"else",
"association",
".",
"klass",
".",
"primary_key",
"end",
"table",
"=",
"association",
".",
"belongs_to?",
"?",
"active_scaffold_config",
".",
"model",
".",
"table_name",
":",
"association",
".",
"table_name",
"value",
"=",
"association",
".",
"klass",
".",
"find",
"(",
"value",
")",
".",
"send",
"(",
"association",
".",
"primary_key",
")",
"if",
"association",
".",
"primary_key",
"if",
"association",
".",
"polymorphic?",
"unless",
"value",
".",
"is_a?",
"(",
"Array",
")",
"&&",
"value",
".",
"size",
"==",
"2",
"raise",
"ActiveScaffold",
"::",
"MalformedConstraint",
",",
"polymorphic_constraint_error",
"(",
"association",
")",
",",
"caller",
"end",
"condition",
"=",
"{",
"table",
"=>",
"{",
"association",
".",
"foreign_type",
"=>",
"value",
"[",
"0",
"]",
",",
"field",
"=>",
"value",
"[",
"1",
"]",
"}",
"}",
"else",
"condition",
"=",
"{",
"table",
"=>",
"{",
"field",
".",
"to_s",
"=>",
"value",
"}",
"}",
"end",
"condition",
"end"
] |
We do NOT want to use .search_sql. If anything, search_sql will refer
to a human-searchable value on the associated record.
|
[
"We",
"do",
"NOT",
"want",
"to",
"use",
".",
"search_sql",
".",
"If",
"anything",
"search_sql",
"will",
"refer",
"to",
"a",
"human",
"-",
"searchable",
"value",
"on",
"the",
"associated",
"record",
"."
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/constraints.rb#L96-L123
|
14,386
|
activescaffold/active_scaffold
|
lib/active_scaffold/constraints.rb
|
ActiveScaffold.Constraints.apply_constraints_to_record
|
def apply_constraints_to_record(record, options = {})
options[:allow_autosave] = false if options[:allow_autosave].nil?
constraints = options[:constraints] || active_scaffold_constraints
config = record.is_a?(active_scaffold_config.model) ? active_scaffold_config : active_scaffold_config_for(record.class)
constraints.each do |k, v|
column = config.columns[k]
if column&.association
if column.association.collection?
record.send(k.to_s).send(:<<, column.association.klass.find(v))
elsif column.association.polymorphic?
unless v.is_a?(Array) && v.size == 2
raise ActiveScaffold::MalformedConstraint, polymorphic_constraint_error(column.association), caller
end
record.send("#{k}=", v[0].constantize.find(v[1]))
else # regular singular association
record.send("#{k}=", column.association.klass.find(v))
# setting the belongs_to side of a has_one isn't safe. if the has_one was already
# specified, rails won't automatically clear out the previous associated record.
#
# note that we can't take the extra step to correct this unless we're permitted to
# run operations where activerecord auto-saves the object.
reverse = column.association.reverse_association
if reverse.singular? && !reverse.belongs_to? && options[:allow_autosave]
record.send(k).send("#{reverse.name}=", record)
end
end
else
record.send("#{k}=", v)
end
end
end
|
ruby
|
def apply_constraints_to_record(record, options = {})
options[:allow_autosave] = false if options[:allow_autosave].nil?
constraints = options[:constraints] || active_scaffold_constraints
config = record.is_a?(active_scaffold_config.model) ? active_scaffold_config : active_scaffold_config_for(record.class)
constraints.each do |k, v|
column = config.columns[k]
if column&.association
if column.association.collection?
record.send(k.to_s).send(:<<, column.association.klass.find(v))
elsif column.association.polymorphic?
unless v.is_a?(Array) && v.size == 2
raise ActiveScaffold::MalformedConstraint, polymorphic_constraint_error(column.association), caller
end
record.send("#{k}=", v[0].constantize.find(v[1]))
else # regular singular association
record.send("#{k}=", column.association.klass.find(v))
# setting the belongs_to side of a has_one isn't safe. if the has_one was already
# specified, rails won't automatically clear out the previous associated record.
#
# note that we can't take the extra step to correct this unless we're permitted to
# run operations where activerecord auto-saves the object.
reverse = column.association.reverse_association
if reverse.singular? && !reverse.belongs_to? && options[:allow_autosave]
record.send(k).send("#{reverse.name}=", record)
end
end
else
record.send("#{k}=", v)
end
end
end
|
[
"def",
"apply_constraints_to_record",
"(",
"record",
",",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":allow_autosave",
"]",
"=",
"false",
"if",
"options",
"[",
":allow_autosave",
"]",
".",
"nil?",
"constraints",
"=",
"options",
"[",
":constraints",
"]",
"||",
"active_scaffold_constraints",
"config",
"=",
"record",
".",
"is_a?",
"(",
"active_scaffold_config",
".",
"model",
")",
"?",
"active_scaffold_config",
":",
"active_scaffold_config_for",
"(",
"record",
".",
"class",
")",
"constraints",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"column",
"=",
"config",
".",
"columns",
"[",
"k",
"]",
"if",
"column",
"&.",
"association",
"if",
"column",
".",
"association",
".",
"collection?",
"record",
".",
"send",
"(",
"k",
".",
"to_s",
")",
".",
"send",
"(",
":<<",
",",
"column",
".",
"association",
".",
"klass",
".",
"find",
"(",
"v",
")",
")",
"elsif",
"column",
".",
"association",
".",
"polymorphic?",
"unless",
"v",
".",
"is_a?",
"(",
"Array",
")",
"&&",
"v",
".",
"size",
"==",
"2",
"raise",
"ActiveScaffold",
"::",
"MalformedConstraint",
",",
"polymorphic_constraint_error",
"(",
"column",
".",
"association",
")",
",",
"caller",
"end",
"record",
".",
"send",
"(",
"\"#{k}=\"",
",",
"v",
"[",
"0",
"]",
".",
"constantize",
".",
"find",
"(",
"v",
"[",
"1",
"]",
")",
")",
"else",
"# regular singular association",
"record",
".",
"send",
"(",
"\"#{k}=\"",
",",
"column",
".",
"association",
".",
"klass",
".",
"find",
"(",
"v",
")",
")",
"# setting the belongs_to side of a has_one isn't safe. if the has_one was already",
"# specified, rails won't automatically clear out the previous associated record.",
"#",
"# note that we can't take the extra step to correct this unless we're permitted to",
"# run operations where activerecord auto-saves the object.",
"reverse",
"=",
"column",
".",
"association",
".",
"reverse_association",
"if",
"reverse",
".",
"singular?",
"&&",
"!",
"reverse",
".",
"belongs_to?",
"&&",
"options",
"[",
":allow_autosave",
"]",
"record",
".",
"send",
"(",
"k",
")",
".",
"send",
"(",
"\"#{reverse.name}=\"",
",",
"record",
")",
"end",
"end",
"else",
"record",
".",
"send",
"(",
"\"#{k}=\"",
",",
"v",
")",
"end",
"end",
"end"
] |
Applies constraints to the given record.
Searches through the known columns for association columns. If the given constraint is an association,
it assumes that the constraint value is an id. It then does a association.klass.find with the value
and adds the associated object to the record.
For some operations ActiveRecord will automatically update the database. That's not always ok.
If it *is* ok (e.g. you're in a transaction), then set :allow_autosave to true.
|
[
"Applies",
"constraints",
"to",
"the",
"given",
"record",
"."
] |
1954f85b5395d09de09fa86f3ea70c29bbee2612
|
https://github.com/activescaffold/active_scaffold/blob/1954f85b5395d09de09fa86f3ea70c29bbee2612/lib/active_scaffold/constraints.rb#L141-L173
|
14,387
|
rossta/montrose
|
lib/montrose/schedule.rb
|
Montrose.Schedule.events
|
def events(opts = {})
enums = @rules.map { |r| r.merge(opts).events }
Enumerator.new do |y|
loop do
enum = active_enums(enums).min_by(&:peek) or break
y << enum.next
end
end
end
|
ruby
|
def events(opts = {})
enums = @rules.map { |r| r.merge(opts).events }
Enumerator.new do |y|
loop do
enum = active_enums(enums).min_by(&:peek) or break
y << enum.next
end
end
end
|
[
"def",
"events",
"(",
"opts",
"=",
"{",
"}",
")",
"enums",
"=",
"@rules",
".",
"map",
"{",
"|",
"r",
"|",
"r",
".",
"merge",
"(",
"opts",
")",
".",
"events",
"}",
"Enumerator",
".",
"new",
"do",
"|",
"y",
"|",
"loop",
"do",
"enum",
"=",
"active_enums",
"(",
"enums",
")",
".",
"min_by",
"(",
":peek",
")",
"or",
"break",
"y",
"<<",
"enum",
".",
"next",
"end",
"end",
"end"
] |
Returns an enumerator for iterating over timestamps in the schedule
@example Return the events
schedule = Montrose::Schedule.build do |s|
s << { every: :day }
end
schedule.events
@return [Enumerator] an enumerator of recurrence timestamps
|
[
"Returns",
"an",
"enumerator",
"for",
"iterating",
"over",
"timestamps",
"in",
"the",
"schedule"
] |
91af7d2d5c337aa255510179d24eb023775674bb
|
https://github.com/rossta/montrose/blob/91af7d2d5c337aa255510179d24eb023775674bb/lib/montrose/schedule.rb#L72-L80
|
14,388
|
rossta/montrose
|
lib/montrose/stack.rb
|
Montrose.Stack.advance
|
def advance(time)
yes, no = @stack.partition { |rule| rule.include?(time) }
if no.empty?
yes.all? { |rule| rule.advance!(time) } or return false
puts time if ENV["DEBUG"]
yield time if block_given?
true
else
no.any? { |rule| rule.continue?(time) }
end
end
|
ruby
|
def advance(time)
yes, no = @stack.partition { |rule| rule.include?(time) }
if no.empty?
yes.all? { |rule| rule.advance!(time) } or return false
puts time if ENV["DEBUG"]
yield time if block_given?
true
else
no.any? { |rule| rule.continue?(time) }
end
end
|
[
"def",
"advance",
"(",
"time",
")",
"yes",
",",
"no",
"=",
"@stack",
".",
"partition",
"{",
"|",
"rule",
"|",
"rule",
".",
"include?",
"(",
"time",
")",
"}",
"if",
"no",
".",
"empty?",
"yes",
".",
"all?",
"{",
"|",
"rule",
"|",
"rule",
".",
"advance!",
"(",
"time",
")",
"}",
"or",
"return",
"false",
"puts",
"time",
"if",
"ENV",
"[",
"\"DEBUG\"",
"]",
"yield",
"time",
"if",
"block_given?",
"true",
"else",
"no",
".",
"any?",
"{",
"|",
"rule",
"|",
"rule",
".",
"continue?",
"(",
"time",
")",
"}",
"end",
"end"
] |
Given a time instance, advances state of when all
recurrence rules on the stack match, and yielding
time to the block, otherwise, invokes break? on
non-matching rules.
@param [Time] time - time instance candidate for recurrence
|
[
"Given",
"a",
"time",
"instance",
"advances",
"state",
"of",
"when",
"all",
"recurrence",
"rules",
"on",
"the",
"stack",
"match",
"and",
"yielding",
"time",
"to",
"the",
"block",
"otherwise",
"invokes",
"break?",
"on",
"non",
"-",
"matching",
"rules",
"."
] |
91af7d2d5c337aa255510179d24eb023775674bb
|
https://github.com/rossta/montrose/blob/91af7d2d5c337aa255510179d24eb023775674bb/lib/montrose/stack.rb#L42-L53
|
14,389
|
mailgun/mailgun-ruby
|
lib/mailgun/messages/message_builder.rb
|
Mailgun.MessageBuilder.add_campaign_id
|
def add_campaign_id(campaign_id)
fail(Mailgun::ParameterError, 'Too many campaigns added to message.', campaign_id) if @counters[:attributes][:campaign_id] >= Mailgun::Chains::MAX_CAMPAIGN_IDS
set_multi_complex('o:campaign', campaign_id)
@counters[:attributes][:campaign_id] += 1
end
|
ruby
|
def add_campaign_id(campaign_id)
fail(Mailgun::ParameterError, 'Too many campaigns added to message.', campaign_id) if @counters[:attributes][:campaign_id] >= Mailgun::Chains::MAX_CAMPAIGN_IDS
set_multi_complex('o:campaign', campaign_id)
@counters[:attributes][:campaign_id] += 1
end
|
[
"def",
"add_campaign_id",
"(",
"campaign_id",
")",
"fail",
"(",
"Mailgun",
"::",
"ParameterError",
",",
"'Too many campaigns added to message.'",
",",
"campaign_id",
")",
"if",
"@counters",
"[",
":attributes",
"]",
"[",
":campaign_id",
"]",
">=",
"Mailgun",
"::",
"Chains",
"::",
"MAX_CAMPAIGN_IDS",
"set_multi_complex",
"(",
"'o:campaign'",
",",
"campaign_id",
")",
"@counters",
"[",
":attributes",
"]",
"[",
":campaign_id",
"]",
"+=",
"1",
"end"
] |
Add campaign IDs to message. Limit of 3 per message.
@param [String] campaign_id A defined campaign ID to add to the message.
@return [void]
|
[
"Add",
"campaign",
"IDs",
"to",
"message",
".",
"Limit",
"of",
"3",
"per",
"message",
"."
] |
265efffd51209b0170a3225bbe945b649643465a
|
https://github.com/mailgun/mailgun-ruby/blob/265efffd51209b0170a3225bbe945b649643465a/lib/mailgun/messages/message_builder.rb#L176-L181
|
14,390
|
mailgun/mailgun-ruby
|
lib/mailgun/messages/message_builder.rb
|
Mailgun.MessageBuilder.add_tag
|
def add_tag(tag)
if @counters[:attributes][:tag] >= Mailgun::Chains::MAX_TAGS
fail Mailgun::ParameterError, 'Too many tags added to message.', tag
end
set_multi_complex('o:tag', tag)
@counters[:attributes][:tag] += 1
end
|
ruby
|
def add_tag(tag)
if @counters[:attributes][:tag] >= Mailgun::Chains::MAX_TAGS
fail Mailgun::ParameterError, 'Too many tags added to message.', tag
end
set_multi_complex('o:tag', tag)
@counters[:attributes][:tag] += 1
end
|
[
"def",
"add_tag",
"(",
"tag",
")",
"if",
"@counters",
"[",
":attributes",
"]",
"[",
":tag",
"]",
">=",
"Mailgun",
"::",
"Chains",
"::",
"MAX_TAGS",
"fail",
"Mailgun",
"::",
"ParameterError",
",",
"'Too many tags added to message.'",
",",
"tag",
"end",
"set_multi_complex",
"(",
"'o:tag'",
",",
"tag",
")",
"@counters",
"[",
":attributes",
"]",
"[",
":tag",
"]",
"+=",
"1",
"end"
] |
Add tags to message. Limit of 3 per message.
@param [String] tag A defined campaign ID to add to the message.
@return [void]
|
[
"Add",
"tags",
"to",
"message",
".",
"Limit",
"of",
"3",
"per",
"message",
"."
] |
265efffd51209b0170a3225bbe945b649643465a
|
https://github.com/mailgun/mailgun-ruby/blob/265efffd51209b0170a3225bbe945b649643465a/lib/mailgun/messages/message_builder.rb#L187-L193
|
14,391
|
mailgun/mailgun-ruby
|
lib/mailgun/messages/message_builder.rb
|
Mailgun.MessageBuilder.header
|
def header(name, data)
fail(Mailgun::ParameterError, 'Header name for message must be specified') if name.to_s.empty?
begin
jsondata = make_json data
set_single("h:#{name}", jsondata)
rescue Mailgun::ParameterError
set_single("h:#{name}", data)
end
end
|
ruby
|
def header(name, data)
fail(Mailgun::ParameterError, 'Header name for message must be specified') if name.to_s.empty?
begin
jsondata = make_json data
set_single("h:#{name}", jsondata)
rescue Mailgun::ParameterError
set_single("h:#{name}", data)
end
end
|
[
"def",
"header",
"(",
"name",
",",
"data",
")",
"fail",
"(",
"Mailgun",
"::",
"ParameterError",
",",
"'Header name for message must be specified'",
")",
"if",
"name",
".",
"to_s",
".",
"empty?",
"begin",
"jsondata",
"=",
"make_json",
"data",
"set_single",
"(",
"\"h:#{name}\"",
",",
"jsondata",
")",
"rescue",
"Mailgun",
"::",
"ParameterError",
"set_single",
"(",
"\"h:#{name}\"",
",",
"data",
")",
"end",
"end"
] |
Add custom data to the message. The data should be either a hash or JSON
encoded. The custom data will be added as a header to your message.
@param [string] name A name for the custom data. (Ex. X-Mailgun-<Name of Data>: {})
@param [Hash] data Either a hash or JSON string.
@return [void]
|
[
"Add",
"custom",
"data",
"to",
"the",
"message",
".",
"The",
"data",
"should",
"be",
"either",
"a",
"hash",
"or",
"JSON",
"encoded",
".",
"The",
"custom",
"data",
"will",
"be",
"added",
"as",
"a",
"header",
"to",
"your",
"message",
"."
] |
265efffd51209b0170a3225bbe945b649643465a
|
https://github.com/mailgun/mailgun-ruby/blob/265efffd51209b0170a3225bbe945b649643465a/lib/mailgun/messages/message_builder.rb#L247-L255
|
14,392
|
mailgun/mailgun-ruby
|
lib/mailgun/messages/message_builder.rb
|
Mailgun.MessageBuilder.bool_lookup
|
def bool_lookup(value)
return 'yes' if %w(true yes yep).include? value.to_s.downcase
return 'no' if %w(false no nope).include? value.to_s.downcase
value
end
|
ruby
|
def bool_lookup(value)
return 'yes' if %w(true yes yep).include? value.to_s.downcase
return 'no' if %w(false no nope).include? value.to_s.downcase
value
end
|
[
"def",
"bool_lookup",
"(",
"value",
")",
"return",
"'yes'",
"if",
"%w(",
"true",
"yes",
"yep",
")",
".",
"include?",
"value",
".",
"to_s",
".",
"downcase",
"return",
"'no'",
"if",
"%w(",
"false",
"no",
"nope",
")",
".",
"include?",
"value",
".",
"to_s",
".",
"downcase",
"value",
"end"
] |
Converts boolean type to string
@param [String] value The item to convert
@return [void]
|
[
"Converts",
"boolean",
"type",
"to",
"string"
] |
265efffd51209b0170a3225bbe945b649643465a
|
https://github.com/mailgun/mailgun-ruby/blob/265efffd51209b0170a3225bbe945b649643465a/lib/mailgun/messages/message_builder.rb#L342-L346
|
14,393
|
mailgun/mailgun-ruby
|
lib/mailgun/messages/batch_message.rb
|
Mailgun.BatchMessage.send_message
|
def send_message
rkey = 'recipient-variables'
set_multi_simple rkey, JSON.generate(@recipient_variables)
@message[rkey] = @message[rkey].first if @message.key?(rkey)
response = @client.send_message(@domain, @message).to_h!
message_id = response['id'].gsub(/\>|\</, '')
@message_ids[message_id] = count_recipients
reset_message
end
|
ruby
|
def send_message
rkey = 'recipient-variables'
set_multi_simple rkey, JSON.generate(@recipient_variables)
@message[rkey] = @message[rkey].first if @message.key?(rkey)
response = @client.send_message(@domain, @message).to_h!
message_id = response['id'].gsub(/\>|\</, '')
@message_ids[message_id] = count_recipients
reset_message
end
|
[
"def",
"send_message",
"rkey",
"=",
"'recipient-variables'",
"set_multi_simple",
"rkey",
",",
"JSON",
".",
"generate",
"(",
"@recipient_variables",
")",
"@message",
"[",
"rkey",
"]",
"=",
"@message",
"[",
"rkey",
"]",
".",
"first",
"if",
"@message",
".",
"key?",
"(",
"rkey",
")",
"response",
"=",
"@client",
".",
"send_message",
"(",
"@domain",
",",
"@message",
")",
".",
"to_h!",
"message_id",
"=",
"response",
"[",
"'id'",
"]",
".",
"gsub",
"(",
"/",
"\\>",
"\\<",
"/",
",",
"''",
")",
"@message_ids",
"[",
"message_id",
"]",
"=",
"count_recipients",
"reset_message",
"end"
] |
This method initiates a batch send to the API. It formats the recipient
variables, posts to the API, gathers the message IDs, then flushes that data
to prepare for the next batch. This method implements the Mailgun Client, thus,
an exception will be thrown if a communication error occurs.
@return [Boolean]
|
[
"This",
"method",
"initiates",
"a",
"batch",
"send",
"to",
"the",
"API",
".",
"It",
"formats",
"the",
"recipient",
"variables",
"posts",
"to",
"the",
"API",
"gathers",
"the",
"message",
"IDs",
"then",
"flushes",
"that",
"data",
"to",
"prepare",
"for",
"the",
"next",
"batch",
".",
"This",
"method",
"implements",
"the",
"Mailgun",
"Client",
"thus",
"an",
"exception",
"will",
"be",
"thrown",
"if",
"a",
"communication",
"error",
"occurs",
"."
] |
265efffd51209b0170a3225bbe945b649643465a
|
https://github.com/mailgun/mailgun-ruby/blob/265efffd51209b0170a3225bbe945b649643465a/lib/mailgun/messages/batch_message.rb#L85-L94
|
14,394
|
mailgun/mailgun-ruby
|
lib/mailgun/messages/batch_message.rb
|
Mailgun.BatchMessage.store_recipient_variables
|
def store_recipient_variables(recipient_type, address, variables)
variables = { id: @counters[:recipients][recipient_type] } unless variables
@recipient_variables[address] = variables
end
|
ruby
|
def store_recipient_variables(recipient_type, address, variables)
variables = { id: @counters[:recipients][recipient_type] } unless variables
@recipient_variables[address] = variables
end
|
[
"def",
"store_recipient_variables",
"(",
"recipient_type",
",",
"address",
",",
"variables",
")",
"variables",
"=",
"{",
"id",
":",
"@counters",
"[",
":recipients",
"]",
"[",
"recipient_type",
"]",
"}",
"unless",
"variables",
"@recipient_variables",
"[",
"address",
"]",
"=",
"variables",
"end"
] |
This method stores recipient variables for each recipient added, if
variables exist.
|
[
"This",
"method",
"stores",
"recipient",
"variables",
"for",
"each",
"recipient",
"added",
"if",
"variables",
"exist",
"."
] |
265efffd51209b0170a3225bbe945b649643465a
|
https://github.com/mailgun/mailgun-ruby/blob/265efffd51209b0170a3225bbe945b649643465a/lib/mailgun/messages/batch_message.rb#L98-L101
|
14,395
|
mailgun/mailgun-ruby
|
lib/mailgun/response.rb
|
Mailgun.Response.to_yaml
|
def to_yaml
YAML.dump(to_h)
rescue => err
raise ParseError.new(err), err
end
|
ruby
|
def to_yaml
YAML.dump(to_h)
rescue => err
raise ParseError.new(err), err
end
|
[
"def",
"to_yaml",
"YAML",
".",
"dump",
"(",
"to_h",
")",
"rescue",
"=>",
"err",
"raise",
"ParseError",
".",
"new",
"(",
"err",
")",
",",
"err",
"end"
] |
Return response as Yaml
@return [String] A string containing response as YAML
|
[
"Return",
"response",
"as",
"Yaml"
] |
265efffd51209b0170a3225bbe945b649643465a
|
https://github.com/mailgun/mailgun-ruby/blob/265efffd51209b0170a3225bbe945b649643465a/lib/mailgun/response.rb#L47-L51
|
14,396
|
mailgun/mailgun-ruby
|
lib/railgun/mailer.rb
|
Railgun.Mailer.deliver!
|
def deliver!(mail)
mg_message = Railgun.transform_for_mailgun(mail)
response = @mg_client.send_message(@domain, mg_message)
if response.code == 200 then
mg_id = response.to_h['id']
mail.message_id = mg_id
end
response
end
|
ruby
|
def deliver!(mail)
mg_message = Railgun.transform_for_mailgun(mail)
response = @mg_client.send_message(@domain, mg_message)
if response.code == 200 then
mg_id = response.to_h['id']
mail.message_id = mg_id
end
response
end
|
[
"def",
"deliver!",
"(",
"mail",
")",
"mg_message",
"=",
"Railgun",
".",
"transform_for_mailgun",
"(",
"mail",
")",
"response",
"=",
"@mg_client",
".",
"send_message",
"(",
"@domain",
",",
"mg_message",
")",
"if",
"response",
".",
"code",
"==",
"200",
"then",
"mg_id",
"=",
"response",
".",
"to_h",
"[",
"'id'",
"]",
"mail",
".",
"message_id",
"=",
"mg_id",
"end",
"response",
"end"
] |
Initialize the Railgun mailer.
@param [Hash] config Hash of config values, typically from `app_config.action_mailer.mailgun_config`
|
[
"Initialize",
"the",
"Railgun",
"mailer",
"."
] |
265efffd51209b0170a3225bbe945b649643465a
|
https://github.com/mailgun/mailgun-ruby/blob/265efffd51209b0170a3225bbe945b649643465a/lib/railgun/mailer.rb#L42-L51
|
14,397
|
mailgun/mailgun-ruby
|
lib/mailgun/client.rb
|
Mailgun.Client.send_message
|
def send_message(working_domain, data)
if test_mode? then
Mailgun::Client.deliveries << data
return Response.from_hash(
{
:body => '{"id": "test-mode-mail@localhost", "message": "Queued. Thank you."}',
:code => 200,
}
)
end
case data
when Hash
# Remove nil values from the data hash
# Submitting nils to the API will likely cause an error.
# See also: https://github.com/mailgun/mailgun-ruby/issues/32
data = data.select { |k, v| v != nil }
if data.key?(:message)
if data[:message].is_a?(String)
data[:message] = convert_string_to_file(data[:message])
end
return post("#{working_domain}/messages.mime", data)
end
post("#{working_domain}/messages", data)
when MessageBuilder
post("#{working_domain}/messages", data.message)
else
fail ParameterError.new('Unknown data type for data parameter.', data)
end
end
|
ruby
|
def send_message(working_domain, data)
if test_mode? then
Mailgun::Client.deliveries << data
return Response.from_hash(
{
:body => '{"id": "test-mode-mail@localhost", "message": "Queued. Thank you."}',
:code => 200,
}
)
end
case data
when Hash
# Remove nil values from the data hash
# Submitting nils to the API will likely cause an error.
# See also: https://github.com/mailgun/mailgun-ruby/issues/32
data = data.select { |k, v| v != nil }
if data.key?(:message)
if data[:message].is_a?(String)
data[:message] = convert_string_to_file(data[:message])
end
return post("#{working_domain}/messages.mime", data)
end
post("#{working_domain}/messages", data)
when MessageBuilder
post("#{working_domain}/messages", data.message)
else
fail ParameterError.new('Unknown data type for data parameter.', data)
end
end
|
[
"def",
"send_message",
"(",
"working_domain",
",",
"data",
")",
"if",
"test_mode?",
"then",
"Mailgun",
"::",
"Client",
".",
"deliveries",
"<<",
"data",
"return",
"Response",
".",
"from_hash",
"(",
"{",
":body",
"=>",
"'{\"id\": \"test-mode-mail@localhost\", \"message\": \"Queued. Thank you.\"}'",
",",
":code",
"=>",
"200",
",",
"}",
")",
"end",
"case",
"data",
"when",
"Hash",
"# Remove nil values from the data hash",
"# Submitting nils to the API will likely cause an error.",
"# See also: https://github.com/mailgun/mailgun-ruby/issues/32",
"data",
"=",
"data",
".",
"select",
"{",
"|",
"k",
",",
"v",
"|",
"v",
"!=",
"nil",
"}",
"if",
"data",
".",
"key?",
"(",
":message",
")",
"if",
"data",
"[",
":message",
"]",
".",
"is_a?",
"(",
"String",
")",
"data",
"[",
":message",
"]",
"=",
"convert_string_to_file",
"(",
"data",
"[",
":message",
"]",
")",
"end",
"return",
"post",
"(",
"\"#{working_domain}/messages.mime\"",
",",
"data",
")",
"end",
"post",
"(",
"\"#{working_domain}/messages\"",
",",
"data",
")",
"when",
"MessageBuilder",
"post",
"(",
"\"#{working_domain}/messages\"",
",",
"data",
".",
"message",
")",
"else",
"fail",
"ParameterError",
".",
"new",
"(",
"'Unknown data type for data parameter.'",
",",
"data",
")",
"end",
"end"
] |
Simple Message Sending
@param [String] working_domain This is the domain you wish to send from.
@param [Hash] data This should be a standard Hash
containing required parameters for the requested resource.
@return [Mailgun::Response] A Mailgun::Response object.
|
[
"Simple",
"Message",
"Sending"
] |
265efffd51209b0170a3225bbe945b649643465a
|
https://github.com/mailgun/mailgun-ruby/blob/265efffd51209b0170a3225bbe945b649643465a/lib/mailgun/client.rb#L63-L93
|
14,398
|
mailgun/mailgun-ruby
|
lib/mailgun/client.rb
|
Mailgun.Client.post
|
def post(resource_path, data, headers = {})
response = @http_client[resource_path].post(data, headers)
Response.new(response)
rescue => err
raise communication_error err
end
|
ruby
|
def post(resource_path, data, headers = {})
response = @http_client[resource_path].post(data, headers)
Response.new(response)
rescue => err
raise communication_error err
end
|
[
"def",
"post",
"(",
"resource_path",
",",
"data",
",",
"headers",
"=",
"{",
"}",
")",
"response",
"=",
"@http_client",
"[",
"resource_path",
"]",
".",
"post",
"(",
"data",
",",
"headers",
")",
"Response",
".",
"new",
"(",
"response",
")",
"rescue",
"=>",
"err",
"raise",
"communication_error",
"err",
"end"
] |
Generic Mailgun POST Handler
@param [String] resource_path This is the API resource you wish to interact
with. Be sure to include your domain, where necessary.
@param [Hash] data This should be a standard Hash
containing required parameters for the requested resource.
@param [Hash] headers Additional headers to pass to the resource.
@return [Mailgun::Response] A Mailgun::Response object.
|
[
"Generic",
"Mailgun",
"POST",
"Handler"
] |
265efffd51209b0170a3225bbe945b649643465a
|
https://github.com/mailgun/mailgun-ruby/blob/265efffd51209b0170a3225bbe945b649643465a/lib/mailgun/client.rb#L103-L108
|
14,399
|
mailgun/mailgun-ruby
|
lib/mailgun/client.rb
|
Mailgun.Client.get
|
def get(resource_path, params = nil, accept = '*/*')
if params
response = @http_client[resource_path].get(params: params, accept: accept)
else
response = @http_client[resource_path].get(accept: accept)
end
Response.new(response)
rescue => err
raise communication_error err
end
|
ruby
|
def get(resource_path, params = nil, accept = '*/*')
if params
response = @http_client[resource_path].get(params: params, accept: accept)
else
response = @http_client[resource_path].get(accept: accept)
end
Response.new(response)
rescue => err
raise communication_error err
end
|
[
"def",
"get",
"(",
"resource_path",
",",
"params",
"=",
"nil",
",",
"accept",
"=",
"'*/*'",
")",
"if",
"params",
"response",
"=",
"@http_client",
"[",
"resource_path",
"]",
".",
"get",
"(",
"params",
":",
"params",
",",
"accept",
":",
"accept",
")",
"else",
"response",
"=",
"@http_client",
"[",
"resource_path",
"]",
".",
"get",
"(",
"accept",
":",
"accept",
")",
"end",
"Response",
".",
"new",
"(",
"response",
")",
"rescue",
"=>",
"err",
"raise",
"communication_error",
"err",
"end"
] |
Generic Mailgun GET Handler
@param [String] resource_path This is the API resource you wish to interact
with. Be sure to include your domain, where necessary.
@param [Hash] params This should be a standard Hash
containing required parameters for the requested resource.
@param [String] accept Acceptable Content-Type of the response body.
@return [Mailgun::Response] A Mailgun::Response object.
|
[
"Generic",
"Mailgun",
"GET",
"Handler"
] |
265efffd51209b0170a3225bbe945b649643465a
|
https://github.com/mailgun/mailgun-ruby/blob/265efffd51209b0170a3225bbe945b649643465a/lib/mailgun/client.rb#L118-L127
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.