aws_sdk 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/aws-sdk.rb +14 -0
- data/lib/aws.rb +49 -0
- data/lib/aws/api_config/AutoScaling-2011-01-01.yml +791 -0
- data/lib/aws/api_config/CloudFormation-2010-05-15.yml +303 -0
- data/lib/aws/api_config/DynamoDB-2011-12-05.yml +540 -0
- data/lib/aws/api_config/EC2-2011-12-15.yml +3638 -0
- data/lib/aws/api_config/EC2-2012-04-01.yml +3739 -0
- data/lib/aws/api_config/ELB-2011-08-15.yml +512 -0
- data/lib/aws/api_config/IAM-2010-05-08.yml +1221 -0
- data/lib/aws/api_config/SNS-2010-03-31.yml +248 -0
- data/lib/aws/api_config/SQS-2011-10-01.yml +314 -0
- data/lib/aws/api_config/STS-2011-06-15.yml +54 -0
- data/lib/aws/api_config/SimpleDB-2009-04-15.yml +305 -0
- data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +231 -0
- data/lib/aws/api_config/SimpleWorkflow-2012-01-25.yml +721 -0
- data/lib/aws/auto_scaling.rb +162 -0
- data/lib/aws/auto_scaling/activity.rb +102 -0
- data/lib/aws/auto_scaling/activity_collection.rb +82 -0
- data/lib/aws/auto_scaling/client.rb +765 -0
- data/lib/aws/auto_scaling/config.rb +18 -0
- data/lib/aws/auto_scaling/errors.rb +22 -0
- data/lib/aws/auto_scaling/group.rb +420 -0
- data/lib/aws/auto_scaling/group_collection.rb +96 -0
- data/lib/aws/auto_scaling/group_options.rb +146 -0
- data/lib/aws/auto_scaling/instance.rb +192 -0
- data/lib/aws/auto_scaling/instance_collection.rb +63 -0
- data/lib/aws/auto_scaling/launch_configuration.rb +150 -0
- data/lib/aws/auto_scaling/launch_configuration_collection.rb +144 -0
- data/lib/aws/auto_scaling/notification_configuration.rb +89 -0
- data/lib/aws/auto_scaling/notification_configuration_collection.rb +184 -0
- data/lib/aws/auto_scaling/request.rb +23 -0
- data/lib/aws/auto_scaling/scaling_policy.rb +125 -0
- data/lib/aws/auto_scaling/scaling_policy_collection.rb +72 -0
- data/lib/aws/auto_scaling/scaling_policy_options.rb +61 -0
- data/lib/aws/auto_scaling/scheduled_action.rb +145 -0
- data/lib/aws/auto_scaling/scheduled_action_collection.rb +195 -0
- data/lib/aws/auto_scaling/tag.rb +59 -0
- data/lib/aws/auto_scaling/tag_collection.rb +112 -0
- data/lib/aws/cloud_formation.rb +270 -0
- data/lib/aws/cloud_formation/client.rb +339 -0
- data/lib/aws/cloud_formation/config.rb +18 -0
- data/lib/aws/cloud_formation/errors.rb +22 -0
- data/lib/aws/cloud_formation/request.rb +29 -0
- data/lib/aws/cloud_formation/stack.rb +256 -0
- data/lib/aws/cloud_formation/stack_collection.rb +206 -0
- data/lib/aws/cloud_formation/stack_event.rb +75 -0
- data/lib/aws/cloud_formation/stack_event_collection.rb +47 -0
- data/lib/aws/cloud_formation/stack_options.rb +72 -0
- data/lib/aws/cloud_formation/stack_output.rb +53 -0
- data/lib/aws/cloud_formation/stack_resource.rb +117 -0
- data/lib/aws/cloud_formation/stack_resource_collection.rb +84 -0
- data/lib/aws/cloud_formation/stack_resource_summary_collection.rb +72 -0
- data/lib/aws/cloud_formation/stack_summary.rb +71 -0
- data/lib/aws/cloud_formation/stack_summary_collection.rb +127 -0
- data/lib/aws/core.rb +474 -0
- data/lib/aws/core/async_handle.rb +90 -0
- data/lib/aws/core/autoloader.rb +64 -0
- data/lib/aws/core/cacheable.rb +78 -0
- data/lib/aws/core/client.rb +541 -0
- data/lib/aws/core/client/query_json.rb +110 -0
- data/lib/aws/core/client/query_xml.rb +122 -0
- data/lib/aws/core/collection.rb +234 -0
- data/lib/aws/core/collection/limitable.rb +99 -0
- data/lib/aws/core/collection/simple.rb +90 -0
- data/lib/aws/core/configuration.rb +445 -0
- data/lib/aws/core/data.rb +242 -0
- data/lib/aws/core/default_signer.rb +67 -0
- data/lib/aws/core/http/curb_handler.rb +136 -0
- data/lib/aws/core/http/handler.rb +77 -0
- data/lib/aws/core/http/httparty_handler.rb +114 -0
- data/lib/aws/core/http/net_http_handler.rb +85 -0
- data/lib/aws/core/http/request.rb +250 -0
- data/lib/aws/core/http/response.rb +74 -0
- data/lib/aws/core/indifferent_hash.rb +88 -0
- data/lib/aws/core/inflection.rb +47 -0
- data/lib/aws/core/lazy_error_classes.rb +90 -0
- data/lib/aws/core/log_formatter.rb +454 -0
- data/lib/aws/core/meta_utils.rb +45 -0
- data/lib/aws/core/model.rb +57 -0
- data/lib/aws/core/naming.rb +30 -0
- data/lib/aws/core/option_grammar.rb +700 -0
- data/lib/aws/core/page_result.rb +73 -0
- data/lib/aws/core/policy.rb +916 -0
- data/lib/aws/core/resource.rb +408 -0
- data/lib/aws/core/resource_cache.rb +40 -0
- data/lib/aws/core/response.rb +202 -0
- data/lib/aws/core/response_cache.rb +50 -0
- data/lib/aws/core/service_interface.rb +61 -0
- data/lib/aws/core/session_signer.rb +90 -0
- data/lib/aws/core/signature/version_2.rb +42 -0
- data/lib/aws/core/signature/version_3.rb +73 -0
- data/lib/aws/core/signature/version_3_http.rb +72 -0
- data/lib/aws/core/signature/version_4.rb +138 -0
- data/lib/aws/core/uri_escape.rb +42 -0
- data/lib/aws/core/xml/frame.rb +242 -0
- data/lib/aws/core/xml/frame_stack.rb +85 -0
- data/lib/aws/core/xml/grammar.rb +299 -0
- data/lib/aws/core/xml/parser.rb +70 -0
- data/lib/aws/core/xml/root_frame.rb +65 -0
- data/lib/aws/core/xml/sax_handlers/libxml.rb +47 -0
- data/lib/aws/core/xml/sax_handlers/nokogiri.rb +55 -0
- data/lib/aws/core/xml/sax_handlers/ox.rb +41 -0
- data/lib/aws/core/xml/sax_handlers/rexml.rb +43 -0
- data/lib/aws/core/xml/stub.rb +123 -0
- data/lib/aws/dynamo_db.rb +213 -0
- data/lib/aws/dynamo_db/attribute_collection.rb +460 -0
- data/lib/aws/dynamo_db/batch_get.rb +206 -0
- data/lib/aws/dynamo_db/batch_write.rb +251 -0
- data/lib/aws/dynamo_db/client.rb +888 -0
- data/lib/aws/dynamo_db/config.rb +20 -0
- data/lib/aws/dynamo_db/errors.rb +20 -0
- data/lib/aws/dynamo_db/expectations.rb +40 -0
- data/lib/aws/dynamo_db/item.rb +130 -0
- data/lib/aws/dynamo_db/item_collection.rb +852 -0
- data/lib/aws/dynamo_db/item_data.rb +31 -0
- data/lib/aws/dynamo_db/keys.rb +41 -0
- data/lib/aws/dynamo_db/primary_key_element.rb +47 -0
- data/lib/aws/dynamo_db/request.rb +28 -0
- data/lib/aws/dynamo_db/resource.rb +33 -0
- data/lib/aws/dynamo_db/table.rb +489 -0
- data/lib/aws/dynamo_db/table_collection.rb +165 -0
- data/lib/aws/dynamo_db/types.rb +86 -0
- data/lib/aws/ec2.rb +431 -0
- data/lib/aws/ec2/attachment.rb +140 -0
- data/lib/aws/ec2/attachment_collection.rb +54 -0
- data/lib/aws/ec2/availability_zone.rb +87 -0
- data/lib/aws/ec2/availability_zone_collection.rb +43 -0
- data/lib/aws/ec2/block_device_mappings.rb +53 -0
- data/lib/aws/ec2/client.rb +4121 -0
- data/lib/aws/ec2/collection.rb +36 -0
- data/lib/aws/ec2/config.rb +18 -0
- data/lib/aws/ec2/config_transform.rb +63 -0
- data/lib/aws/ec2/customer_gateway.rb +90 -0
- data/lib/aws/ec2/customer_gateway_collection.rb +73 -0
- data/lib/aws/ec2/dhcp_options.rb +106 -0
- data/lib/aws/ec2/dhcp_options_collection.rb +87 -0
- data/lib/aws/ec2/elastic_ip.rb +157 -0
- data/lib/aws/ec2/elastic_ip_collection.rb +97 -0
- data/lib/aws/ec2/errors.rb +32 -0
- data/lib/aws/ec2/filtered_collection.rb +90 -0
- data/lib/aws/ec2/has_permissions.rb +44 -0
- data/lib/aws/ec2/image.rb +254 -0
- data/lib/aws/ec2/image_collection.rb +228 -0
- data/lib/aws/ec2/instance.rb +669 -0
- data/lib/aws/ec2/instance_collection.rb +346 -0
- data/lib/aws/ec2/internet_gateway.rb +122 -0
- data/lib/aws/ec2/internet_gateway/attachment.rb +78 -0
- data/lib/aws/ec2/internet_gateway_collection.rb +54 -0
- data/lib/aws/ec2/key_pair.rb +82 -0
- data/lib/aws/ec2/key_pair_collection.rb +99 -0
- data/lib/aws/ec2/network_acl.rb +256 -0
- data/lib/aws/ec2/network_acl/association.rb +56 -0
- data/lib/aws/ec2/network_acl/entry.rb +147 -0
- data/lib/aws/ec2/network_acl_collection.rb +64 -0
- data/lib/aws/ec2/network_interface.rb +228 -0
- data/lib/aws/ec2/network_interface/attachment.rb +100 -0
- data/lib/aws/ec2/network_interface_collection.rb +103 -0
- data/lib/aws/ec2/permission_collection.rb +174 -0
- data/lib/aws/ec2/region.rb +97 -0
- data/lib/aws/ec2/region_collection.rb +51 -0
- data/lib/aws/ec2/request.rb +22 -0
- data/lib/aws/ec2/reserved_instances.rb +53 -0
- data/lib/aws/ec2/reserved_instances_collection.rb +40 -0
- data/lib/aws/ec2/reserved_instances_offering.rb +58 -0
- data/lib/aws/ec2/reserved_instances_offering_collection.rb +39 -0
- data/lib/aws/ec2/resource.rb +161 -0
- data/lib/aws/ec2/resource_tag_collection.rb +211 -0
- data/lib/aws/ec2/route_table.rb +205 -0
- data/lib/aws/ec2/route_table/association.rb +119 -0
- data/lib/aws/ec2/route_table/route.rb +113 -0
- data/lib/aws/ec2/route_table_collection.rb +72 -0
- data/lib/aws/ec2/security_group.rb +458 -0
- data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +63 -0
- data/lib/aws/ec2/security_group/ingress_ip_permission_collection.rb +61 -0
- data/lib/aws/ec2/security_group/ip_permission.rb +128 -0
- data/lib/aws/ec2/security_group_collection.rb +135 -0
- data/lib/aws/ec2/snapshot.rb +143 -0
- data/lib/aws/ec2/snapshot_collection.rb +131 -0
- data/lib/aws/ec2/subnet.rb +161 -0
- data/lib/aws/ec2/subnet_collection.rb +115 -0
- data/lib/aws/ec2/tag.rb +81 -0
- data/lib/aws/ec2/tag_collection.rb +107 -0
- data/lib/aws/ec2/tagged_collection.rb +53 -0
- data/lib/aws/ec2/tagged_item.rb +85 -0
- data/lib/aws/ec2/volume.rb +170 -0
- data/lib/aws/ec2/volume_collection.rb +97 -0
- data/lib/aws/ec2/vpc.rb +166 -0
- data/lib/aws/ec2/vpc_collection.rb +70 -0
- data/lib/aws/ec2/vpn_connection.rb +99 -0
- data/lib/aws/ec2/vpn_connection/telemetry.rb +49 -0
- data/lib/aws/ec2/vpn_connection_collection.rb +96 -0
- data/lib/aws/ec2/vpn_gateway.rb +123 -0
- data/lib/aws/ec2/vpn_gateway/attachment.rb +45 -0
- data/lib/aws/ec2/vpn_gateway_collection.rb +77 -0
- data/lib/aws/elb.rb +65 -0
- data/lib/aws/elb/availability_zone_collection.rb +138 -0
- data/lib/aws/elb/backend_server_policy_collection.rb +140 -0
- data/lib/aws/elb/client.rb +539 -0
- data/lib/aws/elb/config.rb +18 -0
- data/lib/aws/elb/errors.rb +26 -0
- data/lib/aws/elb/instance_collection.rb +174 -0
- data/lib/aws/elb/listener.rb +189 -0
- data/lib/aws/elb/listener_collection.rb +119 -0
- data/lib/aws/elb/listener_opts.rb +45 -0
- data/lib/aws/elb/load_balancer.rb +253 -0
- data/lib/aws/elb/load_balancer_collection.rb +113 -0
- data/lib/aws/elb/load_balancer_policy.rb +93 -0
- data/lib/aws/elb/load_balancer_policy_collection.rb +208 -0
- data/lib/aws/elb/request.rb +23 -0
- data/lib/aws/errors.rb +122 -0
- data/lib/aws/iam.rb +418 -0
- data/lib/aws/iam/access_key.rb +180 -0
- data/lib/aws/iam/access_key_collection.rb +128 -0
- data/lib/aws/iam/account_alias_collection.rb +79 -0
- data/lib/aws/iam/client.rb +1609 -0
- data/lib/aws/iam/collection.rb +83 -0
- data/lib/aws/iam/config.rb +18 -0
- data/lib/aws/iam/errors.rb +22 -0
- data/lib/aws/iam/group.rb +111 -0
- data/lib/aws/iam/group_collection.rb +132 -0
- data/lib/aws/iam/group_policy_collection.rb +47 -0
- data/lib/aws/iam/group_user_collection.rb +84 -0
- data/lib/aws/iam/login_profile.rb +99 -0
- data/lib/aws/iam/mfa_device.rb +52 -0
- data/lib/aws/iam/mfa_device_collection.rb +127 -0
- data/lib/aws/iam/policy.rb +46 -0
- data/lib/aws/iam/policy_collection.rb +188 -0
- data/lib/aws/iam/request.rb +29 -0
- data/lib/aws/iam/resource.rb +71 -0
- data/lib/aws/iam/server_certificate.rb +141 -0
- data/lib/aws/iam/server_certificate_collection.rb +138 -0
- data/lib/aws/iam/signing_certificate.rb +169 -0
- data/lib/aws/iam/signing_certificate_collection.rb +131 -0
- data/lib/aws/iam/user.rb +205 -0
- data/lib/aws/iam/user_collection.rb +133 -0
- data/lib/aws/iam/user_group_collection.rb +98 -0
- data/lib/aws/iam/user_policy.rb +90 -0
- data/lib/aws/iam/user_policy_collection.rb +45 -0
- data/lib/aws/iam/virtual_mfa_device.rb +139 -0
- data/lib/aws/iam/virtual_mfa_device_collection.rb +73 -0
- data/lib/aws/rails.rb +195 -0
- data/lib/aws/record.rb +116 -0
- data/lib/aws/record/abstract_base.rb +645 -0
- data/lib/aws/record/attributes.rb +384 -0
- data/lib/aws/record/conversion.rb +38 -0
- data/lib/aws/record/dirty_tracking.rb +285 -0
- data/lib/aws/record/errors.rb +143 -0
- data/lib/aws/record/exceptions.rb +48 -0
- data/lib/aws/record/hash_model.rb +161 -0
- data/lib/aws/record/hash_model/attributes.rb +182 -0
- data/lib/aws/record/hash_model/finder_methods.rb +172 -0
- data/lib/aws/record/hash_model/scope.rb +108 -0
- data/lib/aws/record/model.rb +427 -0
- data/lib/aws/record/model/attributes.rb +379 -0
- data/lib/aws/record/model/finder_methods.rb +232 -0
- data/lib/aws/record/model/scope.rb +213 -0
- data/lib/aws/record/naming.rb +31 -0
- data/lib/aws/record/scope.rb +199 -0
- data/lib/aws/record/validations.rb +694 -0
- data/lib/aws/record/validator.rb +237 -0
- data/lib/aws/record/validators/acceptance.rb +51 -0
- data/lib/aws/record/validators/block.rb +38 -0
- data/lib/aws/record/validators/confirmation.rb +43 -0
- data/lib/aws/record/validators/count.rb +108 -0
- data/lib/aws/record/validators/exclusion.rb +43 -0
- data/lib/aws/record/validators/format.rb +57 -0
- data/lib/aws/record/validators/inclusion.rb +56 -0
- data/lib/aws/record/validators/length.rb +107 -0
- data/lib/aws/record/validators/method.rb +33 -0
- data/lib/aws/record/validators/numericality.rb +138 -0
- data/lib/aws/record/validators/presence.rb +45 -0
- data/lib/aws/s3.rb +135 -0
- data/lib/aws/s3/access_control_list.rb +250 -0
- data/lib/aws/s3/acl_object.rb +264 -0
- data/lib/aws/s3/bucket.rb +393 -0
- data/lib/aws/s3/bucket_collection.rb +143 -0
- data/lib/aws/s3/bucket_lifecycle_configuration.rb +360 -0
- data/lib/aws/s3/bucket_version_collection.rb +77 -0
- data/lib/aws/s3/client.rb +1184 -0
- data/lib/aws/s3/client/xml.rb +177 -0
- data/lib/aws/s3/config.rb +26 -0
- data/lib/aws/s3/data_options.rb +100 -0
- data/lib/aws/s3/errors.rb +81 -0
- data/lib/aws/s3/multipart_upload.rb +317 -0
- data/lib/aws/s3/multipart_upload_collection.rb +68 -0
- data/lib/aws/s3/object_collection.rb +337 -0
- data/lib/aws/s3/object_metadata.rb +96 -0
- data/lib/aws/s3/object_upload_collection.rb +77 -0
- data/lib/aws/s3/object_version.rb +143 -0
- data/lib/aws/s3/object_version_collection.rb +89 -0
- data/lib/aws/s3/paginated_collection.rb +75 -0
- data/lib/aws/s3/policy.rb +74 -0
- data/lib/aws/s3/prefix_and_delimiter_collection.rb +47 -0
- data/lib/aws/s3/prefixed_collection.rb +81 -0
- data/lib/aws/s3/presigned_post.rb +553 -0
- data/lib/aws/s3/request.rb +201 -0
- data/lib/aws/s3/s3_object.rb +1037 -0
- data/lib/aws/s3/tree.rb +118 -0
- data/lib/aws/s3/tree/branch_node.rb +68 -0
- data/lib/aws/s3/tree/child_collection.rb +104 -0
- data/lib/aws/s3/tree/leaf_node.rb +94 -0
- data/lib/aws/s3/tree/node.rb +22 -0
- data/lib/aws/s3/tree/parent.rb +87 -0
- data/lib/aws/s3/uploaded_part.rb +80 -0
- data/lib/aws/s3/uploaded_part_collection.rb +84 -0
- data/lib/aws/simple_db.rb +217 -0
- data/lib/aws/simple_db/attribute.rb +154 -0
- data/lib/aws/simple_db/attribute_collection.rb +231 -0
- data/lib/aws/simple_db/client.rb +349 -0
- data/lib/aws/simple_db/config.rb +20 -0
- data/lib/aws/simple_db/consistent_read_option.rb +42 -0
- data/lib/aws/simple_db/delete_attributes.rb +62 -0
- data/lib/aws/simple_db/domain.rb +121 -0
- data/lib/aws/simple_db/domain_collection.rb +113 -0
- data/lib/aws/simple_db/domain_metadata.rb +110 -0
- data/lib/aws/simple_db/errors.rb +55 -0
- data/lib/aws/simple_db/expect_condition_option.rb +45 -0
- data/lib/aws/simple_db/item.rb +93 -0
- data/lib/aws/simple_db/item_collection.rb +649 -0
- data/lib/aws/simple_db/item_data.rb +73 -0
- data/lib/aws/simple_db/put_attributes.rb +60 -0
- data/lib/aws/simple_db/request.rb +23 -0
- data/lib/aws/simple_email_service.rb +426 -0
- data/lib/aws/simple_email_service/client.rb +286 -0
- data/lib/aws/simple_email_service/config.rb +19 -0
- data/lib/aws/simple_email_service/email_address_collection.rb +69 -0
- data/lib/aws/simple_email_service/errors.rb +22 -0
- data/lib/aws/simple_email_service/identity.rb +91 -0
- data/lib/aws/simple_email_service/identity_collection.rb +81 -0
- data/lib/aws/simple_email_service/quotas.rb +64 -0
- data/lib/aws/simple_email_service/request.rb +29 -0
- data/lib/aws/simple_workflow.rb +226 -0
- data/lib/aws/simple_workflow/activity_task.rb +173 -0
- data/lib/aws/simple_workflow/activity_task_collection.rb +123 -0
- data/lib/aws/simple_workflow/activity_type.rb +131 -0
- data/lib/aws/simple_workflow/activity_type_collection.rb +93 -0
- data/lib/aws/simple_workflow/client.rb +1434 -0
- data/lib/aws/simple_workflow/config.rb +18 -0
- data/lib/aws/simple_workflow/count.rb +49 -0
- data/lib/aws/simple_workflow/decision_task.rb +601 -0
- data/lib/aws/simple_workflow/decision_task_collection.rb +225 -0
- data/lib/aws/simple_workflow/domain.rb +122 -0
- data/lib/aws/simple_workflow/domain_collection.rb +169 -0
- data/lib/aws/simple_workflow/errors.rb +20 -0
- data/lib/aws/simple_workflow/history_event.rb +276 -0
- data/lib/aws/simple_workflow/history_event_collection.rb +76 -0
- data/lib/aws/simple_workflow/option_formatters.rb +82 -0
- data/lib/aws/simple_workflow/request.rb +36 -0
- data/lib/aws/simple_workflow/resource.rb +94 -0
- data/lib/aws/simple_workflow/type.rb +89 -0
- data/lib/aws/simple_workflow/type_collection.rb +140 -0
- data/lib/aws/simple_workflow/workflow_execution.rb +386 -0
- data/lib/aws/simple_workflow/workflow_execution_collection.rb +617 -0
- data/lib/aws/simple_workflow/workflow_type.rb +177 -0
- data/lib/aws/simple_workflow/workflow_type_collection.rb +91 -0
- data/lib/aws/sns.rb +74 -0
- data/lib/aws/sns/client.rb +371 -0
- data/lib/aws/sns/config.rb +18 -0
- data/lib/aws/sns/errors.rb +22 -0
- data/lib/aws/sns/has_delivery_policy.rb +68 -0
- data/lib/aws/sns/policy.rb +47 -0
- data/lib/aws/sns/request.rb +23 -0
- data/lib/aws/sns/subscription.rb +144 -0
- data/lib/aws/sns/subscription_collection.rb +80 -0
- data/lib/aws/sns/topic.rb +403 -0
- data/lib/aws/sns/topic_collection.rb +67 -0
- data/lib/aws/sns/topic_subscription_collection.rb +55 -0
- data/lib/aws/sqs.rb +79 -0
- data/lib/aws/sqs/client.rb +360 -0
- data/lib/aws/sqs/config.rb +18 -0
- data/lib/aws/sqs/errors.rb +101 -0
- data/lib/aws/sqs/policy.rb +48 -0
- data/lib/aws/sqs/queue.rb +725 -0
- data/lib/aws/sqs/queue_collection.rb +170 -0
- data/lib/aws/sqs/received_message.rb +181 -0
- data/lib/aws/sqs/received_sns_message.rb +112 -0
- data/lib/aws/sqs/request.rb +43 -0
- data/lib/aws/sts.rb +152 -0
- data/lib/aws/sts/client.rb +105 -0
- data/lib/aws/sts/config.rb +18 -0
- data/lib/aws/sts/errors.rb +22 -0
- data/lib/aws/sts/federated_session.rb +56 -0
- data/lib/aws/sts/policy.rb +30 -0
- data/lib/aws/sts/request.rb +29 -0
- data/lib/aws/sts/session.rb +48 -0
- data/lib/net/http/connection_pool.rb +210 -0
- data/lib/net/http/connection_pool/connection.rb +132 -0
- data/lib/net/http/connection_pool/session.rb +93 -0
- data/lib/user.rb +49 -0
- metadata +433 -0
data/lib/aws/rails.rb
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'yaml'
|
|
15
|
+
|
|
16
|
+
module AWS
|
|
17
|
+
|
|
18
|
+
if Object.const_defined?(:Rails) and Rails.const_defined?(:Railtie)
|
|
19
|
+
|
|
20
|
+
# @private
|
|
21
|
+
class Railtie < Rails::Railtie
|
|
22
|
+
|
|
23
|
+
# configure our plugin on boot. other extension points such
|
|
24
|
+
# as configuration, rake tasks, etc, are also available
|
|
25
|
+
initializer "aws-sdk.initialize" do |app|
|
|
26
|
+
AWS::Rails.setup
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# A handful of useful Rails integration methods.
|
|
33
|
+
#
|
|
34
|
+
# If you require this gem inside a Rails application (via config.gem
|
|
35
|
+
# for rails 2 and bundler for rails 3) then {setup} is called
|
|
36
|
+
# automatically.
|
|
37
|
+
module Rails
|
|
38
|
+
|
|
39
|
+
# Adds extra functionality to Rails.
|
|
40
|
+
#
|
|
41
|
+
# Normailly this method is invoked automatically when you require this
|
|
42
|
+
# gem in a Rails Application:
|
|
43
|
+
#
|
|
44
|
+
# Rails 3+ (RAILS_ROOT/Gemfile)
|
|
45
|
+
#
|
|
46
|
+
# gem 'aws-sdk'
|
|
47
|
+
#
|
|
48
|
+
# Rails 2.1 - 2.3 (RAILS_ROOT/config/environment.rb)
|
|
49
|
+
#
|
|
50
|
+
# config.gem 'aws-sdk'
|
|
51
|
+
#
|
|
52
|
+
# @return [nil]
|
|
53
|
+
def self.setup
|
|
54
|
+
load_yaml_config
|
|
55
|
+
add_action_mailer_delivery_method
|
|
56
|
+
log_to_rails_logger
|
|
57
|
+
nil
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Loads AWS configuration options from +RAILS_ROOT/config/aws.yml+.
|
|
61
|
+
#
|
|
62
|
+
# This configuration file is optional. You can omit this file and instead
|
|
63
|
+
# use ruby to configure AWS inside a configuration initialization script
|
|
64
|
+
# (e.g. RAILS_ROOT/config/intializers/aws.rb).
|
|
65
|
+
#
|
|
66
|
+
# If you have a yaml configuration file it should be formatted like the
|
|
67
|
+
# standard +database.yml+ file in a Rails application. This means there
|
|
68
|
+
# should be one section for Rails environment:
|
|
69
|
+
#
|
|
70
|
+
# development:
|
|
71
|
+
# access_key_id: YOUR_ACCESS_KEY_ID
|
|
72
|
+
# secret_access_key: YOUR_SECRET_ACCESS_KEY
|
|
73
|
+
# simple_db_consistent_reads: false
|
|
74
|
+
#
|
|
75
|
+
# production:
|
|
76
|
+
# access_key_id: YOUR_ACCESS_KEY_ID
|
|
77
|
+
# secret_access_key: YOUR_SECRET_ACCESS_KEY
|
|
78
|
+
# simple_db_consistent_reads: true
|
|
79
|
+
#
|
|
80
|
+
# You should also consider DRYing up your configuration file using
|
|
81
|
+
# YAML references:
|
|
82
|
+
#
|
|
83
|
+
# development:
|
|
84
|
+
# access_key_id: YOUR_ACCESS_KEY_ID
|
|
85
|
+
# secret_access_key: YOUR_SECRET_ACCESS_KEY
|
|
86
|
+
# simple_db_consistent_reads: false
|
|
87
|
+
#
|
|
88
|
+
# production:
|
|
89
|
+
# <<: *development
|
|
90
|
+
# simple_db_consistent_reads: true
|
|
91
|
+
#
|
|
92
|
+
# The yaml file will also be ERB parsed so you can use ruby inside of it:
|
|
93
|
+
#
|
|
94
|
+
# development:
|
|
95
|
+
# access_key_id: YOUR_ACCESS_KEY_ID
|
|
96
|
+
# secret_access_key: <%= read_secret_from_a_secure_location %>
|
|
97
|
+
# simple_db_consistent_reads: false
|
|
98
|
+
#
|
|
99
|
+
# production:
|
|
100
|
+
# <<: *development
|
|
101
|
+
# simple_db_consistent_reads: true
|
|
102
|
+
#
|
|
103
|
+
def self.load_yaml_config
|
|
104
|
+
|
|
105
|
+
path = Pathname.new("#{rails_root}/config/aws.yml")
|
|
106
|
+
|
|
107
|
+
if File.exists?(path)
|
|
108
|
+
cfg = YAML::load(ERB.new(File.read(path)).result)
|
|
109
|
+
unless cfg[rails_env]
|
|
110
|
+
raise "config/aws.yml is missing a section for `#{rails_env}`"
|
|
111
|
+
end
|
|
112
|
+
AWS.config(cfg[rails_env])
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Adds a delivery method to ActionMailer that uses
|
|
118
|
+
# {AWS::SimpleEmailService}.
|
|
119
|
+
#
|
|
120
|
+
# Once you have an SES delivery method you can configure Rails to
|
|
121
|
+
# use this for ActionMailer in your environment configuration
|
|
122
|
+
# (e.g. RAILS_ROOT/config/environments/production.rb)
|
|
123
|
+
#
|
|
124
|
+
# config.action_mailer.delivery_method = :amazon_ses
|
|
125
|
+
#
|
|
126
|
+
# === Defaults
|
|
127
|
+
#
|
|
128
|
+
# Normally you don't need to call this method. By default a delivery method
|
|
129
|
+
# named +:amazon_ses+ is added to ActionMailer::Base. This delivery method
|
|
130
|
+
# uses your default configuration (#{AWS.config}).
|
|
131
|
+
#
|
|
132
|
+
# === Custom SES Options
|
|
133
|
+
#
|
|
134
|
+
# If you need to supply configuration values for SES that are different than
|
|
135
|
+
# those in {AWS.config} then you can pass those options:
|
|
136
|
+
#
|
|
137
|
+
# AWS.add_action_mailer_delivery_method(:ses, custom_options)
|
|
138
|
+
#
|
|
139
|
+
# @param [Symbol] name (:amazon_ses) The name of the delivery
|
|
140
|
+
# method. The name used here should be the same as you set in
|
|
141
|
+
# your environment config. If you name the delivery method
|
|
142
|
+
# +:amazon_ses+ then you could do something like this in your
|
|
143
|
+
# config/environments/ENV.rb file:
|
|
144
|
+
#
|
|
145
|
+
# config.action_mailer.delivery_method = :amazon_ses
|
|
146
|
+
#
|
|
147
|
+
# @param [Hash] options A hash of options that are passes to
|
|
148
|
+
# {AWS::SimpleEmailService#new} before delivering email.
|
|
149
|
+
#
|
|
150
|
+
# @return [nil]
|
|
151
|
+
#
|
|
152
|
+
def self.add_action_mailer_delivery_method name = :amazon_ses, options = {}
|
|
153
|
+
|
|
154
|
+
if ::Rails.version.to_f >= 3
|
|
155
|
+
ActiveSupport.on_load(:action_mailer) do
|
|
156
|
+
self.add_delivery_method(name, AWS::SimpleEmailService, options)
|
|
157
|
+
end
|
|
158
|
+
else
|
|
159
|
+
amb = ::ActionMailer::Base
|
|
160
|
+
amb.send(:define_method, "perform_delivery_#{name}") do |mail|
|
|
161
|
+
AWS::SimpleEmailService.new(options).send_raw_email(mail)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
nil
|
|
166
|
+
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Configures AWS to log to the Rails default logger.
|
|
170
|
+
# @return [nil]
|
|
171
|
+
def self.log_to_rails_logger
|
|
172
|
+
AWS.config(:logger => rails_logger)
|
|
173
|
+
nil
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# @private
|
|
177
|
+
protected
|
|
178
|
+
def self.rails_env
|
|
179
|
+
::Rails.respond_to?(:env) ? ::Rails.env : RAILS_ENV
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# @private
|
|
183
|
+
protected
|
|
184
|
+
def self.rails_root
|
|
185
|
+
::Rails.respond_to?(:root) ? ::Rails.root.to_s : RAILS_ROOT
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# @private
|
|
189
|
+
protected
|
|
190
|
+
def self.rails_logger
|
|
191
|
+
::Rails.respond_to?(:logger) ? ::Rails.logger : ::RAILS_DEFAULT_LOGGER
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
end
|
|
195
|
+
end
|
data/lib/aws/record.rb
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'set'
|
|
15
|
+
|
|
16
|
+
module AWS
|
|
17
|
+
|
|
18
|
+
# AWS::Record is an ORM built on top of AWS services.
|
|
19
|
+
module Record
|
|
20
|
+
|
|
21
|
+
AWS.register_autoloads(self) do
|
|
22
|
+
autoload :Base, 'model'
|
|
23
|
+
autoload :Model, 'model'
|
|
24
|
+
autoload :HashModel, 'hash_model'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @private
|
|
28
|
+
class RecordNotFound < StandardError; end
|
|
29
|
+
|
|
30
|
+
# Sets a prefix to be applied to all SimpleDB domains associated with
|
|
31
|
+
# AWS::Record::Base classes.
|
|
32
|
+
#
|
|
33
|
+
# AWS::Record.domain_prefix = 'production_'
|
|
34
|
+
#
|
|
35
|
+
# class Product < AWS::Record::Base
|
|
36
|
+
# set_shard_name 'products'
|
|
37
|
+
# end
|
|
38
|
+
#
|
|
39
|
+
# p = Product.new
|
|
40
|
+
# p.shard #=> 'products'
|
|
41
|
+
# p.save # the product is persisted to the 'production-products' domain
|
|
42
|
+
#
|
|
43
|
+
# @param [String] prefix A prefix to append to all domains. This is useful
|
|
44
|
+
# for grouping domains used by one application with a single prefix.
|
|
45
|
+
#
|
|
46
|
+
def self.domain_prefix= prefix
|
|
47
|
+
@domain_prefix = prefix
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# @return [String,nil] The string that is prepended to all domain names.
|
|
51
|
+
def self.domain_prefix
|
|
52
|
+
@domain_prefix
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Sets a prefix to be applied to all DynamoDB tables associated
|
|
56
|
+
# with {AWS::Record::HashModel} and {AWS::Record::ListModel}
|
|
57
|
+
# classes.
|
|
58
|
+
#
|
|
59
|
+
# AWS::Record.table_prefix = 'production_'
|
|
60
|
+
#
|
|
61
|
+
# class Product < AWS::Record::HashModel
|
|
62
|
+
# set_shard_name 'products'
|
|
63
|
+
# end
|
|
64
|
+
#
|
|
65
|
+
# p = Product.new
|
|
66
|
+
# p.shard #=> 'products'
|
|
67
|
+
# p.save # the product is persisted to the 'production-products' table
|
|
68
|
+
#
|
|
69
|
+
# @param [String] prefix A prefix to append to all tables. This is
|
|
70
|
+
# useful for grouping tables used by one application with a
|
|
71
|
+
# single prefix.
|
|
72
|
+
#
|
|
73
|
+
def self.table_prefix= prefix
|
|
74
|
+
@table_prefix = prefix
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# @return [String,nil] The string that is prepended to all table names.
|
|
78
|
+
def self.table_prefix
|
|
79
|
+
@table_prefix
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# A utility method for casting values into an array.
|
|
83
|
+
#
|
|
84
|
+
# * nil is returned as an empty array, []
|
|
85
|
+
# * Arrays are returned unmodified
|
|
86
|
+
# * Everything else is returned as the sole element of an array
|
|
87
|
+
#
|
|
88
|
+
# @param [Object] value
|
|
89
|
+
# @return [Array] The value cast into an array
|
|
90
|
+
# @private
|
|
91
|
+
def self.as_array value
|
|
92
|
+
case value
|
|
93
|
+
when nil then []
|
|
94
|
+
when Set then value.to_a
|
|
95
|
+
when Array then value
|
|
96
|
+
else [value]
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# A utility method for casting values into
|
|
101
|
+
#
|
|
102
|
+
# * Sets are returned unmodified
|
|
103
|
+
# * everything else is passed through #{as_array} and then into a new Set
|
|
104
|
+
#
|
|
105
|
+
# @param [Object] value
|
|
106
|
+
# @return [Set] The value cast into a Set.
|
|
107
|
+
# @private
|
|
108
|
+
def self.as_set value
|
|
109
|
+
case value
|
|
110
|
+
when Set then value
|
|
111
|
+
else Set.new(as_array(value))
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
end
|
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
# Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'uuidtools'
|
|
15
|
+
require 'set'
|
|
16
|
+
|
|
17
|
+
require 'aws/record/scope'
|
|
18
|
+
require 'aws/record/naming'
|
|
19
|
+
require 'aws/record/validations'
|
|
20
|
+
require 'aws/record/dirty_tracking'
|
|
21
|
+
require 'aws/record/conversion'
|
|
22
|
+
require 'aws/record/errors'
|
|
23
|
+
require 'aws/record/exceptions'
|
|
24
|
+
|
|
25
|
+
module AWS
|
|
26
|
+
module Record
|
|
27
|
+
module AbstractBase
|
|
28
|
+
|
|
29
|
+
def self.extended base
|
|
30
|
+
|
|
31
|
+
base.send(:extend, ClassMethods)
|
|
32
|
+
base.send(:include, InstanceMethods)
|
|
33
|
+
base.send(:include, DirtyTracking)
|
|
34
|
+
base.send(:extend, Validations)
|
|
35
|
+
|
|
36
|
+
# these 3 modules are for rails 3+ active model compatability
|
|
37
|
+
base.send(:extend, Naming)
|
|
38
|
+
base.send(:include, Naming)
|
|
39
|
+
base.send(:include, Conversion)
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
module InstanceMethods
|
|
44
|
+
|
|
45
|
+
# Constructs a new record.
|
|
46
|
+
#
|
|
47
|
+
# @param [Hash] attributes Attributes that should be bulk assigned
|
|
48
|
+
# to this record. You can also specify the shard (i.e. domain
|
|
49
|
+
# or table) this record should persist to via +:shard+).
|
|
50
|
+
#
|
|
51
|
+
# @option attributes [String] :shard The domain/table this record
|
|
52
|
+
# should persist to. If this is omitted, it will persist to the
|
|
53
|
+
# class default shard (which defaults to the class name).
|
|
54
|
+
#
|
|
55
|
+
# @return [Model,HashModel] Returns a new (non-persisted) record.
|
|
56
|
+
# Call {#save} to persist changes to AWS.
|
|
57
|
+
#
|
|
58
|
+
def initialize attributes = {}
|
|
59
|
+
|
|
60
|
+
attributes = attributes.dup
|
|
61
|
+
|
|
62
|
+
# supporting :domain for backwards compatability, :shard is prefered
|
|
63
|
+
@_shard = attributes.delete(:domain)
|
|
64
|
+
@_shard ||= attributes.delete('domain')
|
|
65
|
+
@_shard ||= attributes.delete(:shard)
|
|
66
|
+
@_shard ||= attributes.delete('shard')
|
|
67
|
+
@_shard = self.class.shard_name(@_shard)
|
|
68
|
+
|
|
69
|
+
@_data = {}
|
|
70
|
+
assign_default_values
|
|
71
|
+
bulk_assign(attributes)
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# @return [String] Returns the name of the shard this record
|
|
76
|
+
# is persisted to or will be persisted to. Defaults to the
|
|
77
|
+
# domain/table named after this record class.
|
|
78
|
+
def shard
|
|
79
|
+
@_shard
|
|
80
|
+
end
|
|
81
|
+
alias_method :domain, :shard # for backwards compatability
|
|
82
|
+
|
|
83
|
+
# The id for each record is auto-generated. The default strategy
|
|
84
|
+
# generates uuid strings.
|
|
85
|
+
# @return [String] Returns the id string (uuid) for this record. Retuns
|
|
86
|
+
# nil if this is a new record that has not been persisted yet.
|
|
87
|
+
def id
|
|
88
|
+
@_id
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# @return [Hash] A hash with attribute names as hash keys (strings) and
|
|
92
|
+
# attribute values (of mixed types) as hash values.
|
|
93
|
+
def attributes
|
|
94
|
+
attributes = Core::IndifferentHash.new
|
|
95
|
+
attributes['id'] = id if persisted?
|
|
96
|
+
self.class.attributes.keys.inject(attributes) do |hash,attr_name|
|
|
97
|
+
hash.merge(attr_name => __send__(attr_name))
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Acts like {#update} but does not call {#save}.
|
|
102
|
+
#
|
|
103
|
+
# record.attributes = { :name => 'abc', :age => 20 }
|
|
104
|
+
#
|
|
105
|
+
# @param [Hash] attributes A hash of attributes to set on this record
|
|
106
|
+
# without calling save.
|
|
107
|
+
#
|
|
108
|
+
# @return [Hash] Returns the attribute hash that was passed in.
|
|
109
|
+
#
|
|
110
|
+
def attributes= attributes
|
|
111
|
+
bulk_assign(attributes)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Persistence indicates if the record has been saved previously or not.
|
|
115
|
+
#
|
|
116
|
+
# @example
|
|
117
|
+
# @recipe = Recipe.new(:name => 'Buttermilk Pancackes')
|
|
118
|
+
# @recipe.persisted? #=> false
|
|
119
|
+
# @recipe.save!
|
|
120
|
+
# @recipe.persisted? #=> true
|
|
121
|
+
#
|
|
122
|
+
# @return [Boolean] Returns true if this record has been persisted.
|
|
123
|
+
def persisted?
|
|
124
|
+
!!@_persisted
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# @return [Boolean] Returns true if this record has not been persisted
|
|
128
|
+
# to SimpleDB.
|
|
129
|
+
def new_record?
|
|
130
|
+
!persisted?
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# @return [Boolean] Returns true if this record has no validation errors.
|
|
134
|
+
def valid?
|
|
135
|
+
run_validations
|
|
136
|
+
errors.empty?
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def errors
|
|
140
|
+
@errors ||= Errors.new
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Creates new records, updates existing records.
|
|
144
|
+
# @return [Boolean] Returns true if the record saved without errors,
|
|
145
|
+
# false otherwise.
|
|
146
|
+
def save
|
|
147
|
+
if valid?
|
|
148
|
+
persisted? ? update : create
|
|
149
|
+
clear_changes!
|
|
150
|
+
true
|
|
151
|
+
else
|
|
152
|
+
false
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Creates new records, updates exsting records. If there is a validation
|
|
157
|
+
# error then an exception is raised.
|
|
158
|
+
# @raise [InvalidRecordError] Raised when the record has validation
|
|
159
|
+
# errors and can not be saved.
|
|
160
|
+
# @return [true] Returns true after a successful save.
|
|
161
|
+
def save!
|
|
162
|
+
raise InvalidRecordError.new(self) unless save
|
|
163
|
+
true
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Bulk assigns the attributes and then saves the record.
|
|
167
|
+
# @param [Hash] attribute_hash A hash of attribute names (keys) and
|
|
168
|
+
# attribute values to assign to this record.
|
|
169
|
+
# @return (see #save)
|
|
170
|
+
def update_attributes attribute_hash
|
|
171
|
+
bulk_assign(attribute_hash)
|
|
172
|
+
save
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# Bulk assigns the attributes and then saves the record. Raises
|
|
176
|
+
# an exception (AWS::Record::InvalidRecordError) if the record is not
|
|
177
|
+
# valid.
|
|
178
|
+
# @param (see #update_attributes)
|
|
179
|
+
# @return [true]
|
|
180
|
+
def update_attributes! attribute_hash
|
|
181
|
+
if update_attributes(attribute_hash)
|
|
182
|
+
true
|
|
183
|
+
else
|
|
184
|
+
raise InvalidRecordError.new(self)
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Deletes the record.
|
|
189
|
+
# @return [true]
|
|
190
|
+
def delete
|
|
191
|
+
if persisted?
|
|
192
|
+
if deleted?
|
|
193
|
+
raise 'unable to delete, this object has already been deleted'
|
|
194
|
+
else
|
|
195
|
+
delete_storage
|
|
196
|
+
@_deleted = true
|
|
197
|
+
end
|
|
198
|
+
else
|
|
199
|
+
raise 'unable to delete, this object has not been saved yet'
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
alias_method :destroy, :delete
|
|
203
|
+
|
|
204
|
+
# @return [Boolean] Returns true if this instance object has been deleted.
|
|
205
|
+
def deleted?
|
|
206
|
+
persisted? ? !!@_deleted : false
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# If you define a custom setter, you use #[]= to set the value
|
|
210
|
+
# on the record.
|
|
211
|
+
#
|
|
212
|
+
# class Book < AWS::Record::Model
|
|
213
|
+
#
|
|
214
|
+
# string_attr :name
|
|
215
|
+
#
|
|
216
|
+
# # replace the default #author= method
|
|
217
|
+
# def author= name
|
|
218
|
+
# self['author'] = name.blank? ? 'Anonymous' : name
|
|
219
|
+
# end
|
|
220
|
+
#
|
|
221
|
+
# end
|
|
222
|
+
#
|
|
223
|
+
# @param [String,Symbol] The attribute name to set a value for
|
|
224
|
+
# @param attribute_value The value to assign.
|
|
225
|
+
protected
|
|
226
|
+
def []= attribute_name, new_value
|
|
227
|
+
self.class.attribute_for(attribute_name) do |attribute|
|
|
228
|
+
|
|
229
|
+
if_tracking_changes do
|
|
230
|
+
original_value = type_cast(attribute, attribute_was(attribute.name))
|
|
231
|
+
incoming_value = type_cast(attribute, new_value)
|
|
232
|
+
if original_value == incoming_value
|
|
233
|
+
clear_change!(attribute.name)
|
|
234
|
+
else
|
|
235
|
+
attribute_will_change!(attribute.name)
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
@_data[attribute.name] = new_value
|
|
240
|
+
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# Returns the typecasted value for the named attribute.
|
|
245
|
+
#
|
|
246
|
+
# book = Book.new(:title => 'My Book')
|
|
247
|
+
# book['title'] #=> 'My Book'
|
|
248
|
+
# book.title #=> 'My Book'
|
|
249
|
+
#
|
|
250
|
+
# === Intended Use
|
|
251
|
+
#
|
|
252
|
+
# This method's primary use is for getting/setting the value for
|
|
253
|
+
# an attribute inside a custom method:
|
|
254
|
+
#
|
|
255
|
+
# class Book < AWS::Record::Model
|
|
256
|
+
#
|
|
257
|
+
# string_attr :title
|
|
258
|
+
#
|
|
259
|
+
# def title
|
|
260
|
+
# self['title'] ? self['title'].upcase : nil
|
|
261
|
+
# end
|
|
262
|
+
#
|
|
263
|
+
# end
|
|
264
|
+
#
|
|
265
|
+
# book = Book.new(:title => 'My Book')
|
|
266
|
+
# book.title #=> 'MY BOOK'
|
|
267
|
+
#
|
|
268
|
+
# @param [String,Symbol] attribute_name The name of the attribute to fetch
|
|
269
|
+
# a value for.
|
|
270
|
+
# @return The current type-casted value for the named attribute.
|
|
271
|
+
protected
|
|
272
|
+
def [] attribute_name
|
|
273
|
+
self.class.attribute_for(attribute_name) do |attribute|
|
|
274
|
+
type_cast(attribute, @_data[attribute.name])
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
protected
|
|
279
|
+
def create
|
|
280
|
+
populate_id
|
|
281
|
+
touch_timestamps('created_at', 'updated_at')
|
|
282
|
+
increment_optimistic_lock_value
|
|
283
|
+
create_storage
|
|
284
|
+
@_persisted = true
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
private
|
|
288
|
+
def update
|
|
289
|
+
return unless changed?
|
|
290
|
+
touch_timestamps('updated_at')
|
|
291
|
+
increment_optimistic_lock_value
|
|
292
|
+
update_storage
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
protected
|
|
296
|
+
def populate_id
|
|
297
|
+
@_id = UUIDTools::UUID.random_create.to_s
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
protected
|
|
301
|
+
def touch_timestamps *attributes
|
|
302
|
+
now = Time.now
|
|
303
|
+
attributes.each do |attr_name|
|
|
304
|
+
if
|
|
305
|
+
self.class.attributes[attr_name] and
|
|
306
|
+
!attribute_changed?(attr_name)
|
|
307
|
+
# don't touch timestamps the user modified
|
|
308
|
+
then
|
|
309
|
+
__send__("#{attr_name}=", now)
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
protected
|
|
315
|
+
def increment_optimistic_lock_value
|
|
316
|
+
if_locks_optimistically do |lock_attr|
|
|
317
|
+
if value = self[lock_attr.name]
|
|
318
|
+
self[lock_attr.name] = value + 1
|
|
319
|
+
else
|
|
320
|
+
self[lock_attr.name] = 1
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
protected
|
|
326
|
+
def if_locks_optimistically &block
|
|
327
|
+
if opt_lock_attr = self.class.optimistic_locking_attr
|
|
328
|
+
yield(opt_lock_attr)
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
protected
|
|
333
|
+
def opt_lock_conditions
|
|
334
|
+
conditions = {}
|
|
335
|
+
if_locks_optimistically do |lock_attr|
|
|
336
|
+
if was = attribute_was(lock_attr.name)
|
|
337
|
+
conditions[:if] = { lock_attr.name => lock_attr.serialize(was) }
|
|
338
|
+
else
|
|
339
|
+
conditions[:unless_exists] = lock_attr.name
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
conditions
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
private
|
|
346
|
+
def assign_default_values
|
|
347
|
+
# populate default attribute values
|
|
348
|
+
ignore_changes do
|
|
349
|
+
self.class.attributes.values.each do |attribute|
|
|
350
|
+
begin
|
|
351
|
+
# copy default values down so methods like #gsub! don't
|
|
352
|
+
# modify the default values for other objects
|
|
353
|
+
@_data[attribute.name] = attribute.default_value.clone
|
|
354
|
+
rescue TypeError
|
|
355
|
+
@_data[attribute.name] = attribute.default_value
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
private
|
|
362
|
+
def bulk_assign hash
|
|
363
|
+
flatten_date_parts(hash).each_pair do |attr_name, attr_value|
|
|
364
|
+
__send__("#{attr_name}=", attr_value)
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
private
|
|
369
|
+
# Rails date and time select helpers split date and time
|
|
370
|
+
# attributes into multiple values for form submission.
|
|
371
|
+
# These attributes get named things like 'created_at(1i)'
|
|
372
|
+
# and represent year/month/day/hour/min/sec parts of
|
|
373
|
+
# the date/time.
|
|
374
|
+
#
|
|
375
|
+
# This method converts these attributes back into a single
|
|
376
|
+
# value and converts them to Date and DateTime objects.
|
|
377
|
+
def flatten_date_parts attributes
|
|
378
|
+
|
|
379
|
+
multi_attributes = Set.new
|
|
380
|
+
|
|
381
|
+
hash = attributes.inject({}) do |hash,(key,value)|
|
|
382
|
+
# collects attribuets like "created_at(1i)" into an array of parts
|
|
383
|
+
if key =~ /\(/
|
|
384
|
+
key, index = key.to_s.split(/\(|i\)/)
|
|
385
|
+
hash[key] ||= []
|
|
386
|
+
hash[key][index.to_i - 1] = value.to_i
|
|
387
|
+
multi_attributes << key
|
|
388
|
+
else
|
|
389
|
+
hash[key] = value
|
|
390
|
+
end
|
|
391
|
+
hash
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
# convert multiattribute values into date/time objects
|
|
395
|
+
multi_attributes.each do |key|
|
|
396
|
+
|
|
397
|
+
values = hash[key]
|
|
398
|
+
|
|
399
|
+
hash[key] = case values.size
|
|
400
|
+
when 0 then nil
|
|
401
|
+
when 2
|
|
402
|
+
now = Time.now
|
|
403
|
+
Time.local(now.year, now.month, now.day, values[0], values[1], 0, 0)
|
|
404
|
+
when 3 then Date.new(*values)
|
|
405
|
+
else DateTime.new(*values)
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
hash
|
|
411
|
+
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
private
|
|
415
|
+
def type_cast attribute, raw
|
|
416
|
+
if attribute.set?
|
|
417
|
+
values = Record.as_array(raw).inject([]) do |values,value|
|
|
418
|
+
values << attribute.type_cast(value)
|
|
419
|
+
values
|
|
420
|
+
end
|
|
421
|
+
Set.new(values.compact)
|
|
422
|
+
else
|
|
423
|
+
attribute.type_cast(raw)
|
|
424
|
+
end
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
private
|
|
428
|
+
def serialize_attributes
|
|
429
|
+
|
|
430
|
+
hash = {}
|
|
431
|
+
self.class.attributes.each_pair do |attribute_name,attribute|
|
|
432
|
+
value = serialize_attribute(attribute, @_data[attribute_name])
|
|
433
|
+
unless [nil, []].include?(value)
|
|
434
|
+
hash[attribute_name] = value
|
|
435
|
+
end
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
# simple db does not support persisting items without attribute values
|
|
439
|
+
raise EmptyRecordError.new(self) if hash.empty?
|
|
440
|
+
|
|
441
|
+
hash
|
|
442
|
+
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
private
|
|
446
|
+
def serialize_attribute attribute, raw_value
|
|
447
|
+
type_casted_value = type_cast(attribute, raw_value)
|
|
448
|
+
case type_casted_value
|
|
449
|
+
when nil then nil
|
|
450
|
+
when Set then type_casted_value.map{|v| attribute.serialize(v) }
|
|
451
|
+
else attribute.serialize(type_casted_value)
|
|
452
|
+
end
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
# @private
|
|
456
|
+
protected
|
|
457
|
+
def hydrate id, data
|
|
458
|
+
|
|
459
|
+
# @todo need to do something about partial hyrdation of attributes
|
|
460
|
+
|
|
461
|
+
@_id = id
|
|
462
|
+
|
|
463
|
+
# New objects are populated with default values, but we don't
|
|
464
|
+
# want these values to hang around when hydrating persisted values
|
|
465
|
+
# (those values may have been blanked out before save).
|
|
466
|
+
self.class.attributes.values.each do |attribute|
|
|
467
|
+
@_data[attribute.name] = nil
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
ignore_changes do
|
|
471
|
+
bulk_assign(deserialize_item_data(data))
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
@_persisted = true
|
|
475
|
+
|
|
476
|
+
end
|
|
477
|
+
|
|
478
|
+
protected
|
|
479
|
+
def create_storage
|
|
480
|
+
raise NotImplementedError
|
|
481
|
+
end
|
|
482
|
+
|
|
483
|
+
protected
|
|
484
|
+
def update_storage
|
|
485
|
+
raise NotImplementedError
|
|
486
|
+
end
|
|
487
|
+
|
|
488
|
+
protected
|
|
489
|
+
def delete_storage
|
|
490
|
+
raise NotImplementedError
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
module ClassMethods
|
|
496
|
+
|
|
497
|
+
# Allows you to override the default shard name for this class.
|
|
498
|
+
# The shard name defaults to the class name.
|
|
499
|
+
# @param [String] name
|
|
500
|
+
def set_shard_name name
|
|
501
|
+
@_shard_name = name
|
|
502
|
+
end
|
|
503
|
+
alias_method :set_domain_name, :set_shard_name
|
|
504
|
+
alias_method :shard_name=, :set_shard_name
|
|
505
|
+
|
|
506
|
+
# Returns the name of the shard this class will persist records
|
|
507
|
+
# into by default.
|
|
508
|
+
#
|
|
509
|
+
# @param [String] name Defaults to the name of this class.
|
|
510
|
+
# @return [String] Returns the full prefixed domain name for this class.
|
|
511
|
+
def shard_name name = nil
|
|
512
|
+
case name
|
|
513
|
+
when nil
|
|
514
|
+
@_shard_name || self.name
|
|
515
|
+
when AWS::DynamoDB::Table
|
|
516
|
+
name.name.gsub(/^#{Record::table_prefix}/, '')
|
|
517
|
+
when AWS::SimpleDB::Domain
|
|
518
|
+
name.name.gsub(/^#{Record::domain_prefix}/, '')
|
|
519
|
+
else name
|
|
520
|
+
end
|
|
521
|
+
end
|
|
522
|
+
alias_method :domain_name, :shard_name
|
|
523
|
+
|
|
524
|
+
# Adds a scoped finder to this class.
|
|
525
|
+
#
|
|
526
|
+
# class Book < AWS::Record::Model
|
|
527
|
+
# scope :top_10, order(:popularity, :desc).limit(10)
|
|
528
|
+
# end
|
|
529
|
+
#
|
|
530
|
+
# Book.top_10.to_a
|
|
531
|
+
# #=> [#<Book...>, #<Book...>]
|
|
532
|
+
#
|
|
533
|
+
# Book.top_10.first
|
|
534
|
+
# #=> #<Book...>
|
|
535
|
+
#
|
|
536
|
+
# You can also provide a block that accepts params for the scoped
|
|
537
|
+
# finder. This block should return a scope.
|
|
538
|
+
#
|
|
539
|
+
# class Book < AWS::Record::Model
|
|
540
|
+
# scope :by_author, lambda {|name| where(:author => name) }
|
|
541
|
+
# end
|
|
542
|
+
#
|
|
543
|
+
# # top 10 books by the author 'John Doe'
|
|
544
|
+
# Book.by_author('John Doe').top_10
|
|
545
|
+
#
|
|
546
|
+
# @param [Symbol] name The name of the scope. Scope names should be
|
|
547
|
+
# method-safe and should not conflict with any other class methods.
|
|
548
|
+
#
|
|
549
|
+
# @param [Scope] scope
|
|
550
|
+
#
|
|
551
|
+
def scope name, scope = nil, &block
|
|
552
|
+
|
|
553
|
+
method_definition = scope ? lambda { scope } : block
|
|
554
|
+
|
|
555
|
+
extend(Module.new { define_method(name, &method_definition) })
|
|
556
|
+
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
# @private
|
|
560
|
+
def new_scope
|
|
561
|
+
self::Scope.new(self)
|
|
562
|
+
end
|
|
563
|
+
|
|
564
|
+
def optimistic_locking attribute_name = :version_id
|
|
565
|
+
attribute = integer_attr(attribute_name)
|
|
566
|
+
@optimistic_locking_attr = attribute
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
# @return [Boolean] Returns true if this class is configured to
|
|
570
|
+
# perform optimistic locking.
|
|
571
|
+
def optimistic_locking?
|
|
572
|
+
!!@optimistic_locking_attr
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
@private
|
|
576
|
+
def optimistic_locking_attr
|
|
577
|
+
@optimistic_locking_attr
|
|
578
|
+
end
|
|
579
|
+
|
|
580
|
+
# @return [Hash<String,Attribute>] Returns a hash of all of the
|
|
581
|
+
# configured attributes for this class.
|
|
582
|
+
def attributes
|
|
583
|
+
@attributes ||= {}
|
|
584
|
+
end
|
|
585
|
+
|
|
586
|
+
# @private
|
|
587
|
+
def attribute_for attribute_name, &block
|
|
588
|
+
unless attribute = attributes[attribute_name.to_s]
|
|
589
|
+
raise UndefinedAttributeError.new(attribute_name.to_s)
|
|
590
|
+
end
|
|
591
|
+
block_given? ? yield(attribute) : attribute
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
# @private
|
|
595
|
+
def add_attribute attribute
|
|
596
|
+
|
|
597
|
+
attr_name = attribute.name
|
|
598
|
+
|
|
599
|
+
attributes[attr_name] = attribute
|
|
600
|
+
|
|
601
|
+
# setter
|
|
602
|
+
define_method("#{attr_name}=") do |value|
|
|
603
|
+
self[attr_name] = value
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
# getter
|
|
607
|
+
define_method(attr_name) do
|
|
608
|
+
self[attr_name]
|
|
609
|
+
end
|
|
610
|
+
|
|
611
|
+
# before type-cast getter
|
|
612
|
+
define_method("#{attr_name}_before_type_cast") do
|
|
613
|
+
@_data[attr_name]
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
## dirty tracking methods
|
|
617
|
+
|
|
618
|
+
define_method("#{attr_name}_changed?") do
|
|
619
|
+
attribute_changed?(attr_name)
|
|
620
|
+
end
|
|
621
|
+
|
|
622
|
+
define_method("#{attr_name}_change") do
|
|
623
|
+
attribute_change(attr_name)
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
define_method("#{attr_name}_was") do
|
|
627
|
+
attribute_was(attr_name)
|
|
628
|
+
end
|
|
629
|
+
|
|
630
|
+
define_method("#{attr_name}_will_change!") do
|
|
631
|
+
attribute_will_change!(attr_name)
|
|
632
|
+
end
|
|
633
|
+
|
|
634
|
+
define_method("reset_#{attr_name}!") do
|
|
635
|
+
reset_attribute!(attr_name)
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
attribute
|
|
639
|
+
|
|
640
|
+
end
|
|
641
|
+
|
|
642
|
+
end
|
|
643
|
+
end
|
|
644
|
+
end
|
|
645
|
+
end
|