class Clubhouse::ClubhouseResource

Public Class Methods

inherited(other) click to toggle source
# File lib/clubhouse2/clubhouse_resource.rb, line 5
def self.inherited(other)
        @@subclasses << other
end
new(client:, object:) click to toggle source
# File lib/clubhouse2/clubhouse_resource.rb, line 34
def initialize(client:, object:)
        @client = client

        self.class.properties.each do |this_property|
                self.class.class_eval { attr_accessor(this_property.to_sym) }
                self.class.send(:define_method, (this_property.to_s + '=').to_sym) do |value|
                        update({ this_property => resolve_to_ids(value) })
                        instance_variable_set('@' + this_property.to_s, resolve_to_ids(value))
                end
        end

        set_properties(object)
        self
end
property_filter_create() click to toggle source

A list of properties to exlude from any create request

# File lib/clubhouse2/clubhouse_resource.rb, line 10
def self.property_filter_create
        [
                :archived, :days_to_thermometer, :entity_type, :id, :show_thermometer, :stats, :created_at, :updated_at,
                :started_at, :completed_at, :comments, :position, :started, :project_ids, :completed, :blocker, :moved_at,
                :task_ids, :files, :comment_ids, :workflow_state_id, :story_links, :mention_ids, :file_ids, :linked_file_ids,
                :tasks
        ]
end
property_filter_update() click to toggle source

A list of properties to exlude from any update request

# File lib/clubhouse2/clubhouse_resource.rb, line 20
def self.property_filter_update
        self.property_filter_create
end
subclass(sub_class) click to toggle source
# File lib/clubhouse2/clubhouse_resource.rb, line 24
def self.subclass(sub_class)
        @@subclasses.find { |s| s.name == 'Clubhouse::%s' % sub_class.capitalize }
end
validate(args) click to toggle source
# File lib/clubhouse2/clubhouse_resource.rb, line 32
def self.validate(args); end

Public Instance Methods

api_url() click to toggle source
# File lib/clubhouse2/clubhouse_resource.rb, line 28
def api_url
        self.class.api_url + "/#{@id}"
end
delete!() click to toggle source
# File lib/clubhouse2/clubhouse_resource.rb, line 76
def delete!
        flush
        @client.api_request(:delete, @client.url(api_url))
end
flush() click to toggle source

Empties resource cache

# File lib/clubhouse2/clubhouse_resource.rb, line 65
def flush
        @client.flush(self.class)
end
resolve_to_ids(object) click to toggle source
# File lib/clubhouse2/clubhouse_resource.rb, line 49
def resolve_to_ids(object)
        return object.collect { |o| resolve_to_ids(o) } if object.is_a? Array
        (object.respond_to?(:id) ? object.id : object)
end
set_properties(object) click to toggle source
# File lib/clubhouse2/clubhouse_resource.rb, line 54
def set_properties(object)
        object.each_pair do |k, v|
                instance_variable_set('@' + k.to_s, value_format(k, v))
        end
end
to_h() click to toggle source
# File lib/clubhouse2/clubhouse_resource.rb, line 81
def to_h
        Hash[ (self.class.properties - self.class.property_filter_create).map { |name| [ name, instance_variable_get('@' + name.to_s) ] } ].compact
end
update(args = {}) click to toggle source
# File lib/clubhouse2/clubhouse_resource.rb, line 69
def update(args = {})
        new_params = args.reject { |k, v| self.class.property_filter_update.include? k.to_sym }
        validate(new_params)
        flush
        @client.api_request(:put, @client.url(api_url), :json => new_params)
end
value_format(key, value) click to toggle source
# File lib/clubhouse2/clubhouse_resource.rb, line 60
def value_format(key, value)
        DateTime.strptime(value+'+0000', '%Y-%m-%dT%H:%M:%SZ%z') rescue value
end