mirror of
https://github.com/onyx-and-iris/obsws-ruby.git
synced 2024-11-15 18:50:47 +00:00
now using String refinement
Events Director module renamed patch bump
This commit is contained in:
parent
3a0f298045
commit
4c4746fe8a
@ -28,8 +28,8 @@ module OBSWS
|
|||||||
ALL = LOW_VOLUME | HIGH_VOLUME
|
ALL = LOW_VOLUME | HIGH_VOLUME
|
||||||
end
|
end
|
||||||
|
|
||||||
module EventDirector
|
module Director
|
||||||
include Util::String
|
using Util::CoreExtensions
|
||||||
|
|
||||||
def observers
|
def observers
|
||||||
@observers ||= {}
|
@observers ||= {}
|
||||||
@ -50,13 +50,13 @@ module OBSWS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fire(event, data)
|
def fire(event, data)
|
||||||
observers[snakecase(event).to_sym]&.each { |block| data.empty? ? block.call : block.call(data) }
|
observers[event.snakecase.to_sym]&.each { |block| data.empty? ? block.call : block.call(data) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Client
|
class Client
|
||||||
include Logging
|
include Logging
|
||||||
include EventDirector
|
include Events::Director
|
||||||
include Mixin::TearDown
|
include Mixin::TearDown
|
||||||
include Mixin::OPCodes
|
include Mixin::OPCodes
|
||||||
|
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
module OBSWS
|
module OBSWS
|
||||||
module Mixin
|
module Mixin
|
||||||
module Meta
|
module Meta
|
||||||
include Util::String
|
using Util::CoreExtensions
|
||||||
|
|
||||||
def make_field_methods(*params)
|
def make_field_methods(*params)
|
||||||
params.each do |param|
|
params.each do |param|
|
||||||
define_singleton_method(snakecase(param.to_s)) { @resp[param] }
|
define_singleton_method(param.to_s.snakecase) { @resp[param] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class MetaObject
|
class MetaObject
|
||||||
|
using Util::CoreExtensions
|
||||||
include Mixin::Meta
|
include Mixin::Meta
|
||||||
|
|
||||||
def initialize(resp, fields)
|
def initialize(resp, fields)
|
||||||
@ -21,7 +22,7 @@ module OBSWS
|
|||||||
|
|
||||||
def empty? = @fields.empty?
|
def empty? = @fields.empty?
|
||||||
|
|
||||||
def attrs = @fields.map { |f| snakecase(f.to_s) }
|
def attrs = @fields.map { |f| f.to_s.snakecase }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Represents a request response object
|
# Represents a request response object
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
module OBSWS
|
module OBSWS
|
||||||
module Util
|
module Util
|
||||||
module String
|
module CoreExtensions
|
||||||
def camelcase(s)
|
refine String do
|
||||||
s.split("_").map(&:capitalize).join
|
def camelcase
|
||||||
end
|
split("_").map(&:capitalize).join
|
||||||
|
end
|
||||||
|
|
||||||
def snakecase(s)
|
def snakecase
|
||||||
s
|
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
||||||
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
||||||
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
.downcase
|
||||||
.downcase
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,7 +11,7 @@ module OBSWS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def patch
|
def patch
|
||||||
1
|
2
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_a
|
def to_a
|
||||||
|
Loading…
Reference in New Issue
Block a user