Class: Ace::Assign::Models::Assignment

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/assign/models/assignment.rb

Overview

Assignment data model representing a workflow assignment.

Pure data carrier with no business logic (ATOM pattern). All attributes are immutable after initialization.

NOTE: Could be refactored to use Data.define in Ruby 3.2+ for reduced boilerplate, but tests would need to be updated to provide all required fields.

Examples:

assignment = Assignment.new(
  id: "8or5kx",
  name: "my-workflow",
  description: "Example workflow",
  created_at: Time.now,
  source_config: "job.yaml"
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, created_at:, source_config:, description: nil, updated_at: nil, cache_dir: nil, parent: nil) ⇒ Assignment

Returns a new instance of Assignment.

Parameters:

  • id (String)

    Unique assignment ID (6-char compact timestamp)

  • name (String)

    Human-readable assignment name

  • description (String, nil) (defaults to: nil)

    Optional assignment description

  • created_at (Time)

    When assignment was created

  • updated_at (Time, nil) (defaults to: nil)

    When assignment was last updated

  • source_config (String)

    Path to source configuration file

  • cache_dir (String, nil) (defaults to: nil)

    Assignment cache directory

  • parent (String, nil) (defaults to: nil)

    Parent assignment ID for hierarchy linking



32
33
34
35
36
37
38
39
40
41
# File 'lib/ace/assign/models/assignment.rb', line 32

def initialize(id:, name:, created_at:, source_config:, description: nil, updated_at: nil, cache_dir: nil, parent: nil)
  @id = id.freeze
  @name = name.freeze
  @description = description&.freeze
  @created_at = created_at
  @updated_at = updated_at || created_at
  @source_config = source_config.freeze
  @cache_dir = cache_dir&.freeze
  @parent = parent&.freeze
end

Instance Attribute Details

#cache_dirObject (readonly)

Returns the value of attribute cache_dir.



22
23
24
# File 'lib/ace/assign/models/assignment.rb', line 22

def cache_dir
  @cache_dir
end

#created_atObject (readonly)

Returns the value of attribute created_at.



22
23
24
# File 'lib/ace/assign/models/assignment.rb', line 22

def created_at
  @created_at
end

#descriptionObject (readonly)

Returns the value of attribute description.



22
23
24
# File 'lib/ace/assign/models/assignment.rb', line 22

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



22
23
24
# File 'lib/ace/assign/models/assignment.rb', line 22

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/ace/assign/models/assignment.rb', line 22

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



22
23
24
# File 'lib/ace/assign/models/assignment.rb', line 22

def parent
  @parent
end

#source_configObject (readonly)

Returns the value of attribute source_config.



22
23
24
# File 'lib/ace/assign/models/assignment.rb', line 22

def source_config
  @source_config
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



22
23
24
# File 'lib/ace/assign/models/assignment.rb', line 22

def updated_at
  @updated_at
end

Class Method Details

.from_h(data, cache_dir: nil) ⇒ Assignment

Create from hash (YAML deserialization)

Parameters:

  • data (Hash)

    Assignment data hash

  • cache_dir (String, nil) (defaults to: nil)

    Assignment cache directory

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ace/assign/models/assignment.rb', line 61

def self.from_h(data, cache_dir: nil)
  new(
    id: data["session_id"],
    name: data["name"],
    description: data["description"],
    created_at: parse_time(data["created_at"]),
    updated_at: parse_time(data["updated_at"]),
    source_config: data["source_config"],
    cache_dir: cache_dir,
    parent: data["parent"]
  )
end

Instance Method Details

#assignment_fileString

Returns Path to assignment.yaml file.

Returns:

  • (String)

    Path to assignment.yaml file



89
90
91
92
93
# File 'lib/ace/assign/models/assignment.rb', line 89

def assignment_file
  return nil unless cache_dir

  File.join(cache_dir, "assignment.yaml")
end

#reports_dirString

Returns Path to reports directory.

Returns:

  • (String)

    Path to reports directory



82
83
84
85
86
# File 'lib/ace/assign/models/assignment.rb', line 82

def reports_dir
  return nil unless cache_dir

  File.join(cache_dir, "reports")
end

#steps_dirString

Returns Path to steps directory.

Returns:

  • (String)

    Path to steps directory



75
76
77
78
79
# File 'lib/ace/assign/models/assignment.rb', line 75

def steps_dir
  return nil unless cache_dir

  File.join(cache_dir, "steps")
end

#to_hHash

Convert to hash for YAML serialization

Returns:

  • (Hash)

    Assignment data as hash



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ace/assign/models/assignment.rb', line 45

def to_h
  {
    "session_id" => id,
    "name" => name,
    "description" => description,
    "created_at" => created_at.iso8601,
    "updated_at" => updated_at.iso8601,
    "source_config" => source_config,
    "parent" => parent
  }.compact
end