Class: Seedlings
- Inherits:
-
Object
- Object
- Seedlings
- Defined in:
- lib/seedlings.rb,
lib/seedlings/version.rb
Overview
Seedlings.rb
A Seeding system that handles all the annoying corner-cases for you.
Defined Under Namespace
Modules: ActiveModel
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#adapt! ⇒ Object
determine what manner of class we’ve been asked to seed and load the appropriate adapter.
-
#initialize(klass, options, data) ⇒ Seedlings
constructor
A new instance of Seedlings.
-
#plant! ⇒ Object
Get this planting party started.
- #plant_and_return(the_data) ⇒ Object
Constructor Details
#initialize(klass, options, data) ⇒ Seedlings
Returns a new instance of Seedlings.
19 20 21 22 23 24 |
# File 'lib/seedlings.rb', line 19 def initialize klass, , data self.klass = klass self. = { :update_existing => true }.merge() self.data = data adapt! end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/seedlings.rb', line 7 def data @data end |
#klass ⇒ Object
Returns the value of attribute klass.
7 8 9 |
# File 'lib/seedlings.rb', line 7 def klass @klass end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/seedlings.rb', line 7 def @options end |
Class Method Details
.plant(klass, options, *data) ⇒ Object
9 10 11 12 |
# File 'lib/seedlings.rb', line 9 def self.plant klass, , *data thang = new(klass, , data) thang.plant! end |
.plant_and_return(klass, options, data) ⇒ Object
14 15 16 17 |
# File 'lib/seedlings.rb', line 14 def self.plant_and_return klass, , data seedling = new(klass, , [data]) seedling.plant_and_return data end |
Instance Method Details
#adapt! ⇒ Object
determine what manner of class we’ve been asked to seed and load the appropriate adapter. Yes, I know it only does one thing now. N.B. I’m open to more efficient suggestions here.
30 31 32 |
# File 'lib/seedlings.rb', line 30 def adapt! extend Seedlings::ActiveModel end |
#plant! ⇒ Object
Get this planting party started
36 37 38 39 40 |
# File 'lib/seedlings.rb', line 36 def plant! data.each do |the_data| find_and_update_model_with the_data unless the_data.nil? end end |
#plant_and_return(the_data) ⇒ Object
42 43 44 |
# File 'lib/seedlings.rb', line 42 def plant_and_return the_data find_and_update_model_with the_data unless the_data.nil? end |