lib/netzke/basepack/attr_config.rb in netzke-basepack-0.12.9 vs lib/netzke/basepack/attr_config.rb in netzke-basepack-1.0.0.0.pre
- old
+ new
@@ -1,42 +1,51 @@
module Netzke
module Basepack
- # Common parts of FieldConfig and ColumnConfig
+ # Base for FieldConfig and ColumnConfig
class AttrConfig < ActiveSupport::OrderedOptions
- def initialize(c, data_adapter)
+ def initialize(c, model_adapter)
c = {name: c.to_s} if c.is_a?(Symbol) || c.is_a?(String)
c[:name] = c[:name].to_s
self.replace(c)
- @data_adapter = data_adapter || NullDataAdapter.new(nil)
+ @model_adapter = model_adapter
end
def primary?
- @data_adapter.primary_key_attr?(self)
+ @model_adapter.primary_key_attr?(self)
end
def association?
- @data_adapter.association_attr?(self)
+ @model_adapter.association_attr?(self)
end
- def set_defaults!
- set_read_only! if read_only.nil?
+ def set_defaults
+ set_read_only if read_only.nil?
end
- def set_read_only!
+ def set_read_only
self.read_only = primary? ||
!responded_to_by_model? &&
!association?
+ self.delete(:read_only) if read_only == false
end
private
+ def default_label
+ if association?
+ @model_adapter.human_attribute_name(name.split("__").first)
+ else
+ @model_adapter.human_attribute_name(name)
+ end
+ end
+
def responded_to_by_model?
# if no model class is provided, assume the attribute is being responded to
- @data_adapter.model_class.nil? ||
+ @model_adapter.model.nil? ||
!setter.nil? ||
- @data_adapter.model_class.instance_methods.include?(:"#{name}=") ||
- @data_adapter.model_class.attribute_names.include?(name)
+ @model_adapter.model.instance_methods.include?(:"#{name}=") ||
+ @model_adapter.model.attribute_names.include?(name)
end
end
end
end