Sha256: eef10bb6b622f88e6954c7f4505a1e43398166b47d261dd0fe473d6ef9c713ad

Contents?: true

Size: 1.15 KB

Versions: 12

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module RailsBestPractices
  module Core
    # Model attributes container.
    class ModelAttributes
      def initialize
        @attributes = {}
      end

      # Add a model attribute.
      #
      # @param [String] model name
      # @param [String] attribute name
      # @param [String] attribute type
      def add_attribute(model_name, attribute_name, attribute_type)
        @attributes[model_name] ||= {}
        @attributes[model_name][attribute_name] = attribute_type
      end

      # Get attribute type.
      #
      # @param [String] model name
      # @param [String] attribute name
      # @return [String] attribute type
      def get_attribute_type(model_name, attribute_name)
        @attributes[model_name] ||= {}
        @attributes[model_name][attribute_name]
      end

      # If it is a model's attribute.
      #
      # @param [String] model name
      # @param [String] attribute name
      # @return [Boolean] true if it is the model's attribute
      def is_attribute?(model_name, attribute_name)
        @attributes[model_name] ||= {}
        !!@attributes[model_name][attribute_name]
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rails_best_practices-1.23.2 lib/rails_best_practices/core/model_attributes.rb
rails_best_practices-1.23.1 lib/rails_best_practices/core/model_attributes.rb
rails_best_practices-1.23.0 lib/rails_best_practices/core/model_attributes.rb
rails_best_practices-1.22.1 lib/rails_best_practices/core/model_attributes.rb
rails_best_practices-1.22.0 lib/rails_best_practices/core/model_attributes.rb
rails_best_practices-1.21.0 lib/rails_best_practices/core/model_attributes.rb
rails_best_practices-1.20.1 lib/rails_best_practices/core/model_attributes.rb
rails_best_practices-1.20.0 lib/rails_best_practices/core/model_attributes.rb
rails_best_practices-1.19.5 lib/rails_best_practices/core/model_attributes.rb
rails_best_practices-1.19.4 lib/rails_best_practices/core/model_attributes.rb
rails_best_practices-1.19.3 lib/rails_best_practices/core/model_attributes.rb
rails_best_practices-1.19.2 lib/rails_best_practices/core/model_attributes.rb