Sha256: feeeba9b0379ad2343cd4d77b33e37ba9b5847f8ac9f3ac7d7c3c74a5e892fe9

Contents?: true

Size: 996 Bytes

Versions: 9

Compression:

Stored size: 996 Bytes

Contents

module RedboothRuby
  class Base
    include RedboothRuby::Operations::Base

    attr_accessor :created_time, :session

    # Initializes the object using the given attributes
    #
    # @param [Hash] attributes The attributes to use for initialization
    def initialize(attributes = {})
      set_attributes(attributes)
      parse_timestamps
    end

    # Model validations
    #
    # @return [Boolean]
    def valid?
      errors.empty?
    end

    # Accesor for the errors
    #
    def errors
      @errors || []
    end

    # Sets the attributes
    #
    # @param [Hash] attributes The attributes to initialize
    def set_attributes(attributes)
      attributes.each_pair do |key, value|
        instance_variable_set("@#{key}", value)
      end
    end

    # Parses UNIX timestamps and creates Time objects.
    def parse_timestamps
      @created_time = created_time.to_i if created_time.is_a? String
      @created_time = Time.at(created_time) if created_time
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
redbooth-ruby-0.2.3 lib/redbooth-ruby/base.rb
redbooth-ruby-0.2.2 lib/redbooth-ruby/base.rb
redbooth-ruby-0.2.1 lib/redbooth-ruby/base.rb
redbooth-ruby-0.2.0 lib/redbooth-ruby/base.rb
redbooth-ruby-0.1.4 lib/redbooth-ruby/base.rb
redbooth-ruby-0.1.3 lib/redbooth-ruby/base.rb
redbooth-ruby-0.1.1 lib/redbooth-ruby/base.rb
redbooth-ruby-0.1.0 lib/redbooth-ruby/base.rb
redbooth-ruby-0.0.5 lib/redbooth-ruby/base.rb