Sha256: b4bb8aab93dbc7ed759076b6555289a43c1e247fea599f4c9dbe528df6b50dcb

Contents?: true

Size: 938 Bytes

Versions: 8

Compression:

Stored size: 938 Bytes

Contents

module Tito
  class Event < Base    
    belongs_to :account

    property :title, type: :string
    property :security_token, type: :string

    def account_id
      attributes['account_id'] || attributes['account-id']
    end

    def account_id=(val)
      attributes['account_id'] = val
    end

    def security_token
      attributes['security_token'] || attributes['security-token']
    end

    class << self

      def get(path)
        parts = path.split('/')
        where(account_id: parts[0]).find(parts[1]).first
      end

      def path(params=nil)
        prefix_path = '%{account_id}'
        path_params = params.delete(:path) || params
        parts = [].unshift(prefix_path % path_params.symbolize_keys)
        if !params[:id]
          parts << 'events'
        end
        File.join(*parts)
        rescue KeyError
          raise ArgumentError, "Please make sure to include account_id"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tito-0.1.11 lib/tito/event.rb
tito-0.1.10 lib/tito/event.rb
tito-0.1.9 lib/tito/event.rb
tito-0.1.8 lib/tito/event.rb
tito-0.1.7 lib/tito/event.rb
tito-0.1.6 lib/tito/event.rb
tito-0.1.4 lib/tito/event.rb
tito-0.1.3 lib/tito/event.rb