module Slappy::SlackAPI::Findable::ClassMethods
Attributes
api_name[R]
list_name[R]
monitor_event[R]
monitor_registerd[R]
Public Instance Methods
api_name=(api_name)
click to toggle source
# File lib/slappy/slack_api/concerns/findable.rb, line 16 def api_name=(api_name) @api_name = api_name end
find(arg)
click to toggle source
# File lib/slappy/slack_api/concerns/findable.rb, line 53 def find(arg) return find_by_keyword(arg) if arg.instance_of? Hash find id: arg end
find_by_keyword(hash)
click to toggle source
# File lib/slappy/slack_api/concerns/findable.rb, line 58 def find_by_keyword(hash) hash.map { |key, value| list.find { |obj| obj.send(key) == value } }.first end
list(options = {})
click to toggle source
# File lib/slappy/slack_api/concerns/findable.rb, line 39 def list(options = {}) register_monitor @list = get_list(options) unless @list @list end
list_name=(list_name)
click to toggle source
# File lib/slappy/slack_api/concerns/findable.rb, line 20 def list_name=(list_name) @list_name = list_name end
monitor_event=(target)
click to toggle source
# File lib/slappy/slack_api/concerns/findable.rb, line 24 def monitor_event=(target) target = [target] unless target.instance_of? Array @monitor_event = target end
register_monitor()
click to toggle source
# File lib/slappy/slack_api/concerns/findable.rb, line 29 def register_monitor return if @monitor_registerd @monitor_event.each do |event| Slappy.monitor event do @list = nil end end @monitor_registerd = true end
Private Instance Methods
get_list(options = {})
click to toggle source
# File lib/slappy/slack_api/concerns/findable.rb, line 64 def get_list(options = {}) method_name = "#{api_name}_list" options[:channel] = SlackAPI.find(options[:channel]).id if options[:channel] result = Slack.send(method_name, options) unless result['ok'] exception = SlackError.new "Error message from slack (#{result['error']})" fail exception, exception.message end result[list_name].map { |data| new(data) } end