Sha256: 5655bc3887bc3b11313a530e4724a82d14056c5030ecb4e14eae52ca0d06361f

Contents?: true

Size: 596 Bytes

Versions: 4

Compression:

Stored size: 596 Bytes

Contents

require 'activerecord'

module ActiveRecord
  class Base
    def self.blueprint(*args)
      options = args.extract_options!
      if args.present?
        klass = self
        Blueprints::Plan.new(*args) do
          klass.blueprint options
        end
      else
        returning(self.new) do |object|
          options.each do |attr, value|
            value = Blueprints::Namespace.root.context.instance_variable_get(value) if value.is_a? Symbol and value.to_s =~ /^@.+$/
            object.send("#{attr}=", value)
          end
          object.save!
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blueprints-0.3.3 lib/blueprints/ar_extensions.rb
blueprints-0.3.2 lib/blueprints/ar_extensions.rb
blueprints-0.3.1 lib/blueprints/ar_extensions.rb
blueprints-0.3.0 lib/blueprints/ar_extensions.rb