Class: DataShift::Operator
- Inherits:
-
Object
- Object
- DataShift::Operator
- Includes:
- Logging
- Defined in:
- lib/datashift/model_methods/operator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#operator ⇒ Object
readonly
The :operator that can be called to assign e.g orders or Products.new.orders << Order.new.
-
#operator_type ⇒ Object
readonly
The type of operator e.g normal method or Rails :assignment, :belongs_to, :has_one, :has_many etc.
Class Method Summary collapse
-
.supported_types_enum ⇒ Object
List of supported operator types e.g :assignment, :belongs_to, :has_one, :has_many etc N.B these are in priority order ie.
Instance Method Summary collapse
-
#initialize(operator, type = :method) ⇒ Operator
constructor
Operator is a population type method call Type determines the style of operator call; simple assignment, an association or a method call.
- #operator?(name, case_sensitive = false) ⇒ Boolean
-
#operator_for(type) ⇒ Object
Return the actual operator’s name for supplied method type where type one of :assignment, :has_one, :belongs_to, :has_many etc.
- #operator_type?(type) ⇒ Boolean
Methods included from Logging
#logdir, #logdir=, #logger, #verbose
Constructor Details
#initialize(operator, type = :method) ⇒ Operator
Operator is a population type method call Type determines the style of operator call; simple assignment, an association or a method call
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/datashift/model_methods/operator.rb', line 34 def initialize(operator, type = :method) type_as_sym = type.to_sym if ModelMethod.supported_types_enum.include?(type_as_sym) @operator_type = type_as_sym else raise BadOperatorType, "No such operator Type [#{type_as_sym}] cannot instantiate ModelMethod for #{operator}" end @operator = operator.to_s.strip end |
Instance Attribute Details
#operator ⇒ Object (readonly)
The :operator that can be called to assign e.g orders or Products.new.orders << Order.new
26 27 28 |
# File 'lib/datashift/model_methods/operator.rb', line 26 def operator @operator end |
#operator_type ⇒ Object (readonly)
The type of operator e.g normal method or Rails :assignment, :belongs_to, :has_one, :has_many etc
29 30 31 |
# File 'lib/datashift/model_methods/operator.rb', line 29 def operator_type @operator_type end |
Class Method Details
.supported_types_enum ⇒ Object
List of supported operator types e.g :assignment, :belongs_to, :has_one, :has_many etc N.B these are in priority order ie. often prefer to process assignments first, then associations
20 21 22 23 |
# File 'lib/datashift/model_methods/operator.rb', line 20 def self.supported_types_enum @type_enum ||= [:assignment, :enum, :belongs_to, :has_one, :has_many, :method] @type_enum end |
Instance Method Details
#operator?(name, case_sensitive = false) ⇒ Boolean
54 55 56 57 |
# File 'lib/datashift/model_methods/operator.rb', line 54 def operator?(name, case_sensitive = false) return false if(name.nil?) case_sensitive ? operator == name : operator.casecmp(name.downcase).zero? end |
#operator_for(type) ⇒ Object
Return the actual operator’s name for supplied method type where type one of :assignment, :has_one, :belongs_to, :has_many etc
49 50 51 52 |
# File 'lib/datashift/model_methods/operator.rb', line 49 def operator_for( type ) return operator if @operator_type == type.to_sym nil end |
#operator_type?(type) ⇒ Boolean
59 60 61 |
# File 'lib/datashift/model_methods/operator.rb', line 59 def operator_type?(type) @operator_type == type.to_sym end |