Class: Gorillib::Factory::BaseFactory
- Defined in:
- lib/gorillib/factories.rb
Overview
A gorillib Factory should answer to the following:
typename
-- a handle (symbol, lowercased-underscored) naming this typenative?
-- native objects do not need type-conversionblankish?
-- blankish objects are type-converted to anil
valueproduct
-- the class of objects produced when non-blankreceive
-- performs the actual conversion
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#blankish?(obj) ⇒ true, false
A
blankish
object should be converted tonil
, not a value. -
#initialize(options = {}) ⇒ BaseFactory
constructor
A new instance of BaseFactory.
-
#native?(obj) ⇒ true, false
A
native
object does not need any transformation; it is accepted directly. -
#receive(*args) ⇒ Object
performs the actual conversion.
- #typename ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BaseFactory
Returns a new instance of BaseFactory.
61 62 63 64 65 66 |
# File 'lib/gorillib/factories.rb', line 61 def initialize(={}) @product = .delete(:product){ self.class.product } define_blankish_method(.delete(:blankish)) if .has_key?(:blankish) redefine(:convert, .delete(:convert)) if .has_key?(:convert) warn "Unknown options #{.keys}" unless .empty? end |
Class Method Details
.blankish?(obj) ⇒ Boolean
90 91 92 |
# File 'lib/gorillib/factories.rb', line 90 def self.blankish?(obj) obj.nil? || (obj == "") end |
.native?(obj) ⇒ Boolean
81 |
# File 'lib/gorillib/factories.rb', line 81 def self.native?(obj) self.new.native?(obj) ; end |
.typename ⇒ Object
68 69 70 |
# File 'lib/gorillib/factories.rb', line 68 def self.typename @typename ||= Gorillib::Inflector.underscore(product.name).to_sym end |
Instance Method Details
#blankish?(obj) ⇒ true, false
A blankish
object should be converted to nil
, not a value
87 88 89 |
# File 'lib/gorillib/factories.rb', line 87 def blankish?(obj) obj.nil? || (obj == "") end |
#native?(obj) ⇒ true, false
A native
object does not need any transformation; it is accepted directly.
By default, an object is native if it is_a?(product)
78 79 80 |
# File 'lib/gorillib/factories.rb', line 78 def native?(obj) obj.is_a?(@product) end |
#receive(*args) ⇒ Object
performs the actual conversion
95 96 97 |
# File 'lib/gorillib/factories.rb', line 95 def receive(*args) NoMethodError.abstract_method(self) end |
#typename ⇒ Object
71 |
# File 'lib/gorillib/factories.rb', line 71 def typename ; self.class.typename ; end |