Sha256: 77304d0e07513e82dcfa4f7702b17ecb4b95bff37809f4e75e20153a3e4d4ffc

Contents?: true

Size: 1.04 KB

Versions: 36

Compression:

Stored size: 1.04 KB

Contents

module Ticket::Foundry
  extend ActiveSupport::Concern

  module ClassMethods
    def foundry(options = {})
      foundry_setup_next(options[:using])
      foundry_setup_attr(options[:with])
    end

    private

    def foundry_setup_next(using)
      define_method(:foundry_using_next) { send(using) } if using.present?
    end

    def foundry_setup_attr(with)
      with ||= lambda { Hash.new }
      define_method(:foundry_attributes, &with)
    end
  end

  def create_tickets
    Ticket.import(build_tickets)
  end

  def build_tickets
    foundry_template.collect(&:build).flatten
  end

  def foundry_template
    if respond_to?(:foundry_using_next)
      template = next_template
      template.each { |template| template.update_attributes(foundry_attributes) }
    else
      Ticket::Template.new(foundry_attributes)
    end
  end

  private

    def next_template
      if foundry_using_next.respond_to?(:collect)
        foundry_using_next.collect(&:foundry_template)
      else
        Array.wrap(foundry_using_next.foundry_template)
      end
    end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.10 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.9 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.8 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.7 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.6 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.5 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.4 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.3 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.2 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.1 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre app/models/ticket/foundry.rb
artfully_ose-1.1.0 app/models/ticket/foundry.rb
artfully_ose-1.1.0.rc2 app/models/ticket/foundry.rb
artfully_ose-1.1.0.rc1 app/models/ticket/foundry.rb
artfully_ose-1.0.0.rc4 app/models/ticket/foundry.rb
artfully_ose-1.0.0.rc3 app/models/ticket/foundry.rb