Sha256: 3a02d75e9029906b4ec6b155d93fb9055a5ecc5e45fc4ad471de5790a13c4ef6

Contents?: true

Size: 1017 Bytes

Versions: 16

Compression:

Stored size: 1017 Bytes

Contents

module IntercomRails

  module Proxy

    class Company < Proxy

      proxy_delegator :id, :identity => true
      proxy_delegator :name
      proxy_delegator :created_at

      config_delegator :plan
      config_delegator :monthly_spend

      def self.companies_for_user(user)
        return unless config(:user).company_association.present?
        companies = config(:user).company_association.call(user.user)
        return unless companies.kind_of?(Array)

        companies.map { |company| new(company) }.select { |company_proxy| company_proxy.valid? }
      end

      def self.current_in_context(search_object)
        begin
          if config.current.present?
            company_proxy = new(search_object.instance_eval(&config.current), search_object) 
            return company_proxy if company_proxy.valid?
          end
        rescue NameError
        end

        raise NoCompanyFoundError 
      end

      def valid?
        company.present? && identity_present? 
      end

    end

  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
intercom-rails-0.2.24 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.23 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.22 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.21 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.20 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.19 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.18 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.17 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.16 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.15 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.14 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.13 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.12 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.11 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.10 lib/intercom-rails/proxy/company.rb
intercom-rails-0.2.9 lib/intercom-rails/proxy/company.rb