Sha256: d57d942c2150ad5d6359099af9beadca24ea6ddaf22662e9986173fa0844b23e

Contents?: true

Size: 1.08 KB

Versions: 23

Compression:

Stored size: 1.08 KB

Contents

module Netzke
  module Basepack
    # Common parts of FieldConfig and ColumnConfig
    class AttrConfig < ActiveSupport::OrderedOptions
      def initialize(c, data_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)
      end

      def primary?
        @data_adapter.primary_key_attr?(self)
      end

      def association?
        @data_adapter.association_attr?(self)
      end

      def set_defaults!
        set_read_only! if read_only.nil?
      end

      def set_read_only!
        self.read_only = primary? ||
          !responded_to_by_model? &&
          !association?
      end

    private

      def responded_to_by_model?
        # if no model class is provided, assume the attribute is being responded to
        @data_adapter.model_class.nil? ||
          !setter.nil? ||
          @data_adapter.model_class.instance_methods.include?(:"#{name}=") ||
          @data_adapter.model_class.attribute_names.include?(name)
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
netzke-basepack-0.12.9 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.12.8 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.12.7 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.12.6 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.12.5 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.12.4 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.12.3 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.12.2 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.12.1 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.11.2 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.11.1 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.12.0 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.12.0.rc1 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.12.0.beta lib/netzke/basepack/attr_config.rb
netzke-basepack-0.11.0 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.10.1 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.10.0 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.9.0 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.10.0.rc2 lib/netzke/basepack/attr_config.rb
netzke-basepack-0.9.0.rc1 lib/netzke/basepack/attr_config.rb