Sha256: 2228d8b061f3d57422ce28d6a9e51292aaeba6a75d786999f3b133170f5dfcce

Contents?: true

Size: 905 Bytes

Versions: 1

Compression:

Stored size: 905 Bytes

Contents

module Microscope
  class InstanceMethod
    class BooleanInstanceMethod < InstanceMethod
      def apply
        infinitive_verb = self.class.past_participle_to_infinitive(field.name)

        model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
          define_method "#{infinitive_verb}!" do
            send("#{field.name}=", true)
            save!
          end

          define_method "not_#{infinitive_verb}!" do
            send("#{field.name}=", false)
            save!
          end
          alias_method 'un#{infinitive_verb}!', 'not_#{infinitive_verb}!'

          define_method "mark_as_#{field.name}" do
            send("#{field.name}=", true)
          end

          define_method "mark_as_not_#{field.name}" do
            send("#{field.name}=", false)
          end
          alias_method 'mark_as_un#{field.name}', 'mark_as_not_#{field.name}'
        RUBY
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
microscope-0.6.1 lib/microscope/instance_method/boolean_instance_method.rb