README.md in pliable-0.1.0 vs README.md in pliable-0.2.0

- old
+ new

@@ -4,11 +4,13 @@ |------------------------ | ----------------- | | Gem name | pliable | | License | [MIT](LICENSE.txt) | | Version | [![Gem Version](https://badge.fury.io/rb/pliable.png)](http://badge.fury.io/rb/pliable) | | Continuous Integration | [![Build Status](https://travis-ci.org/mfpiccolo/pliable.png?branch=master)](https://travis-ci.org/mfpiccolo/pliable) -Z| Grade | [![Code Climate](https://codeclimate.com/github/mfpiccolo/pliable.png)](https://codeclimate.com/github/mfpiccolo/pliable) +| Test Coverage | [![Coverage Status](https://coveralls.io/repos/mfpiccolo/pliable/badge.png?branch=master)](https://coveralls.io/r/mfpiccolo/pliable?branch=coveralls) +| Grade | [![Code Climate](https://codeclimate.com/github/mfpiccolo/pliable.png)](https://codeclimate.com/github/mfpiccolo/pliable) +| Dependencies | [![Dependency Status](https://gemnasium.com/mfpiccolo/pliable.png)](https://gemnasium.com/mfpiccolo/pliable) | Homepage | [http://mfpiccolo.github.io/pliable][homepage] | | Documentation | [http://rdoc.info/github/mfpiccolo/pliable/frames][documentation] | | Issues | [https://github.com/mfpiccolo/pliable/issues][issues] | ## Description @@ -37,11 +39,11 @@ Pliable allows you to save individual records from external schemaless databases into your postgres backed rails apps. We store all of the data in a plies table. The Ply model contains logic that allows you to inherit from Ply and then act as if these iherited models are normal Active Record models. -Here is the Ply model your generator created: +Here is the Ply model your generator created by running `rails g pliable:models`: ```ruby class Ply < Pliable::Ply # Define methods here that you want all you Ply backed models to have. end @@ -49,11 +51,11 @@ Now you can create a model that is backed by Ply. ```ruby class Foo < Ply - # This is redundant if it is the same name ass the class but required for now. + # This is redundant if it is the same name as the class but required for now. ply_name "Foo" # Define methods that you only want Foo to have. end ``` @@ -112,11 +114,11 @@ ```ruby # Notice it inherits from Pliable::Ply class Ply < Pliable::Ply - # Define methods here that you want all of your models to have + # Define methods here that you want all of your Ply inherited models to have def anything_you_like puts "I can play disco all night" end end @@ -128,16 +130,18 @@ # Notice it inherits from your apps Ply class Invoice < Ply # If you dont put this you will get all Ply records. # This is the name that you have put into the otype attribute. - # In this example I just used the exact salesforce api name + # In this example I just used the exact salesforce api name. + # This is also why we need the configuration to strip off "__c" + # for pluralization. ply_name "Invoice__c" # Add Invoice specific methods here def what_dosnt_gather_moss? - "A rolling stone!" + puts "A rolling stone!" end end ``` @@ -148,26 +152,16 @@ ply_name "Line_Item__c" # You guessed it. LineItem specific methods here. def best_pliable_quote - "Facts are stubborn, but statistics are more pliable. - Mark Twain" + puts "Facts are stubborn, but statistics are more pliable. - Mark Twain" end end ``` -Here is your PlyRelation model: - -```ruby -# This will probably not be needed in the future and will live in the gem -class PlyRelation < ActiveRecord::Base - belongs_to :parent, class_name: 'Ply' - belongs_to :child, class_name: 'Ply' -end -``` - A service object for pulling salesforce data into your app: ```ruby class SalesforceSynch @@ -191,44 +185,41 @@ #Fake service object that sets up a client to connect to databasedotcom @client = ConnectToDatabasedotcom.call(user.salesforce_credentials) end def create_plys_from_salesforce_records - data = [] - - # sf_api model names as strings in array records = [] # User has_many :plies in this example (i.e. user.plies) client.get_the_records_you_want.each do |record| object = user.plies.find_or_create_by(oid: record.Id) object.update_attributes( # The data attribute is a json column. This is where you store all shcemaless data. data: record.attributes, - # Whatever the service calls the object (i.e. Invoice__c for salesforce) + # Whatever the service calls the object (i.e. "Invoice__c" for salesforce) otype: record.salesforce_api_name, # Use last_checked and last_modified to know when you need to update a record last_checked: Time.zone.now ) end end - # Dynamically deduce if there is a relationship with any of the plys that have been imported. + # Dynamically deduce if there is a relationship with any of the plies that have been imported. # In the case of saleforce the id of related object is stored by using the name of that # object as a key. (ie "Invoice__c" => "long_uiniq_id"). In this app users choose a few models - # that they want to bring over but you could easily just get everything. + # that they want to bring over (i.e user.model_names). user.plies.each do |ply| related_model_names = ply.instance_variables.map {|e| e.to_s.gsub("@", "") } & user.model_names related_model_names.each do |name| child = Ply.find_by_oid(ply.send(name.to_sym)) unless PlyRelation.where(parent_id: record.id, child_id: child.id).present? ply.children.new( parent_id: ply.id, parent_type: ply.otype, child_id: ply.id, child_type: ply.otype - ).save # #create does not work yet. Sorry + ).save # #create does not work yet. Sorry end end end end end @@ -244,11 +235,11 @@ invoice.line_items => #<ActiveRecord::AssociationRelation [#<Pliable::Ply id: 2 ...> invoice.line_items.first.invoices.find(invoice.id) === invoice => true -invoice.SalesForceCustomAttribute__c => Whatever it is in salesforce. +invoice.SalesForceCustomAttribute__c => # Whatever it is in salesforce. Invoice.all => #<ActiveRecord::Relation [#<Invoice id: 136, user_id: 1...> LineItem.first => #<LineItem id: 145, user_id: 1...> @@ -276,10 +267,10 @@ 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request -[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/e1a155a07163d56ca0c4f246c7aa8766 "githalytics.com")](http://githalytics.com/mfpiccolo/pliable) +[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/3d22924e211bdc891d3ad124e085a595 "githalytics.com")](http://githalytics.com/mfpiccolo/pliable) [license]: https://github.com/mfpiccolo/pliable/MIT-LICENSE [homepage]: http://mfpiccolo.github.io/pliable [documentation]: http://rdoc.info/github/mfpiccolo/pliable/frames [issues]: https://github.com/mfpiccolo/pliable/issues