lib/monday/resources.rb in monday_ruby-0.6.2 vs lib/monday/resources.rb in monday_ruby-1.0.0
- old
+ new
@@ -1,27 +1,23 @@
# frozen_string_literal: true
-require_relative "resources/account"
-require_relative "resources/activity_log"
-require_relative "resources/board"
-require_relative "resources/board_view"
-require_relative "resources/column"
-require_relative "resources/group"
-require_relative "resources/item"
-require_relative "resources/subitem"
-require_relative "resources/workspace"
-require_relative "resources/update"
+Dir[File.join(__dir__, "resources", "*.rb")].sort.each { |file| require file }
module Monday
+ # Encapsulates all available resources and includes them in the client.
module Resources
- include Account
- include ActivityLog
- include Board
- include BoardView
- include Column
- include Group
- include Item
- include Subitem
- include Workspace
- include Update
+ def self.initialize(client)
+ constants.each do |constant|
+ resource_class = const_get(constant)
+ resource_name = constant.to_s.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
+ client.instance_variable_set("@#{resource_name}", resource_class.new(client))
+ define_resource_accessor(client, resource_name) unless client.class.method_defined?(resource_name)
+ end
+ end
+
+ def self.define_resource_accessor(client, resource_name)
+ client.class.class_eval do
+ attr_reader resource_name
+ end
+ end
end
end