Sha256: 5b6787dbb9f0d1ce2984cf18f809a6cd529487328d07d5c6cf78b2ca338995bf

Contents?: true

Size: 1.54 KB

Versions: 36

Compression:

Stored size: 1.54 KB

Contents

module Kaui
  module RailsMethods

    def self.included(base_class)
      base_class.class_eval do
        # Required to build urls in views
        extend  ActiveModel::Naming
        include ActiveModel::Validations
        # Required to make form_for work
        include ActiveModel::Conversion

        def ==(other)
          !other.nil? && self.class == other.class && self.to_hash == other.to_hash
        end

        def persisted?
          # Hard to know...
          false
        end

        def new_record?
          !persisted?
        end

        def to_param
          # Hard to know (depends on the model)...
          nil
        end

        def read_attribute_for_validation(attr)
          send(attr)
        end

        def save
          @errors.add(:save, 'Saving this object is not yet supported')
          false
        end

        def update_attributes(tag_definition)
          @errors.add(:update, 'Updating this object is not yet supported')
          false
        end

        def destroy
          @errors.add(:destroy, 'Destroying this object is not yet supported')
          false
        end

      end # end instance methods

      base_class.instance_eval do
        def self.human_attribute_name(attr, options = {})
          attr
        end

        def self.lookup_ancestors
          [self]
        end

        def self.all
          []
        end

        def self.count
          all.count
        end

        def self.find(id)
          nil
        end
      end # end class methods
    end # end def included
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
kaui-2.1.0 app/models/kaui/rails_methods.rb
kaui-2.0.4 app/models/kaui/rails_methods.rb
kaui-2.0.3 app/models/kaui/rails_methods.rb
kaui-2.0.2 app/models/kaui/rails_methods.rb
kaui-2.0.1 app/models/kaui/rails_methods.rb
kaui-2.0.0 app/models/kaui/rails_methods.rb
kaui-1.4.1 app/models/kaui/rails_methods.rb
kaui-1.4.0 app/models/kaui/rails_methods.rb
kaui-1.3.0 app/models/kaui/rails_methods.rb
kaui-1.2.0 app/models/kaui/rails_methods.rb
kaui-1.1.0 app/models/kaui/rails_methods.rb
kaui-1.0.0 app/models/kaui/rails_methods.rb
kaui-0.16.2 app/models/kaui/rails_methods.rb
kaui-0.16.1 app/models/kaui/rails_methods.rb
kaui-0.16.0 app/models/kaui/rails_methods.rb
kaui-0.15.5 app/models/kaui/rails_methods.rb
kaui-0.15.4 app/models/kaui/rails_methods.rb
kaui-0.15.3 app/models/kaui/rails_methods.rb
kaui-0.15.2 app/models/kaui/rails_methods.rb
kaui-0.15.1 app/models/kaui/rails_methods.rb