moco-ruby 1.0.0.alpha → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -5
- data/Gemfile +1 -0
- data/Gemfile.lock +6 -4
- data/README.md +38 -2
- data/copy_project.rb +337 -0
- data/lib/moco/client.rb +2 -2
- data/lib/moco/collection_proxy.rb +10 -0
- data/lib/moco/connection.rb +8 -2
- data/lib/moco/entities/activity.rb +6 -1
- data/lib/moco/entities/base_entity.rb +14 -5
- data/lib/moco/entities/expense.rb +10 -2
- data/lib/moco/entities/holiday.rb +1 -1
- data/lib/moco/entities/project.rb +31 -14
- data/lib/moco/entities/web_hook.rb +1 -1
- data/lib/moco/entity_collection.rb +3 -3
- data/lib/moco/nested_collection_proxy.rb +4 -1
- data/lib/moco/sync.rb +411 -71
- data/lib/moco/version.rb +1 -1
- data/lib/moco-ruby.rb +6 -0
- data/lib/moco.rb +5 -3
- data/sync_activity.rb +16 -4
- metadata +12 -10
|
@@ -7,29 +7,46 @@ module MOCO
|
|
|
7
7
|
association(:customer, "Company")
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
def leader
|
|
11
|
+
# Use the association method to fetch the leader
|
|
12
|
+
association(:leader, "User")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def co_leader
|
|
16
|
+
# Use the association method to fetch the co_leader
|
|
17
|
+
association(:co_leader, "User")
|
|
18
|
+
end
|
|
19
|
+
|
|
10
20
|
# Fetches activities associated with this project.
|
|
11
21
|
def activities
|
|
12
22
|
# Use the has_many method to fetch activities
|
|
13
23
|
has_many(:activities)
|
|
14
24
|
end
|
|
15
25
|
|
|
26
|
+
# Fetches expenses associated with this project.
|
|
27
|
+
def expenses
|
|
28
|
+
# Don't cache the proxy - create a fresh one each time
|
|
29
|
+
# This ensures we get fresh data when expenses are created/updated/deleted
|
|
30
|
+
MOCO::NestedCollectionProxy.new(client, self, :expenses, "Expense")
|
|
31
|
+
end
|
|
32
|
+
|
|
16
33
|
# Fetches tasks associated with this project.
|
|
17
34
|
def tasks
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
proxy = MOCO::NestedCollectionProxy.new(client, self, :tasks, "Task")
|
|
24
|
-
# We need to manually set the loaded records since we already have them
|
|
25
|
-
proxy.instance_variable_set(:@records, attributes[:tasks])
|
|
26
|
-
proxy.instance_variable_set(:@loaded, true)
|
|
27
|
-
proxy
|
|
28
|
-
end
|
|
29
|
-
else
|
|
30
|
-
# Otherwise, use has_many with nested=true
|
|
31
|
-
has_many(:tasks, nil, nil, true)
|
|
35
|
+
# If tasks are already embedded in the attributes (e.g., from projects.assigned),
|
|
36
|
+
# return them directly instead of making a new API call
|
|
37
|
+
embedded_tasks = attributes[:tasks]
|
|
38
|
+
if embedded_tasks.is_a?(Array) && embedded_tasks.all? { |t| t.is_a?(MOCO::Task) }
|
|
39
|
+
return embedded_tasks
|
|
32
40
|
end
|
|
41
|
+
|
|
42
|
+
# Otherwise, create a proxy for fetching tasks via API
|
|
43
|
+
# Don't cache the proxy - create a fresh one each time
|
|
44
|
+
# This ensures we get fresh data when tasks are created/updated/deleted
|
|
45
|
+
MOCO::NestedCollectionProxy.new(client, self, :tasks, "Task")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def to_s
|
|
49
|
+
"Project #{identifier} \"#{name}\" (#{id})"
|
|
33
50
|
end
|
|
34
51
|
|
|
35
52
|
def active?
|
|
@@ -14,8 +14,8 @@ module MOCO
|
|
|
14
14
|
@entity_class_name = entity_class_name
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def all
|
|
18
|
-
collection.all
|
|
17
|
+
def all
|
|
18
|
+
collection.all
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def find(id)
|
|
@@ -31,7 +31,7 @@ module MOCO
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def each(&)
|
|
34
|
-
|
|
34
|
+
collection.each(&)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def first
|
|
@@ -12,9 +12,12 @@ module MOCO
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
# Override determine_base_path to include the parent's path
|
|
15
|
+
# For nested resources, we ignore any custom entity_path and just use simple pluralization
|
|
15
16
|
def determine_base_path(path_or_entity_name)
|
|
16
17
|
parent_type = ActiveSupport::Inflector.underscore(parent.class.name.split("::").last)
|
|
17
|
-
|
|
18
|
+
# Use simple tableized name, not entity_path (which might include 'projects/' prefix)
|
|
19
|
+
nested_path = ActiveSupport::Inflector.tableize(path_or_entity_name.to_s)
|
|
20
|
+
"#{parent_type.pluralize}/#{parent.id}/#{nested_path}"
|
|
18
21
|
end
|
|
19
22
|
|
|
20
23
|
# Create a new entity in this nested collection
|