Class: ProjectAdapter::Adapter
- Inherits:
-
Object
- Object
- ProjectAdapter::Adapter
- Defined in:
- app/concerns/project_adapter.rb
Instance Attribute Summary collapse
-
#attribute_name ⇒ Object
readonly
Returns the value of attribute attribute_name.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #define_methods! ⇒ Object
-
#initialize(model, adapter_module) ⇒ Adapter
constructor
A new instance of Adapter.
- #title ⇒ Object
- #validation_method ⇒ Object
Constructor Details
#initialize(model, adapter_module) ⇒ Adapter
Returns a new instance of Adapter.
27 28 29 30 31 32 |
# File 'app/concerns/project_adapter.rb', line 27 def initialize(model, adapter_module) @model = model @namespace = adapter_module @name = adapter_module.name @attribute_name = name.demodulize.underscore end |
Instance Attribute Details
#attribute_name ⇒ Object (readonly)
Returns the value of attribute attribute_name.
34 35 36 |
# File 'app/concerns/project_adapter.rb', line 34 def attribute_name @attribute_name end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
34 35 36 |
# File 'app/concerns/project_adapter.rb', line 34 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'app/concerns/project_adapter.rb', line 34 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
34 35 36 |
# File 'app/concerns/project_adapter.rb', line 34 def namespace @namespace end |
Instance Method Details
#define_methods! ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/concerns/project_adapter.rb', line 44 def define_methods! model.module_eval <<-RUBY def self.with_#{attribute_name} where arel_table[:#{attribute_name}_name].not_eq("None") end def has_#{attribute_name}? #{attribute_name}_name != "None" end def #{validation_method} #{attribute_name}_adapter.errors_with_parameters(self, *parameters_for_#{attribute_name}_adapter.values).each do |attribute, messages| errors.add(attribute, messages) if messages.any? end end def #{attribute_name} @#{attribute_name} ||= #{attribute_name}_adapter .build(self, *parameters_for_#{attribute_name}_adapter.values) .extend(FeatureSupport) end def parameters_for_#{attribute_name}_adapter #{attribute_name}_adapter.parameters.each_with_object({}) do |parameter, hash| hash[parameter] = extended_attributes[parameter.to_s] end end def #{attribute_name}_adapter #{namespace}.adapter(#{attribute_name}_name) end RUBY end |
#title ⇒ Object
36 37 38 |
# File 'app/concerns/project_adapter.rb', line 36 def title name.demodulize.titleize end |
#validation_method ⇒ Object
40 41 42 |
# File 'app/concerns/project_adapter.rb', line 40 def validation_method :"#{attribute_name}_configuration_is_valid" end |