913498680070c6a5a619cb533e93ecaaee4b821e — Michael Rees 9 months ago 6130cac
Use constructor to create Subscriptions

Constructors are preferred over simply creating an object of the right
type to ensure that any fields that are added to the object in the
future are updated throughout the codebase.
1 files changed, 3 insertions(+), 4 deletions(-)

M src/romanpkg/subscriptions.nim
M src/romanpkg/subscriptions.nim => src/romanpkg/subscriptions.nim +3 -4
@@ 41,7 41,7 @@ proc getSubscriptions*(): seq[Subscription] {.raises: [RomanError].} =
          raise newException(RomanError,
            "unrecognized type field in subscriptions file: " & p.row[2])

      result.add(Subscription(name: p.row[0], url: p.row[1], feedKind: kind))
      result.add(newSubscription(p.row[0], p.row[1], kind))

    result.sort(proc(a, b: Subscription): int = cmpIgnoreCase(a.name, b.name))

@@ 77,9 77,8 @@ proc addFullSubscriptionToSubsFile(subscription: Subscription) {.raises: [RomanE

proc addSubscriptionToSubsFile*(url: string, feedKind: FeedKind) {.
    raises: [RomanError].} =
  let feed = getFeed(Subscription(url: url, feedKind: feedKind))
  let subscription = Subscription(name: feed.title, url: url,
      feedKind: feed.kind)
  let feed = getFeed(newSubscription("", url, feedKind))
  let subscription = newSubscription(feed.title, url, feed.kind)