Sha256: 212d165147c465e0855521d0f13256ebfa3f827c22389c44189e77d9d5acbbd0

Contents?: true

Size: 687 Bytes

Versions: 7

Compression:

Stored size: 687 Bytes

Contents

require 'forwardable'

module Bogus
  class ActiveRecordAccessors
    extend Takes
    extend Forwardable

    takes :klass, :instance_methods

    def_delegators :model_methods, :remove, :define

    def all
      return [] unless klass < ActiveRecord::Base
      return missing_attributes
    end

    def get(name)
      Attribute.new(name)
    end

    private

    def model_methods
      instance_methods.call(klass)
    end

    def all_attributes
      klass.columns.map(&:name).map(&:to_sym)
    end

    def missing_attributes
      all_attributes - model_methods.all
    end

    class Attribute < Struct.new(:name)
      def parameters
        []
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bogus-0.1.7 lib/bogus/fakes/active_record_accessors.rb
bogus-0.1.6 lib/bogus/fakes/active_record_accessors.rb
bogus-0.1.5 lib/bogus/fakes/active_record_accessors.rb
bogus-0.1.4 lib/bogus/fakes/active_record_accessors.rb
bogus-0.1.3 lib/bogus/active_record_accessors.rb
bogus-0.1.2 lib/bogus/active_record_accessors.rb
bogus-0.1.1 lib/bogus/active_record_accessors.rb