Class: AwsCli::CLI::DYNAMO::Item

Inherits:
Thor
  • Object
show all
Defined in:
lib/awscli/cli/dynamo/item.rb

Instance Method Summary collapse

Instance Method Details

#batch_getObject



212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/awscli/cli/dynamo/item.rb', line 212

def batch_get
  unless options[:requests]
    abort 'option --requests is required'
  end
  options[:requests].each do |request|
    unless request =~ /^(.*?)(?:,((N|S|B|NS|SS|BS)=(.*?))(:(N|S|B|NS|SS|BS)=(.*?))*)+$/
      abort 'Invalid --request format, see `awscli dynamo item help batch_get` for usage examples'
    end
  end
  create_dynamo_object
  @ddb.batch_get options
end

#batch_writeObject



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/awscli/cli/dynamo/item.rb', line 240

def batch_write
  unless options[:put_requests] or options[:delete_requests]
    abort 'option --put-requests or --delete-requests is required to perform batch_write'
  end
  options[:put_requests] and options[:put_requests].each do |put_request|
    unless put_request =~ /^(.*?)(?:,((.*?):(N|S|B|NS|SS|BS):(.*?))*)+$/
      abort 'Invalid --put-requests format, see `awscli dynamo item help batch_write` for usage examples'
    end
  end
  options[:delete_requests] and options[:delete_requests].each do |delete_request|
    unless delete_request =~ /^(.*?)(?:,((N|S|B|NS|SS|BS)=(.*?))(:(N|S|B|NS|SS|BS)=(.*?))*)+$/
      abort 'Invalid --delete-requests format, see `awscli dynamo item help batch_write` for usage examples'
    end
  end
  create_dynamo_object
  @ddb.batch_write options
end

#deleteObject



116
117
118
119
120
121
122
123
124
125
# File 'lib/awscli/cli/dynamo/item.rb', line 116

def delete
  unless options[:table_name] and options[:hash_key]
    abort 'required options --table-name, --hash-key'
  end
  if options[:expected_exists]
    abort '--expected-exists only accepts true or false' unless %w(true false).include?(options[:expected_exists])
  end
  create_dynamo_object
  @ddb.delete options
end

#getObject



71
72
73
74
75
76
77
# File 'lib/awscli/cli/dynamo/item.rb', line 71

def get
  unless options[:table_name] and options[:hash_key]
    abort 'required options --table-name, --hash-key'
  end
  create_dynamo_object
  @ddb.get options
end

#putObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/awscli/cli/dynamo/item.rb', line 54

def put
  unless options[:table_name] and options[:item]
    abort 'required options --table-name, --item'
  end
  if options[:expected_exists]
    abort '--expected-exists only accepts true or false' unless %w(true false).include?(options[:expected_exists])
  end
  create_dynamo_object
  @ddb.put options
end

#queryObject



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/awscli/cli/dynamo/item.rb', line 144

def query
  unless options[:table_name] and options[:hash_key_value]
    abort 'options --table-name and --hash-key-value are required'
  end
  abort 'invalid --hash-key-value format' unless options[:hash_key_value] =~ /^(.*?),(.*?)$/
  if options[:scan_index_forward]
    abort 'invalid option --scan-index-forward value' unless options[:scan_index_forward] =~ /true|false/
  end
  if options[:range_key_filter]
    abort 'invalid --range-key-filter format' unless options[:range_key_filter] =~ /^(BETWEEN|BEGINS_WITH|EQ|LE|LT|GE|GT),(N|S|B|NS|SS|BS),(.*?)$/
  end
  if options[:start_key]
    abort 'Invalid --start-key format' unless options[:start_key] =~ /^(.*?),(.*?)$/
  end
  if options[:start_range_key]
    abort 'Invalid --start-range-key format' unless options[:start_range_key] =~ /^(.*?),(.*?)$/
  end
  create_dynamo_object
  @ddb.query options
end

#scanObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/awscli/cli/dynamo/item.rb', line 177

def scan
  unless options[:table_name]
    abort 'option --table-name is required.'
  end
  if options[:scan_filter]
    abort 'Invalid --scan-filter format' unless options[:scan_filter] =~ /^(BETWEEN|BEGINS_WITH|EQ|LE|LT|GE|GT),(.*?),(N|S|B|NS|SS|BS),(.*?)$/
  end
  if options[:start_key]
    abort 'Invalid --start-key format' unless options[:start_key] =~ /^(.*?),(.*?)$/
  end
  if options[:start_range_key]
    abort 'Invalid --start-range-key format' unless options[:start_range_key] =~ /^(.*?),(.*?)$/
  end
  create_dynamo_object
  @ddb.scan options
end

#updateObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/awscli/cli/dynamo/item.rb', line 92

def update
  unless options[:table_name] and options[:hash_key] and options[:attr_updates]
    abort 'required options --table-name, --hash-kye, --attr-updates'
  end
  if options[:expected_exists]
    abort '--expected-exists only accepts true or false' unless %w(true false).include?(options[:expected_exists])
  end
  create_dynamo_object
  @ddb.update options
end