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.3.0.pre3 app/models/ticket/foundry.rb
artfully_ose-1.3.0.pre2 app/models/ticket/foundry.rb
artfully_ose-1.3.0.pre1 app/models/ticket/foundry.rb
artfully_ose-1.2.0 app/models/ticket/foundry.rb
artfully_ose-1.2.0.beta.1 app/models/ticket/foundry.rb
artfully_ose-1.2.0.alpha.2 app/models/ticket/foundry.rb
artfully_ose-1.2.0.alpha.1 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.27 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.26 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.24 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.23 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.21 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.20 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.19 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.18 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.17 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.16 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.15 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.12 app/models/ticket/foundry.rb
artfully_ose-1.2.0.pre.11 app/models/ticket/foundry.rb