rubyisms #51

Merged
merged 64 commits into from Jul 1, 2014

Projects

None yet

1 participant

@mattly
mattly commented Jun 18, 2014

The basics:

app = Orchestrate::Application.new "your api key"
users = app[:users]

Application is currently a very thin wrapper around Client, and is constructed the same way. I eventually plan to put a factory on the base Orchestrate module with a memoized accessor.

Collection is pretty basic for now, but here's some things it can do:

users.create(:rich, {"name" => "Richard"}) # performs put-if-absent, returns KeyValue
users.set(:rich, {"name" => "Rich"}) # performs put, returns KeyValue
users[:rich] = {"name" => "Richard III"} # performs put, returns input (per ruby standard)
users[:rich] # returns KV

I've also got a very loose work-in-progress Lazy Enumerable around the list query by implementing Enumerable in collection. So you can do for example:

users.map {|user| [user.key, user.refime] }

to iterate over all the items in the collection (10 at a time). I'm trying to think about scoping and whatnot, with start/end/etc and limits. The ruby way to do limits would be users.take(15).map {|u| ... } but
I have no way to say, do a larger query because I know I only need 15 users. So, thinking about this.

Here's some stuff with KeyValue:

rich = users[:rich]
rich.value  # the item's value
rich[:name] # does a lookup against the item's value, converting keys to strings as needed
rich[:name] = "Dick" # again, converts the key to a string
if rich.save     # performs put-if-match with current ref, returns boolean for success/failure.  indexing_conflict error is considered success.
  puts rich.ref  # the new ref from the response
else
  rich.reload!   # retrieves the current value
  # ...
  rich.save!     # performs put-if-match, raises on exception.  indexing_conflict is again considered a success.
end

There's also KeyValue#destroy and KeyValue#destroy! that perform delete-if-match and the bang version raises on error. The bang version raising on error is a convention from rails I've adopted.

Next up, I'm going to round out the list and search stuff on collection, and go back to KV and do Refs.

@mattly
mattly commented Jun 24, 2014

On further thought, I think we have enough here to incorporate into a release. Of course, it's not complete yet, but working with KeyValue items is already much nicer. I'm also allergic to long-running feature branches.

@mattly mattly changed the title from WIP rubyisms to rubyisms Jun 24, 2014
@mattly
mattly commented Jun 24, 2014

Barring any objection, I'm going to release this stuff in 0.7 next week. There's enough stuff here with the basic KeyValue interaction to be useful, and I'd prefer to get it into people's hands. I'm going to block out tickets for the remaining parts of the API.

@mattly mattly added this to the map API objects to Ruby milestone Jun 25, 2014
mattly added some commits Jun 16, 2014
@mattly mattly Orchestrate::Application constructor
baby steps
a63005a
@mattly mattly Orchestrate::Collection 1b8cf14
@mattly mattly Collection#destroy! b3f395b
@mattly mattly Collection#[] 679bb55
@mattly mattly KeyValue#load / #initialize WIP 0655830
@mattly mattly Collection#[] returns nil on NotFound 8c28820
@mattly mattly KeyValue#[], #[]= 08ecaed
@mattly mattly KeyValue#save handles failure cases 990e96e
@mattly mattly KeyValue#save! 19367bd
@mattly mattly refactor common errors to helper 1e13cb6
@mattly mattly resolve test class name conflict e796221
@mattly mattly KeyValue#destroy, #destroy! f82d9a9
@mattly mattly KV persistence tests extracted acec67d
@mattly mattly leftovers from previous 457276b
@mattly mattly tests in one place f376db7
@mattly mattly KV#last_request_time 69bb2a8
@mattly mattly KeyValue#destroy[!?] unsets the ref
The thinking here:

1) Delete sets the value of the key on the service to a null object

2) #save[!?] normally sends If-Match with the value of @ref

3) The key still exists, you can get the full ref history, etc.  You can
re-create it, and keepings its value around may prove useful.

4) If you call #save again on the deleted KV, it will save without the
'If-Match' header
331c8e2
@mattly mattly resovle CollectionTest conflict 525900f
@mattly mattly Collection#[]= and #set for KV f544f81
@mattly mattly WIP Collection#create 765a48d
@mattly mattly Collection#create does put-if-absent 8e6c39c
@mattly mattly custom inspectors for Application, Collection, KeyValue 5e96f08
@mattly mattly ping -> head in tests fa5b320
@mattly mattly first shot at Collection#each 5d12903
@mattly mattly Collections are enumerable 3628c55
@mattly mattly KeyValue#initialize takes a listing 55dd249
@mattly mattly KeyValue uses last_request_time for #loaded? f99734d
@mattly mattly KeyValue#initialize w/ listing takes ts 61e5ebc
@mattly mattly KeyValue#reftime 0d1b8c4
@mattly mattly Collection#each yields KV docs 09f6e91
@mattly mattly test that Collecton#each is lazy 63160d3
@mattly mattly doc for Application 4379c61
@mattly mattly Collection#create rescues AlreadyPresent 5f4f30c
@mattly mattly Collection gets yardoc d309541
@mattly mattly KeyValue get docs 7ce77d2
@mattly mattly cleanup variable rename 022be3a
@mattly mattly KeyValue#purge test and code 01dc4d7
@mattly mattly KeyValue#purge docs 717cf38
@mattly mattly Collection#delete ad3230e
@mattly mattly Collection#purge a28b200
@mattly mattly Collection#delete/purge docs f1dd230
@mattly mattly isolate Collection KV tests 8e6022d
@mattly mattly test names for create b5dc6d0
@mattly mattly Collection#create does post, too b8219d4
@mattly mattly docs for Collection#create overload to post 4d7271f
@mattly mattly Collection#<< performs post cacc7e1
@mattly mattly refactor KeyValue#create to use << for post 918e6d6
@mattly mattly Collection#<< docs 759300f
@mattly mattly document Collection class 5dc8ede
@mattly mattly Collection#== f156b9c
@mattly mattly Collection#<=> aaa6713
@mattly mattly include api key in equality/sorting 752bc38
@mattly mattly Colleciton, moving around f0850d1
@mattly mattly KeyValue, moving around 37ea269
@mattly mattly KeyValue#==, #eql? 8a473fa
@mattly mattly Collection#==, #<=> docs, note api_key db623ad
@mattly mattly KeyValue#<=> cbf3367
@mattly mattly migrate client test to Minitest::Unit ddb3520
@mattly mattly KeyValue handles parallel response for #load 480ae11
@mattly mattly refactoring KV loading afb3c5b
@mattly mattly KV Enumeration in parallel 0d6657b
@mattly mattly docs for previous commit a361ddc
@mattly mattly don't try Enumerable#lazy on 1.9 8410ec6
@mattly mattly fix 1.9 failing test f311484
@mattly mattly merged commit f311484 into master Jul 1, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@mattly mattly deleted the mattly/25-rubyish branch Jul 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment